Пример #1
0
        //Example: Refusing a presence subscription request:
        //<presence to='*****@*****.**' type='unsubscribed'/>
        /// <summary>
        /// Refuse  subscription request
        /// </summary>
        /// <param name="to">Bare Jid to approve</param>
        public void RefuseSubscriptionRequest(Jid to)
        {
            // <presence to='*****@*****.**' type='subscribe'/>
            Presence pres = new Presence();
            pres.Type = PresenceType.unsubscribed;
            pres.To = to;

            m_connection.Send(pres);
        }
Пример #2
0
        public void XmppCon_OnPresence(object sender, Presence pres)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new OnPresenceDelegate(XmppCon_OnPresence), new object[] { sender, pres });
                return;
            }

            if (pres.Type == PresenceType.subscribe)
            {
                RequestFriendForm f = new RequestFriendForm(XmppCon, pres.From);
                f.TopMost = true;
                try
                {
                    f.Show();
                }
                catch (Exception)
                {

                }

            }
            else if (pres.Type == PresenceType.subscribed)
            {

            }
            else if (pres.Type == PresenceType.unsubscribe)
            {

            }
            else if (pres.Type == PresenceType.unsubscribed)
            {

            }
            else
            {
                try
                {
                    //friendListView.RefreshFriend(pres.From.User, pres.Type, pres.Show);
                    friendListView.RefreshFriend(pres.From.User, pres.Type, pres.Show);
                    if (pres.Type==XMPP.protocol.client.PresenceType.unavailable)
                    {
                        if (Util.ChatForms.ContainsKey(pres.From.Bare))
                        {
                            ((ChatForm)Util.ChatForms[pres.From.Bare]).UpdateFriendOnline(false);
                        }

                        chat_history_listview.UpdateFriendInfoOnline(pres.From, false);
                    }
                    else
                    {
                        if (Util.ChatForms.ContainsKey(pres.From.Bare))
                        {
                            ((ChatForm)Util.ChatForms[pres.From.Bare]).UpdateFriendOnline(true);
                        }
                        chat_history_listview.UpdateFriendInfoOnline(pres.From, true);
                    }
                }
                catch (Exception)
                {

                }
            }
        }
Пример #3
0
        /// <summary>
        /// Leave a conference room
        /// </summary>
        /// <param name="room"></param>
        /// <param name="nickname"></param>
        public void LeaveRoom(Jid room, string nickname)
        {
            Jid to = new Jid(room.ToString());
            to.Resource = nickname;

            Presence pres = new Presence();
            pres.To = to;
            pres.Type = PresenceType.unavailable;

            m_connection.Send(pres);
        }
Пример #4
0
        /// <summary>
        /// Join a chatroom
        /// </summary>
        /// <param name="room">jid of the room to join</param>
        /// <param name="nickname">nickname to use in the room</param>
        /// <param name="password">password for password protected chat rooms</param>
        /// <param name="disableHistory">true for joining without chat room history</param>
        public void JoinRoom(Jid room, string nickname, string password, bool disableHistory)
        {
            /*
            <presence
                from='[email protected]/pda'
                to='[email protected]/thirdwitch'>
              <x xmlns='http://jabber.org/protocol/muc'>
                <password>cauldron</password>
              </x>
            </presence>

            join room and request no history
            <presence
                from='[email protected]/pda'
                to='[email protected]/thirdwitch'>
              <x xmlns='http://jabber.org/protocol/muc'>
                <history maxchars='0'/>
              </x>
            </presence>
            */

            Jid to = new Jid(room.ToString());
            to.Resource = nickname;

            Presence pres = new Presence();
            pres.To = to;
            Muc x = new Muc();
            if (password != null)
                x.Password = password;

            if (disableHistory)
            {
                History hist = new History();
                hist.MaxCharacters = 0;
                x.History = hist;
            }

            pres.AddChild(x);

            m_connection.Send(pres);
        }
Пример #5
0
        /// <summary>
        /// Change the Nickname in a room
        /// </summary>
        /// <param name="room"></param>
        /// <param name="newNick"></param>
        public void ChangeNickname(Jid room, string newNick)
        {
            Jid to = new Jid(room.ToString());
            to.Resource = newNick;

            Presence pres = new Presence();
            pres.To = to;

            m_connection.Send(pres);
        }
Пример #6
0
        /// <summary>
        /// Subscribe to a contact
        /// </summary>
        /// <param name="to">Bare Jid of the rosteritem we want to subscribe</param>
        public void Subscribe(Jid to)
        {
            // <presence to='*****@*****.**' type='subscribe'/>
            Presence pres = new Presence();
            pres.Type = PresenceType.subscribe;
            pres.To = to;

            m_connection.Send(pres);
        }
Пример #7
0
 private void PresenceChatGroupMethod(Presence pres)
 {
     if (pres.Type == PresenceType.error)
     {
         MsgBox.Show(this, "CSS&IM", "密码错误," + pres.Error.Code);
         //this.Enabled = true;
         this.Close();
     }
     if (pres.Type == PresenceType.available)
     {
         this.Enabled = true;
         friend_list.AddFriend(pres.MucUser.Item.Jid, _connection);
         ShowCellText(pres.MucUser.Item.Jid.User + "加入聊天室", Color.Blue);
     }
     if (pres.Type == PresenceType.unavailable)
     {
         friend_list.RemoveFroend(pres.MucUser.Item.Jid);
         ShowCellText(pres.MucUser.Item.Jid.User + "退出聊天室", Color.Blue);
     }
 }
Пример #8
0
        /// <summary>        
        /// Subscribe to a contact
        /// </summary>        
        /// <param name="to">Bare Jid of the rosteritem we want to subscribe</param>
        /// <param name="message">a message which normally contains the reason why we want to subscibe to this contact</param>
        public void Subscribe(Jid to, string message)
        {
            Presence pres = new Presence();
            pres.Type = PresenceType.subscribe;
            pres.To = to;
            pres.Status = message;

            m_connection.Send(pres);
        }
Пример #9
0
        public void Initial(String pswd)
        {
            Jid jid = to_Jid;
            jid.Resource = _connection.MyJID.User;

            this.Show();
            this.Enabled = false;

            _connection.PresenceGrabber.Add(jid, new PresenceCB(PresenceChatGroupCell), null);
            _connection.MessageGrabber.Add(jid, new BareJidComparer(), new MessageCB(MessageCallback), null);
            Presence spres = new Presence();
            spres.To = jid;
            Muc x = new Muc();
            if (pswd != null)
                x.Password = pswd;
            History hist = new History();
            hist.MaxCharacters = 100;
            x.History = hist;
            spres.AddChild(x);
            _connection.Send(spres);
        }
Пример #10
0
        /// <summary>
        /// 聊天室的验证信息和通知回调事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="pres"></param>
        /// <param name="data"></param>
        public void PresenceChatGroupCell(object sender, Presence pres, object data)
        {
            try
            {
                //if (InvokeRequired)
                //{
                //    this.BeginInvoke(new PresenceCB(PresenceChatGroupCell), new object[] { sender, pres, data });
                //}

                this.BeginInvoke(new PresenceChatGroupDelegate(PresenceChatGroupMethod), new object[] { pres });
            }
            catch (Exception)
            {

            }
        }
Пример #11
0
 public static int GetRosterImageIndex(Presence pres)
 {
     if (pres.Type == PresenceType.unavailable)
     {
         return 0;
     }
     else if (pres.Type == PresenceType.error)
     {
         // presence error, we dont care in the miniclient here
     }
     else
     {
         switch (pres.Show)
         {
             case ShowType.NONE:
                 return 1;
             case ShowType.away:
                 return 2;
             case ShowType.chat:
                 return 4;
             case ShowType.xa:
                 return 3;
             case ShowType.dnd:
                 return 5;
         }
     }
     return 0;
 }
        /// <summary>
        /// Sends our Presence, the packet is built of Status, Show and Priority
        /// </summary>
        public void SendMyPresence()
        {
            Presence pres = new Presence(m_Show, m_Status, m_Priority);

            // Add client caps when enabled
            if (m_EnableCapabilities)
            {
                if (m_Capabilities.Version == null)
                    UpdateCapsVersion();

                pres.AddChild(m_Capabilities);
            }

            this.Send(pres);
        }
Пример #13
0
        /// <summary>
        /// A presence is received. Now check if its from a Jid we are looking for and
        /// raise the event in this case.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="pres"></param>
        private void m_connection_OnPresence(object sender, Presence pres)
        {
            if (pres == null)
                return;

            lock (m_grabbing)
            {
                IDictionaryEnumerator myEnum = m_grabbing.GetEnumerator();

                while(myEnum.MoveNext())
                {
                    TrackerData t = myEnum.Value as TrackerData;
                    if (t.comparer.Compare(new Jid((string)myEnum.Key), pres.From) == 0)
                    {
                        // Execute the callback
                        t.cb(this, pres, t.data);
                    }
                }
            }
        }
Пример #14
0
 /// <summary>
 /// 用于PresenceChatGroupCell回调调用
 /// </summary>
 /// <param name="pres"></param>
 private void PresenceChatGroupMethod(Presence pres)
 {
     if (pres.Type == PresenceType.error)
     {
         CSS.IM.UI.Form.MsgBox.Show(this, "CSS&IM", "密码错误," + pres.Error.Code);
         //this.Enabled = true;
         this.Close();
     }
     if (pres.Type == PresenceType.available)
     {
         this.Enabled = true;
         friend_list.AddFriend(pres.MucUser.Item.Jid, XmppConn);
         RTBRecord_Show(pres.MucUser.Item.Jid.User + "加入聊天室", Color.Blue);
     }
     if (pres.Type == PresenceType.unavailable)
     {
         friend_list.RemoveFroend(pres.MucUser.Item.Jid);
         RTBRecord_Show(pres.MucUser.Item.Jid.User + "退出聊天室", Color.Blue);
     }
 }
Пример #15
0
        /// <summary>
        /// 通验证后要进行聊天室初始化
        /// </summary>
        /// <param name="pswd"></param>
        public void Initial(String pswd)
        {
            friendHead.Image = CSS.IM.UI.Util.ResClass.GetImgRes("big199");

            Jid jid = TO_Jid;
            jid.Resource = XmppConn.MyJID.User;

            this.Show();
            this.Enabled = false;

            XmppConn.PresenceGrabber.Add(jid, new PresenceCB(PresenceChatGroupCell), null);
            XmppConn.MessageGrabber.Add(jid, new CSS.IM.XMPP.Collections.BareJidComparer(), new MessageCB(MessageCallback), null);
            Presence spres = new Presence();
            spres.To = jid;
            Muc x = new Muc();
            if (pswd != null)
                x.Password = pswd;
            History hist = new History();
            hist.MaxCharacters = 100;
            x.History = hist;
            spres.AddChild(x);
            XmppConn.Send(spres);
        }