Item is used in jabber:iq:roster, jabber:iq:search
Inheritance: agsXMPP.protocol.Base.RosterItem
Ejemplo n.º 1
0
 public void OnRoster(RosterItem item)
 {
     var bare = item.Jid.Bare.ToLower();
     var target = GetOrDefault(bare);
     if (target == null && item.Subscription != SubscriptionType.remove)
     {
         bool subscribed = RosterData.Subscribed(item);
         var jid = item.Jid;
         var name = RosterData.Name(item);
         var interlocutor = new Interlocutor
         {
             Id = Guid.NewGuid(),
             Name = name,
             Server = jid.Server,
             User = jid.User,
             Subscribed = subscribed,
         };
         _client.Contacts.Add(interlocutor);
     }
     else if (target != null && item.Subscription != SubscriptionType.remove)
     {
         bool subscribed = RosterData.Subscribed(item);
         var jid = item.Jid;
         var name = RosterData.Name(item);
         target.Name = name;
         target.Server = jid.Server;
         target.User = jid.User;
         target.Subscribed = subscribed;
     }
     else if (target != null && item.Subscription == SubscriptionType.remove)
     {
         _client.Contacts.Remove(target);
     }
 }
Ejemplo n.º 2
0
        private void XmppCon_OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new agsXMPP.XmppClientConnection.RosterHandler(XmppCon_OnRosterItem), new object[] { this, item });
                return;
            }
            if (item.Subscription != SubscriptionType.remove)
            {
                ListViewItem li;

                li = FindRosterListViewItem(item.Jid);
                if (li == null)
                {
                    li = new ListViewItem(item.Name != null ? item.Name : item.Jid.ToString());

                    li.Tag = item.Jid.ToString();
                    li.SubItems.Add("");
                    li.SubItems.Add("");
                    lvwRoster.Items.Add(li);
                }
                else
                {
                    li.Text = item.Name != null ? item.Name : item.Jid.ToString();
                }
            }
            else
            {
                ListViewItem li = FindRosterListViewItem(item.Jid);
            }
        }
Ejemplo n.º 3
0
        private void _xmpp_OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
        {
            var user = _users.FirstOrDefault(u => u.Name.ToLower() == item.Jid.Bare);

            if (user == null)
            {
                return;
            }
        }
Ejemplo n.º 4
0
 private void OnRosterItem(object sender, RosterItem item)
 {
     if (_listModeOn)
     {
         _listHandler.OnRoster(item);
     }
     else
     {
         _itemHandler.OnRoster(item);
     }
 }
Ejemplo n.º 5
0
 public RosterItem[] GetRoster()
 {
     ElementList nl = SelectElements(typeof(RosterItem));
     int i = 0;
     RosterItem[] result = new RosterItem[nl.Count];
     foreach (RosterItem ri in nl)
     {
         result[i] = (RosterItem) ri;
         i++;
     }
     return result;
 }
Ejemplo n.º 6
0
        public ChatUser(RosterItem item)
        {
            this.Name = item.Name;
            this.Mention = item.Name;
            this.Id = item.Jid.User;
            this.Bare = item.Jid.Bare;

            try
            {
                var mention = item.Attributes["mention_name"].ToString();
                if (!String.IsNullOrWhiteSpace(mention))
                    this.Mention = mention;
            }
            catch { }
        }
Ejemplo n.º 7
0
 public static string Name(RosterItem item)
 {
     if (!string.IsNullOrEmpty(item.Name))
     {
         return item.Name;
     }
     if (!string.IsNullOrEmpty(item.Jid.User))
     {
         return item.Jid.User;
     }
     if (!string.IsNullOrEmpty(item.Jid.Server))
     {
         return item.Jid.Server;
     }
     return "unknown";
 }
Ejemplo n.º 8
0
        private void OnRosterItem(object sender, RosterItem item)
        {
            var vsId = XmppIdConverter.Convert(item.Jid);

            if (_container.Contains(vsId) && item.Subscription == SubscriptionType.remove)
            {
                _listener.RemoveInterlocutor(vsId);
            }
            else if (_container.Contains(vsId) && item.Subscription != SubscriptionType.remove)
            {
                _listener.UpdateInterlocutor(RosterInfo.Create(item));
            }
            else if (!_container.Contains(vsId) && item.Subscription != SubscriptionType.remove)
            {
                _listener.CreateInterlocutor(RosterInfo.Create(item));
            }
        }
Ejemplo n.º 9
0
        private void XmppCon_OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new agsXMPP.XmppClientConnection.RosterHandler(XmppCon_OnRosterItem), new object[] { this, item });
                return;
            }

            if (item.Subscription != SubscriptionType.remove)
            {
                rosterControl.AddRosterItem(item);
            }
            else
            {
                rosterControl.RemoveRosterItem(item);
            }
        }
        /// <summary>
        /// 移除所有组中的好友,并提交给服务器。
        /// </summary>
        /// <param name="rosterItem">好友</param>
        private void RemoveMyRoster(agsXMPP.protocol.iq.roster.RosterItem rosterItem)
        {
            List <NavBarItem> nbList = FindNavBarItem(rosterItem.Jid.Bare);

            for (int i = nbList.Count - 1; i >= 0; i--)
            {
                NavBarItem item = nbList[i];

                foreach (NavBarGroup navGroup in this.navBar.Groups)
                {
                    navGroup.ItemLinks.Remove(item);
                }
            }
            hintLink = null;

            //wei=>XmppRosterManager.Instance.Remove(rosterItem);
        }
Ejemplo n.º 11
0
        private void ConnectiOnRosterItem(object sender, RosterItem item)
        {
            var contact = new Contact
            {
                Id     = GetContactId(item.Jid),
                Jid    = item.Jid,
                Name   = item.Name,
                Groups = (
                    from g in item.GetGroups().OfType <Group>()
                    select g.Name).ToArray(),
                ConferenceUser = false
            };
            var contact1 = contact;

            _roster[contact1.Id] = contact1;
            OnContactChanged(contact1, ContactChangeType.Add);
        }
Ejemplo n.º 12
0
        private void OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
        {
            ts.TraceInformation("OnRosterItem {0} ask {1}, from {2}", this.Jid.ToString(), item.Ask, item.Jid.ToString());

            if (item.Ask == AskType.subscribe)
            {
                //ts.TraceInformation("OnRosterItem {0} ask=subscribe", this.Jid.ToString(), item.ToString());
                if (SubscribeConfirmHandler != null)
                {
                    SubscribeConfirmHandler(this, this.Jid, item.Jid);
                }
            }

            if (RosterItemHandler != null)
            {
                RosterItemHandler(this, this.Jid, item);
            }
        }
Ejemplo n.º 13
0
 public void xmpp_OnRosterItem(object sender, RosterItem item)
 {
     try
     {
         Core.UserList.Add(item);
         Core.RunOnUiThread(() =>
             {
                 if (item.GetAttribute("name") == "Facebook User")
                 {
                     return;
                 }
                 try
                 {
                     var chatItem = new ChatPlayerItem
                     {
                         Group = item.GetAttribute("group"),
                         Jid = item.Jid,
                         Messages = new List<string>(),
                         Username = item.GetAttribute("name")
                     };
                     Core.AllPlayers.Add(item.GetAttribute("name"), chatItem);
                 }
                 catch
                 {
                     var itemPlayer = Core.AllPlayers[item.GetAttribute("name")];
                     Core.AllPlayers.Remove(item.GetAttribute("name"));
                     Core.AllPlayers.Add(item.GetAttribute("name"), itemPlayer);
                 }
                 var control = new PlayerChatControl
                 {
                     _playerNameLabel = { Content = item.GetAttribute("name") },
                     Tag = Core.AllPlayers[item.GetAttribute("name")]
                 };
                 Core.PlayerChatControls.Add(item.GetAttribute("jid"), control);
             });
     }
     catch
     {
         //MessageBox.Show(ex.ToString());
     }
 }
Ejemplo n.º 14
0
 private void _connection_OnRosterItem(object sender, RosterItem item)
 {
     if (InvokeRequired)
     {
         BeginInvoke(
             new XmppClientConnection.RosterHandler(_connection_OnRosterItem), new[] { sender, item });
         return;
     }
     if (item.Subscription == SubscriptionType.none)
     {
         return;
     }
     if (item.Subscription != SubscriptionType.remove)
     {
         string group = SystermConst.DefaultGroupName;
         if (item.GetGroups().Count > 0)
         {
             string name = ((Group)item.GetGroups().Item(0)).Name;
             group = string.IsNullOrEmpty(name) ? SystermConst.DefaultGroupName : name;
         }
         _friendDictionary.Add(item.Jid, group);
     }
 }
Ejemplo n.º 15
0
 public void OnRoster(RosterItem item)
 {
     var bare = item.Jid.Bare.ToLower();
     if (!_interlocutors.ContainsKey(bare) && item.Subscription != SubscriptionType.remove)
     {
         bool subscribed = RosterData.Subscribed(item);
         var jid = item.Jid;
         var name = RosterData.Name(item);
         var interlocutor = new Interlocutor
         {
             Id = Guid.NewGuid(),
             Name = name,
             Server = jid.Server,
             User = jid.User,
             Subscribed = subscribed,
         };
         _client.Contacts.Add(interlocutor);
     }
     else if (_interlocutors.ContainsKey(bare) && item.Subscription != SubscriptionType.remove)
     {
         bool subscribed = RosterData.Subscribed(item);
         var jid = item.Jid;
         var name = RosterData.Name(item);
         var interlocutor = _interlocutors[bare];
         interlocutor.Name = name;
         interlocutor.Server = jid.Server;
         interlocutor.User = jid.User;
         interlocutor.Subscribed = subscribed;
         _interlocutors.Remove(bare);
     }
     else if (_interlocutors.ContainsKey(bare) && item.Subscription == SubscriptionType.remove)
     {
         var interlocutor = _interlocutors[bare];
         _interlocutors.Remove(bare);
         _client.Contacts.Remove(interlocutor);
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Add a contact to the Roster.
        /// </summary>
        /// <param name="jid">The BARE jid of the contact that should be added.</param>
        /// <param name="nickname">Nickname for the contact.</param>
        /// <param name="group">An Array of groups when you want to add the contact to multiple groups.</param>
        public void AddRosterItem(Jid jid, string nickname, string[] group)
        {
            RosterIq riq = new RosterIq();

            riq.Type = IqType.set;

            RosterItem ri = new RosterItem();

            ri.Jid = jid;

            if (nickname != null)
            {
                ri.Name = nickname;
            }

            foreach (string g in group)
            {
                ri.AddGroup(g);
            }

            riq.Query.AddRosterItem(ri);

            m_connection.Send(riq);
        }
Ejemplo n.º 17
0
            private void ProcessPresence(Presence presence)
            {
                bool bSend = false;
                #region subscribe
                if (presence.Type == PresenceType.subscribe)
                {
                    //RECV: <presence xmlns="jabber:client" type="subscribe" to="test2@localhost" />

                    //SEND: 
                    //<iq id="162" type="set">
                    //    <query xmlns="jabber:iq:roster">
                    //        <item jid="test2@localhost" name="test2" subscription="none" ask="subscribe"/>
                    //    </query>
                    //</iq>

                    //SEND: <presence xmlns="jabber:client" type="subscribe" to="test2@localhost" from="test@localhost" />

                    // push roster set iq to all the resurce
                    RosterIq newRosterIq = new RosterIq(IqType.set);
                    newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                    Jid subscribeJID = presence.To;

                    RosterItem ri = new RosterItem();
                    ri.Name = subscribeJID.User;
                    ri.Jid = subscribeJID;


                    Friend friend = this.m_ClientAccount.FindFriend(subscribeJID.ToString());
                    if (friend == null)
                    {

                    }
                    ///ask status change
                    friend.SubscriptionStatus = 0;

                    ri.Subscription = friend.SubscriptionType;
                    ri.Ask = AskType.subscribe;

                    foreach (string strGroup in friend.Groups)
                    {
                        ri.AddGroup(strGroup);
                    }

                    newRosterIq.Query.AddRosterItem(ri);

                    //Push roster update to all client
                    //foreach (Account account in this.m_Server.ClientConnections.Keys)
                    //{
                    //    if (account.JID.Bare.ToLower() == this.m_ClientAccount.JID.Bare.ToLower())
                    //    {
                    //        //this.m_Server.ClientConnections[account].Send(newRosterIq);
                    //        Send(account, newRosterIq);
                    //    }
                    //}

                    Send(newRosterIq);

                    Presence newPresence = new Presence();
                    newPresence.Namespace = agsXMPP.Uri.CLIENT;
                    newPresence.Type = PresenceType.subscribe;
                    newPresence.From = new Jid(this.m_ClientAccount.JID.Bare);
                    newPresence.To = presence.To;

                    /////路由信息
                    //account = new Account();
                    //account.Company = presence.To.Company;
                    //account.UserID = presence.To.User;

                    //if(this.m_Server.ClientConnections.ContainsKey(account))
                    //{
                    //    //this.m_Server.ClientConnections[account].Send(newPresence);
                    //    SendToAllResource(account, newPresence);
                    //}
                    //else
                    //{
                    //    this.m_Server.CachePresences.Add(newPresence.To, newPresence);
                    //}

                    bSend = Send(presence.To, newPresence);
                    if (!bSend)
                    {

                    }

                    //RosterIq newRosterIq = new RosterIq(IqType.set);

                    //RosterItem ri = new RosterItem();
                    //ri.Name = presence.To.User;
                    //ri.Jid = presence.To;
                    //ri.Subscription = SubscriptionType.none;
                    //ri.Ask = AskType.subscribe;
                    //newRosterIq.Query.AddRosterItem(ri);

                    //Send(newRosterIq);

                }
                #endregion
                #region subscribed
                else if (presence.Type == PresenceType.subscribed)
                {
                    //RECV: <presence xmlns="jabber:client" type="subscribed" to="test@localhost" />

                    //<iq id="178" type="set">
                    //    <query xmlns="jabber:iq:roster">
                    //        <item jid="test@localhost" name="test@localhost" subscription="from" />
                    //    </query>
                    //</iq>

                    //<iq id="181" type="set">
                    //    <query xmlns="jabber:iq:roster">
                    //        <item jid="test2@localhost" name="test2@localhost" subscription="to" />
                    //    </query>
                    //</iq>

                    //SEND: 
                    //<presence xmlns="jabber:client" type="subscribed" to="test@localhost" from="test2@localhost" />
                    //<presence xmlns="jabber:client" from="test2@localhost/MF" xml:lang="zh-cn" to="test@localhost/MF">
                    //    <priority>10</priority>
                    //</presence>

                    RosterIq newRosterIq = null;
                    RosterItem ri = null;

                    Jid userJID = presence.To;
                    Jid contactJID = this.m_ClientAccount.JID;

                    ///改变花名册的订阅状态
                    Friend user = this.m_ClientAccount.FindFriend(userJID.ToString());
                    if (user == null)
                    {
                        user = this.m_ClientAccount.AddFriend();
                        user.JID = userJID;
                        user.Nick = userJID.User;
                        user.SubscriptionType = SubscriptionType.none;
                        user.SubscriptionStatus = -1;
                    }

                    if (user.Nick == null || user.Nick == string.Empty)
                    {
                        user.Nick = userJID.User;
                    }

                    user.SubscriptionStatus = 1;
                    if (user.SubscriptionType == SubscriptionType.none)
                    {
                        user.SubscriptionType = SubscriptionType.from;
                    }
                    else if (user.SubscriptionType == SubscriptionType.to)
                    {
                        user.SubscriptionType = SubscriptionType.both;
                    }
                    else
                    {

                    }

                    //联系人花名册中的用户的订阅状态保存
                    user.Save();

                    // push roster set iq to all the resurce
                    newRosterIq = new RosterIq(IqType.set);
                    newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                    ri = new RosterItem();
                    ri.Name = userJID.User;
                    ri.Jid = userJID;
                    ri.Subscription = user.SubscriptionType;

                    foreach (string strGroup in user.Groups)
                    {
                        ri.AddGroup(strGroup);
                    }

                    newRosterIq.Query.AddRosterItem(ri);

                    bSend = Send(this.m_ClientAccount, newRosterIq);
                    if (!bSend)
                    {

                    }

                    Account userAccount = this.m_Server.AccountManager.FindAccount(userJID.ToString());
                    Friend contact = userAccount.FindFriend(contactJID.ToString());
                    if (contact == null)
                    {
                        contact = this.m_ClientAccount.AddFriend();
                        contact.JID = contactJID;
                        contact.Nick = contactJID.User;
                        contact.SubscriptionType = SubscriptionType.none;
                        contact.SubscriptionStatus = -1;
                    }

                    if (contact.Nick == null || contact.Nick == string.Empty)
                    {
                        contact.Nick = contactJID.User;
                    }

                    contact.SubscriptionStatus = 1;
                    if (contact.SubscriptionType == SubscriptionType.none)
                    {
                        contact.SubscriptionType = SubscriptionType.to;
                    }
                    else if (contact.SubscriptionType == SubscriptionType.from)
                    {
                        contact.SubscriptionType = SubscriptionType.both;
                    }
                    else
                    {

                    }

                    //用户花名册中的联系人的订阅状态保存
                    contact.Save();

                    // push roster set iq to all the resurce
                    newRosterIq = new RosterIq(IqType.set);
                    newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                    ri = new RosterItem();
                    ri.Name = contact.Nick;
                    ri.Jid = contact.JID;
                    ri.Subscription = contact.SubscriptionType;

                    foreach (string strGroup in contact.Groups)
                    {
                        ri.AddGroup(strGroup);
                    }

                    newRosterIq.Query.AddRosterItem(ri);

                    bSend = Send(userAccount, newRosterIq);
                    if (!bSend)
                    {

                    }

                    //<presence xmlns="jabber:client" type="subscribed" to="test@localhost" from="test2@localhost" />

                    Presence newPresence = new Presence();
                    newPresence.Namespace = agsXMPP.Uri.CLIENT;
                    newPresence.Type = PresenceType.subscribed;
                    newPresence.From = new Jid(this.m_ClientAccount.JID.Bare);
                    newPresence.To = presence.To;

                    bSend = Send(presence.To, newPresence);
                    if (!bSend)
                    {

                    }

                    //<presence xmlns="jabber:client" from="test2@localhost/MF" xml:lang="zh-cn" to="test@localhost/MF">
                    //    <priority>10</priority>
                    //</presence>

                    newPresence.RemoveAttribute("type");
                    newPresence.Language = this.objClientlanguage.Name;
                    newPresence.Priority = 10;
                    Send(presence.To, newPresence);

                }
                #endregion
                #region unsubscribe
                else if (presence.Type == PresenceType.unsubscribe)
                {



                }
                #endregion
                #region unsubscribed
                else if (presence.Type == PresenceType.unsubscribed)
                {
                    //RECV: 
                    //    <presence xmlns="jabber:client" type="unsubscribed" to="test@localhost" />
                    //SEND: 
                    //    <iq id="168" type="set">
                    //        <query xmlns="jabber:iq:roster">
                    //            <item jid="test2@localhost" name="test2" subscription="none" />
                    //        </query>
                    //    </iq>
                    //SEND: <presence xmlns="jabber:client" type="unsubscribed" to="test@localhost/MF" from="test2@localhost" />

                    //SEND: <presence from="test@localhost/MF" xml:lang="zh-cn" type="unavailable" to="test2@localhost/MF" />

                    // push roster set iq to all the resurce
                    RosterIq newRosterIq = null;
                    RosterItem ri = null;

                    newRosterIq = new RosterIq(IqType.set);
                    newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                    Jid subscribeJID = presence.To;

                    ri = new RosterItem();
                    ri.Name = subscribeJID.User;
                    ri.Jid = subscribeJID;

                    Friend friend = this.m_ClientAccount.FindFriend(subscribeJID.ToString());
                    if (friend != null)
                    {
                        ///ask status change
                        friend.SubscriptionStatus = 1;
                        friend.Save();

                        ri.Subscription = friend.SubscriptionType;

                        foreach (string strGroup in friend.Groups)
                        {
                            ri.AddGroup(strGroup);
                        }
                    }
                    else
                    {
                        ri.Subscription = SubscriptionType.none;
                    }

                    newRosterIq.Query.AddRosterItem(ri);

                    Send(newRosterIq);

                    ///to user
                    newRosterIq = new RosterIq(IqType.set);
                    newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                    ri = new RosterItem();

                    Account userAccount = this.m_Server.AccountManager.FindAccount(presence.To.ToString());
                    Friend contactFriend = userAccount.FindFriend(this.m_ClientAccount.JID.ToString());

                    ri.Name = contactFriend.Nick;
                    ri.Jid = contactFriend.JID;
                    ri.Subscription = contactFriend.SubscriptionType;

                    contactFriend.SubscriptionStatus = 1;
                    contactFriend.Save();

                    //Push roster update to all client
                    bSend = Send(presence.To, newRosterIq);
                    if (!bSend)
                    {

                    }

                    Presence newPresence = new Presence();
                    newPresence.Namespace = agsXMPP.Uri.CLIENT;
                    newPresence.Type = PresenceType.unsubscribed;
                    newPresence.From = new Jid(this.m_ClientAccount.JID.Bare);
                    newPresence.To = presence.To;

                    ///路由信息
                    bSend = Send(presence.To, newPresence);
                    if (!bSend)
                    {
                        this.m_Server.CachePresences.Add(newPresence.To, newPresence);
                    }

                    newPresence.Type = PresenceType.unavailable;
                    newPresence.RemoveAttribute("xmlns");
                    newPresence.Language = this.objClientlanguage.Name;

                    bSend = Send(presence.To, newPresence);
                    if (!bSend)
                    {

                    }

                }
                #endregion
                #region unavailable
                else if (presence.Type == PresenceType.unavailable)
                {
                    //<presence xmlns="jabber:client" to="*****@*****.**" type="unavailable" />
                    //<presence from='[email protected]/pda' to='[email protected]/thirdwitch'type='unavailable'/>

                    //<presence
                    //    from='[email protected]/thirdwitch'
                    //    to='[email protected]/desktop'
                    //    type='unavailable'>
                    //  <x xmlns='http://jabber.org/protocol/muc#user'>
                    //    <item affiliation='member' role='none'/>
                    //  </x>
                    //</presence>

                    MucService muc = this.m_Server.GetMucService();
                    if(muc != null)
                    {
                        foreach (KeyValuePair<string, ChatRoom> item in muc.GetRooms())
                        {
                            if (item.Value.JID.ToString() == presence.To.Bare.ToString())
                            {
                                User from = item.Value.FindOnline(this.m_ClientAccount.JID.Bare);
                                if (from == null)
                                {
                                    return;
                                }

                                Presence newPresence = new Presence();
                                newPresence.Type = PresenceType.unavailable;
                                newPresence.From = new Jid(item.Value.JID.ToString() + "/" + from.Nick);
                                foreach (User user in item.Value.GetOnlines())
                                {
                                    newPresence.To = user.JID;

                                    Send(newPresence.To, newPresence);
                                }

                                item.Value.Exit(from);

                                return;
                            }

                        }

                    }

                    return;
                }
                #endregion
                #region else
                else
                {
                    #region showType.Noe
                    if (presence.Show == ShowType.NONE)
                    {
                        ///groupchat roster presence
                        if (presence.To != null)
                        {
                            MucService muc = this.m_Server.GetMucService();
                            if(muc != null)
                            {
                                if (muc.JID.Bare.ToLower() == presence.To.Server.ToLower())
                                {
                                    foreach (KeyValuePair<string, ChatRoom> item in muc.GetRooms())
                                    {
                                        if (item.Value.JID.ToString().ToLower() == presence.To.Bare.ToLower())
                                        {
                                            User login = new User();
                                            login.Nick = presence.To.Resource;
                                            login.Role = agsXMPP.protocol.x.muc.Role.participant;
                                            login.Affiliation = agsXMPP.protocol.x.muc.Affiliation.member;
                                            login.JID = new Jid(this.m_ClientAccount.JID.ToString() + "/" + this.strBindResource);

                                            Presence newPresence = null;

                                            List<User> onlines = item.Value.GetOnlines();
                                            if (onlines == null)
                                            {
                                                item.Value.Enter(login);
                                                return;
                                            }

                                            foreach (User user in onlines)
                                            {
                                                newPresence = new Presence();
                                                newPresence.From = new Jid(presence.To.Bare + "/" + user.Nick);
                                                newPresence.To = login.JID;

                                                newPresence.MucUser = new agsXMPP.protocol.x.muc.User();
                                                newPresence.MucUser.Item = new agsXMPP.protocol.x.muc.Item(user.Affiliation, user.Role);

                                                Send(newPresence.To, newPresence);


                                                newPresence = new Presence();
                                                newPresence.From = new Jid(presence.To.Bare + "/" + login.Nick); ;
                                                newPresence.To = user.JID;

                                                newPresence.MucUser = new agsXMPP.protocol.x.muc.User();
                                                newPresence.MucUser.Item = new agsXMPP.protocol.x.muc.Item(login.Affiliation, login.Role);

                                                Send(newPresence.To, newPresence);

                                            }

                                            item.Value.Enter(login);
                                        }
                                    }

                                    return;

                                }

                            }
                        }

                        foreach (Friend friend in this.m_ClientAccount.Friends)
                        {

                            Account account = this.m_Server.AccountManager.FindAccount(friend.JID.ToString());
                            if (account == null)
                            {
                                continue;
                            }

                            if (!this.m_Server.ClientConnections.ContainsKey(account))
                            {
                                continue;
                            }

                            Presence newPresence = new Presence();
                            //newPresence.From = presence.From;
                            //newPresence.To = presence.To;

                            newPresence.Priority = presence.Priority;

                            SubscriptionType subscriptionType = friend.SubscriptionType;

                            if (subscriptionType == SubscriptionType.from)
                            {
                                newPresence.From = account.JID;
                                newPresence.To = this.m_ClientAccount.JID;
                                Send(newPresence);
                            }
                            else if (subscriptionType == SubscriptionType.to)
                            {
                                newPresence.From = this.m_ClientAccount.JID;
                                newPresence.To = account.JID;

                                Send(account, newPresence);

                            }
                            else if (subscriptionType == SubscriptionType.both)
                            {
                                newPresence.From = account.JID;
                                newPresence.To = this.m_ClientAccount.JID;
                                Send(newPresence);

                                newPresence.SwitchDirection();
                                //this.m_Server.ClientConnections[account].Send(newPresence);
                                Send(account, newPresence);
                            }
                            else
                            {

                            }
                        }

                    }
                    #endregion
                    #region else
                    else
                    {

                    }
                    #endregion

                }
                #endregion

                this.m_Server.AccountManager.Save();

            }
Ejemplo n.º 18
0
	    /// <summary>
        /// Removes a contact from the Roster
        /// </summary>
        /// <param name="jid">The BARE jid of the rosteritem that should be removed</param>
        public void RemoveRosterItem(Jid jid)
        {
            RosterIq riq = new RosterIq();
            riq.Type = IqType.set;

            RosterItem ri = new RosterItem();
            ri.Jid = jid;
            ri.Subscription = SubscriptionType.remove;

            riq.Query.AddRosterItem(ri);

            m_connection.Send(riq);
        }
Ejemplo n.º 19
0
	    /// <summary>
	    /// Add a contact to the Roster.
	    /// </summary>
	    /// <param name="jid">The BARE jid of the contact that should be added.</param>
	    /// <param name="nickname">Nickname for the contact.</param>
	    /// <param name="group">An Array of groups when you want to add the contact to multiple groups.</param>
	    public void AddRosterItem(Jid jid, string nickname, string[] group)
	    {
	        RosterIq riq = new RosterIq();
	        riq.Type = IqType.set;
				
	        RosterItem ri = new RosterItem();
	        ri.Jid	= jid;
			
	        if (nickname != null)
	            ri.Name	= nickname;
			
	        foreach (string g in group)
	        {
	            ri.AddGroup(g);			
	        }

	        riq.Query.AddRosterItem(ri);
				
	        m_connection.Send(riq);
	    }
        /// <summary>
        /// 好友的信息到达事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="item"></param>
        public void ClientConnection_OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
        {
            //wei=>this.TA_Execute(delegate
            //wei=>{
            //wei=>LockWatcher lkw = LockWatcher.New();
            lock (NavLock)
            {
                //wei=> lkw.Stop();

                /*
                 * Additionally, if subscription='from' or subscription='none', you can have ask='suscribe',
                 * which means you sent a subscription request to the item but haven't received an answer yet.
                 */

                /*
                 * Therefore, the following types of contacts SHOULD be displayed by clients:
                 *
                 * items with subscription='both' or subscription='to' ;
                 * items with subscription='none' or subscription='from' and ask='subscribe'. It is ((subscription='none' or subscription='from') and ask='subscribe') ;
                 * items with subscription='none' or subscription='from' which have a 'name' attribute or a 'group' child set. It is ((subscription='none' or subscription='from') and (name attribute or group child)).
                 * The client MAY display contacts with subscription='from' which don't match one of the above cases in an additional 'Observers' group. If no 'Observers' group is used, the client SHOULD NOT display contacts which don't match one of the above rules.
                 *
                 */

                if ((item.Subscription == SubscriptionType.both || item.Subscription == SubscriptionType.to) ||
                    ((item.Subscription == SubscriptionType.none || item.Subscription == SubscriptionType.from) && item.Ask == AskType.subscribe) ||
                    ((item.Subscription == SubscriptionType.none || item.Subscription == SubscriptionType.from) && (!String.IsNullOrEmpty(item.Name) || item.GetGroups().Count > 0)))
                {
                    // 是否需要排序标记
                    bool needSort = false;
                    // SHOULD be displayed by clients:
                    ElementList   groups     = item.GetGroups();
                    List <string> groupNames = new List <string>();

                    foreach (Element g in groups)
                    {
                        groupNames.Add(g.InnerXml);
                    }

                    if (groupNames.Count == 0)
                    {
                        groupNames.Add(DEFAULT_GROUP_NAME);
                    }

                    // 如果movingJid 和事件传入的 JID 相同,则说明该用户移动成功。
                    //wei=>if (movingJid != null && movingJid.EqualsIgnoreResource(item.Jid))
                    //wei=>
                    //wei=>LockWatcher lkw2 = LockWatcher.New();
                    lock (movingJidFlag)
                    {
                        // 首先先移除 movingJid
                        RemoveJidOnUI(movingJid);
                        needSort  = true;        // 移动好友后,需要做排序处理
                        movingJid = null;
                        // 设置好友移动标记为非阻塞状态
                        movingJidFlag.Set();
                    }
                    //wei=>lkw2.Stop();
                    //wei=>}

                    List <NavBarGroup> testGroups = new List <NavBarGroup>();

                    // 遍历传入好友所属的所有组
                    foreach (String groupName in groupNames)
                    {
                        // 创建组
                        NavBarGroup group = AddGroup(groupName);

                        if (testGroups.Contains(group))
                        {
                            continue;
                        }
                        else
                        {
                            testGroups.Add(group);
                        }

                        bool hasUser = false;
                        // ???????????????????????问题:集合已修改;可能无法执行枚举操作。
                        foreach (NavBarItemLink link in group.ItemLinks)
                        {
                            RosterItem rosterItem = link.Item.Tag as RosterItem;
                            //wei=>if (rosterItem.Jid.EqualsIgnoreResource(item.Jid))
                            //wei=>{
                            // 当前组存在该好友
                            hasUser = true;
                            break;
                            //wei=>}
                        }
                        // 如果当前组中不存在该好友,则新增好友到当前组。
                        if (hasUser == false)
                        {
                            NavBarItem nbItem = new NavBarItem(item.Name);

                            nbItem.Tag = item;
                            //wei=> LockWatcher lkw3 = LockWatcher.New();
                            //wei=>lock (PresenceManager.Instance.LockStatus)
                            {
                                //wei=>lkw3.Stop();
                                // 获取用户状态的图标
                                int    mobileStatus = -1;
                                int    status       = -1;
                                string mobileRes    = "";
                                //wei=>PresenceManager.Instance.GetUserStatus(item.Jid, out mobileStatus, out mobileRes, out status);
                                if (mobileStatus >= 0)
                                {
                                    //wei=> nbItem.SmallImageIndex = ResManager.STATUS_MOBILE;
                                }
                                if (status >= 0)
                                {
                                    nbItem.SmallImageIndex = status;
                                }
                                else if (item.Subscription == SubscriptionType.from || item.Subscription == SubscriptionType.none)
                                {
                                    //wei=> nbItem.SmallImageIndex = ResManager.STATUS_UNSUBSCRIBED;
                                }
                                else
                                {
                                    //wei=>nbItem.SmallImageIndex = ResManager.STATUS_OFFLINE;
                                }
                            }
                            if (nbItem == null)
                            {
                            }
                            if (group == null)
                            {
                            }
                            if (group.ItemLinks == null)
                            {
                            }
                            // ???????????????????????????问题:对象当前正在其他地方使用。
                            group.ItemLinks.Add(nbItem);
                        }
                        // 添加“移动组”子菜单
                        AddMoveGroupMenu(groupName);
                    }
                    // 添加“新增组”菜单
                    AddMoveGroupMenu(MENU_NEW_GROUP);

                    //wei=>XmppRosterManager.Instance.Add(item);

                    if (needSort)
                    {
                        waitcall.Run();
                    }
                }
                else if (item.Subscription == SubscriptionType.remove)
                {
                    RemoveMyRoster(item);
                    //wei=>XmppRosterManager.Instance.Remove(item);
                    return;
                }
                else
                {
                    return;
                }
            }
            //wei=>});
        }
Ejemplo n.º 21
0
 private static void XmppClientOnRosterItem(object sender, RosterItem item)
 {
     BuddyList.AddBuddyIfNotExists(item);
 }
Ejemplo n.º 22
0
        // 发送用户列表
        private void ProcessRosterIQ(IQ iq)
        {
            if (iq.Type == IqType.get)
            {

                //获取用户列表
                for (int i = 0; i < Online.onlineuser.Count; i++)
                {
                    RosterItem ri = new RosterItem();
                    ri.Name = Online.onlineuser[i].ToString();
                    ri.Subscription = SubscriptionType.both;
                    ri.Jid = new Jid(ri.Name + "@localhost");
                    iq.Query.AddChild(ri);
                }
                Send(iq);

                //将其他人的信息发送
                Presence pre;
                pre = new Presence();
                pre.Show = ShowType.chat;
                foreach (XmppServerConnection con in Online.onlineuser)
                {
                    pre.From = con.jid;
                    pre.Value = con.m_Sock.RemoteEndPoint.ToString();
                    Send(pre);
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// The xmpp on on roster item.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="item">
        /// The item.
        /// </param>
        private void XmppOnOnRosterItem(object sender, RosterItem item)
        {
            // Friends.Add(item.);
            switch (item.Subscription)
            {
                case SubscriptionType.to:
                    if (item.Jid.User == this.Me.UserName)
                    {
                        break;
                    }

                    if (item.Jid.Server == "conference." + this.Config.ChatHost)
                    {
                        this.Chatting.GetRoom(new User(item.Jid), true);
                    } else if (this.Friends.Count(x => x.UserName == item.Jid.User) == 0)
                    {
                        this.Friends.Add(new User(item.Jid));
                    }

                    break;
                case SubscriptionType.from:
                    if (item.Jid.User == this.Me.UserName)
                    {
                        break;
                    }

                    if (this.Friends.Count(x => x.UserName == item.Jid.User) == 0)
                    {
                        this.Friends.Add(new User(item.Jid));
                    }

                    break;
                case SubscriptionType.both:
                    if (item.Jid.User == this.Me.UserName)
                    {
                        break;
                    }

                    if (this.Friends.Count(x => x.UserName == item.Jid.User) == 0)
                    {
                        this.Friends.Add(new User(item.Jid));
                    }

                    break;
                case SubscriptionType.remove:
                    if (this.Friends.Contains(new User(item.Jid)))
                    {
                        this.Friends.Remove(new User(item.Jid));
                    }

                    break;
            }
        }
Ejemplo n.º 24
0
 public void AddRosterItem(RosterItem r)
 {
     ChildNodes.Add(r);
 }
Ejemplo n.º 25
0
        private Contact AddRosterItem(RosterItem item)
        {
            Contact contact;

            lock (_items._syncObject)
            {
                // for now
                contact = Database.GetContact(item);

                MetaContact metaContact = null;

                if (contact != null)
                {
                    metaContact = Database.GetMetaContact(contact.MetaId);
                }

                if (metaContact == null)
                {
                    metaContact = new MetaContact();
                    Database.SaveMetaContact(metaContact);

                    contact = new Contact(item, metaContact.Id);
                    Database.SaveContact(contact);
                }

                metaContact.AddContact(contact);

                _realContacts.Add(item.Jid.Bare.ToLowerInvariant(), contact);

                _items.Add(metaContact);
            }

            Vcard vcard = Storage.GetVcard(contact.Jid, 99999);

            if (vcard != null)
            {
                contact.SetVcard(vcard);
                contact.HasVCardRecieved = false;
            }

            return contact;
        }
Ejemplo n.º 26
0
        private void DistributeMessage(Message message, Chatstate chatstate)
        {
            lock (_items._syncObject)
            {
                Contact contact = FindContact(message.From);

                if (contact == null)
                {
                    RosterItem rosterItem = new RosterItem(message.From);

                    contact = AddRosterItem(rosterItem);
                }

                List<ContactChat> contactChats = GetContactChats(contact);

                foreach (ContactChat chat in contactChats)
                {
                    if (message.Body != null)
                    {
                        chat.Messages.Add(message);
                    }

                    chat.ChatState = chatstate;
                }

                if (message.Body != null)
                {
                    RecentItems.Instance.Add(contact);
                    Events.Instance.OnEvent(this, new EventChatMessage(contact, message, (contactChats.Count > 0)));
                }
            }
        }
Ejemplo n.º 27
0
 private void OnRosterItem(object sender, RosterItem item)
 {
     _roster.TryAdd(item.Jid.User, item.Name);
 }
Ejemplo n.º 28
0
 public static bool Subscribed(RosterItem item)
 {
     return item.Subscription == SubscriptionType.both ||
            item.Subscription == SubscriptionType.to;
 }
Ejemplo n.º 29
0
        void OnRosterItem(object sender, RosterItem rosterItem)
        {
            // setting to none also removes the person from chat, as we'd never get an offline message anymore
            if (rosterItem.Subscription == SubscriptionType.none
                || rosterItem.Subscription == SubscriptionType.remove) {
                if (rosterItem.Subscription == SubscriptionType.remove) {
                    Contacts.Remove(rosterItem.Jid);
                }
                if (ContactChat == null) {
                    return;
                }
                PersonModel oldp = ContactChat.GetPerson(rosterItem.Jid);
                if (oldp == null) {
                    // doesn't exist, don't need to do anything
                    return;
                }
                Session.RemovePersonFromGroupChat(ContactChat, oldp);
                return;
            }
            // create or update a roster item
            var contact = GetOrCreateContact(rosterItem.Jid.Bare, rosterItem.Name ?? rosterItem.Jid);
            contact.Temporary = false;
            contact.Subscription = rosterItem.Subscription;
            contact.Ask = rosterItem.Ask;
            string oldIdentityName = contact.IdentityName;
            var oldIdentityNameColored = contact.IdentityNameColored;

            contact.IdentityName = rosterItem.Name ?? rosterItem.Jid;

            if (oldIdentityName == contact.IdentityName) {
                // identity name didn't change
                // the rest of this function only handles changed identity names
                return;
            }

            contact.IdentityNameColored = null; // uncache
            ProcessIdentityNameChanged(contact, oldIdentityNameColored, oldIdentityName);
        }
Ejemplo n.º 30
0
 static void xmppCon_OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
 {
     PrintInfo(String.Format("Got contact: {0}", item.Jid));
 }
Ejemplo n.º 31
0
            private void ProcessRosterIQ(IQ iq)
            {
                bool bSend = false;
                if (iq.Type == IqType.get)
                {
                    // Send the roster
                    // we send a dummy roster here, you should retrieve it from a
                    // database or some kind of directory (LDAP, AD etc...)

                    RosterIq rosterIq = new RosterIq(IqType.result);
                    rosterIq.Namespace = agsXMPP.Uri.CLIENT;
                    rosterIq.Id = iq.Id;
                    rosterIq.From = iq.To;
                    rosterIq.To = this.m_ClientAccount.JID;

                    foreach (Friend friend in this.m_ClientAccount.Friends)
                    {
                        RosterItem ri = new RosterItem();
                        ri.Name = friend.Nick;
                        ri.Subscription = friend.SubscriptionType;

                        ////............
                        //friend.JID.Resource = friend.Resource[0];

                        ri.Jid = friend.JID;
                        foreach (string strGroup in friend.Groups)
                        {
                            ri.AddGroup(strGroup);
                        }

                        rosterIq.Query.AddRosterItem(ri);
                    }

                    Send(rosterIq);

                }
                else if (iq.Type == IqType.set)
                {
                    //Received: 
                    //<iq xmlns="jabber:client" id="agsXMPP_18" type="set">
                    //    <query xmlns="jabber:iq:roster">
                    //        <item jid="test2@localhost"/>
                    //    </query>
                    //</iq>

                    //Send: 
                    //<iq xmlns="jabber:client" type="set" id="712">
                    //    <query xmlns="jabber:iq:roster">
                    //        <item name="test2" jid="test2@localhost" subscription="none"/>
                    //    </query>
                    //</iq>

                    //Send: 
                    //<iq xmlns="jabber:client" from="test@localhost/MF" to="test@localhost/MF" type="result" id="agsXMPP_18" />

                    Roster oldRoster = iq.Query as Roster;

                    RosterItem[] rosterItems = oldRoster.GetRoster();

                    Friend friend = null;

                    foreach (RosterItem rosterItem in rosterItems)
                    {
                        if (rosterItem.HasAttribute("subscription"))
                        {
                            if (rosterItem.Subscription == SubscriptionType.remove)
                            {
                                friend = this.m_ClientAccount.FindFriend(rosterItem.Jid.ToString());
                                if (friend == null)
                                {
                                    IQ error = new IQ(IqType.error);
                                    error.Namespace = iq.Namespace;
                                    error.Id = iq.Id;
                                    error.To = this.m_ClientAccount.JID;

                                    Send(error);
                                }

                                this.m_ClientAccount.RemoveFriend(friend);


                                RosterIq newRosterIq = null;
                                RosterItem ri = null;

                                Presence newPresence = null;

                                Account contactAccount = this.m_Server.AccountManager.FindAccount(rosterItem.Jid.ToString());
                                Friend userFriend = contactAccount.FindFriend(this.m_ClientAccount.JID.ToString());
                                if (userFriend == null)
                                {

                                    //RECV: 
                                    //<iq xmlns="jabber:client" id="agsXMPP_17" type="set">
                                    //    <query xmlns="jabber:iq:roster">
                                    //        <item jid="test@localhost" subscription="remove" />
                                    //    </query>
                                    //</iq>

                                    //SEND: <iq type="result" id="agsXMPP_17" to="test2@localhost/MF" from="test2@localhost/MF" />

                                    IQ result = new IQ(IqType.result);
                                    result.Id = iq.Id;
                                    result.From = this.m_ClientAccount.JID;
                                    result.To = this.m_ClientAccount.JID;
                                    Send(result);


                                    //SEND: 
                                    //<iq id="221" type="set">
                                    //    <query xmlns="jabber:iq:roster">
                                    //        <item jid="test@localhost" subscription="remove" />
                                    //    </query>
                                    //</iq>

                                    newRosterIq = new RosterIq(IqType.set);
                                    newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                                    ri = new RosterItem();
                                    ri.Name = rosterItem.Name;
                                    ri.Jid = rosterItem.Jid;
                                    ri.Subscription = rosterItem.Subscription;

                                    newRosterIq.Query.AddRosterItem(ri);

                                    Send(newRosterIq);


                                    //SEND: <presence from="test2@localhost/MF" xml:lang="zh-cn" type="unavailable" to="test@localhost/MF" />
                                    newPresence = new Presence();
                                    newPresence.From = this.m_ClientAccount.JID;
                                    newPresence.To = rosterItem.Jid;
                                    newPresence.Type = PresenceType.unavailable;
                                    newPresence.Language = this.objClientlanguage.Name;

                                    bSend = Send(newPresence.To, newPresence);
                                    if (!bSend)
                                    {

                                    }

                                }
                                else
                                {
                                    if (userFriend.SubscriptionType == SubscriptionType.both)
                                    {

                                        userFriend.SubscriptionType = SubscriptionType.to;
                                        userFriend.Save();

                                        newRosterIq = new RosterIq(IqType.set);
                                        newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                                        ri = new RosterItem();
                                        ri.Name = userFriend.Nick;
                                        ri.Jid = userFriend.JID;
                                        ri.Subscription = userFriend.SubscriptionType;

                                        newRosterIq.Query.AddRosterItem(ri);

                                        bSend = Send(rosterItem.Jid, newRosterIq);
                                        if (!bSend)
                                        {

                                        }

                                        newPresence = new Presence();
                                        newPresence.From = this.m_ClientAccount.JID;
                                        newPresence.To = rosterItem.Jid;

                                        newPresence.Type = PresenceType.unsubscribe;
                                        bSend = Send(rosterItem.Jid, newPresence);
                                        if (!bSend)
                                        {

                                        }

                                        userFriend.SubscriptionType = SubscriptionType.none;
                                        userFriend.Save();

                                        newRosterIq = new RosterIq(IqType.set);
                                        newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                                        ri = new RosterItem();
                                        ri.Name = userFriend.Nick;
                                        ri.Jid = userFriend.JID;
                                        ri.Subscription = userFriend.SubscriptionType;

                                        newRosterIq.Query.AddRosterItem(ri);

                                        bSend = Send(rosterItem.Jid, newRosterIq);
                                        if (!bSend)
                                        {

                                        }

                                        newPresence.Type = PresenceType.unsubscribed;
                                        bSend = Send(rosterItem.Jid, newPresence);
                                        if (!bSend)
                                        {

                                        }

                                        newPresence = new Presence();
                                        newPresence.From = rosterItem.Jid;
                                        newPresence.To = this.m_ClientAccount.JID;
                                        newPresence.Type = PresenceType.unavailable;
                                        newPresence.Language = this.objClientlanguage.Name;

                                        bSend = Send(newPresence.To, newPresence);
                                        if (!bSend)
                                        {

                                        }

                                        newPresence.SwitchDirection();
                                        bSend = Send(newPresence.To, newPresence);
                                        if (!bSend)
                                        {

                                        }

                                        IQ result = new IQ(IqType.result);
                                        result.Id = iq.Id;
                                        result.From = this.m_ClientAccount.JID;
                                        result.To = this.m_ClientAccount.JID;
                                        Send(result);


                                        newRosterIq = new RosterIq(IqType.set);
                                        newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                                        ri = new RosterItem();
                                        ri.Name = rosterItem.Name;
                                        ri.Jid = rosterItem.Jid;
                                        ri.Subscription = rosterItem.Subscription;

                                        newRosterIq.Query.AddRosterItem(ri);

                                        Send(newRosterIq);


                                    }
                                    else if (userFriend.SubscriptionType == SubscriptionType.from)
                                    {
                                        contactAccount.RemoveFriend(userFriend);
                                        contactAccount.Save();

                                        newPresence = new Presence();
                                        newPresence.From = this.m_ClientAccount.JID;
                                        newPresence.To = rosterItem.Jid;
                                        newPresence.Type = PresenceType.unavailable;
                                        newPresence.Language = this.objClientlanguage.Name;

                                        bSend = Send(newPresence.To, newPresence);
                                        if (!bSend)
                                        {

                                        }

                                        IQ result = new IQ(IqType.result);
                                        result.Id = iq.Id;
                                        result.From = this.m_ClientAccount.JID;
                                        result.To = this.m_ClientAccount.JID;
                                        Send(result);


                                        newRosterIq = new RosterIq(IqType.set);
                                        newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                                        ri = new RosterItem();
                                        ri.Name = rosterItem.Name;
                                        ri.Jid = rosterItem.Jid;
                                        ri.Subscription = rosterItem.Subscription;

                                        newRosterIq.Query.AddRosterItem(ri);

                                        Send(newRosterIq);

                                    }
                                    else if (userFriend.SubscriptionType == SubscriptionType.to)
                                    {
                                        userFriend.SubscriptionType = SubscriptionType.none;
                                        userFriend.Save();

                                        newRosterIq = new RosterIq(IqType.set);
                                        newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                                        ri = new RosterItem();
                                        ri.Name = userFriend.Nick;
                                        ri.Jid = userFriend.JID;
                                        ri.Subscription = userFriend.SubscriptionType;

                                        newRosterIq.Query.AddRosterItem(ri);

                                        bSend = Send(rosterItem.Jid, newRosterIq);
                                        if (!bSend)
                                        {

                                        }

                                        newPresence = new Presence();
                                        newPresence.From = this.m_ClientAccount.JID;
                                        newPresence.To = rosterItem.Jid;
                                        newPresence.Type = PresenceType.unsubscribed;
                                        bSend = Send(newPresence.To, newPresence);
                                        if (!bSend)
                                        {

                                        }

                                        newPresence = new Presence();
                                        newPresence.From = this.m_ClientAccount.JID;
                                        newPresence.To = rosterItem.Jid;
                                        newPresence.Type = PresenceType.unavailable;
                                        newPresence.Language = this.objClientlanguage.Name;

                                        bSend = Send(newPresence.To, newPresence);
                                        if (!bSend)
                                        {

                                        }

                                        IQ result = new IQ(IqType.result);
                                        result.Id = iq.Id;
                                        result.From = this.m_ClientAccount.JID;
                                        result.To = this.m_ClientAccount.JID;
                                        Send(result);


                                        newRosterIq = new RosterIq(IqType.set);
                                        newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                                        ri = new RosterItem();
                                        ri.Name = rosterItem.Name;
                                        ri.Jid = rosterItem.Jid;
                                        ri.Subscription = rosterItem.Subscription;

                                        newRosterIq.Query.AddRosterItem(ri);

                                        Send(newRosterIq);


                                    }
                                    else
                                    {

                                    }
                                }

                                ///Save friend Roster to Xml
                                this.m_Server.AccountManager.Save();

                                return;

                            }
                            else
                            {
                                friend = this.m_ClientAccount.FindFriend(rosterItem.Jid.ToString());
                                if (friend == null)
                                {
                                    friend = this.m_ClientAccount.AddFriend();
                                }

                                ///******************************************************
                                ///JID中已经包含有Company,Friend中是否还需要Company信息
                                ///******************************************************
                                friend.JID = rosterItem.Jid;
                                friend.Nick = rosterItem.Name;

                                friend.SubscriptionType = rosterItem.Subscription;
                                friend.SubscriptionStatus = int.Parse(rosterItem.Ask.ToString("D"));

                                foreach (Element groupItem in rosterItem.GetGroups())
                                {
                                    friend.AddGroup(groupItem.InnerXml);
                                }
                                friend.Save();


                                //if (friend.Groups.Count == 0)
                                //{
                                //    friend.AddGroup(friend.Company);
                                //}

                                // push roster set iq to all the resurce
                                RosterIq newRosterIq = new RosterIq(IqType.set);
                                newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                                RosterItem ri = new RosterItem();
                                if (rosterItem.Name == null || rosterItem.Name == string.Empty)
                                {
                                    ri.Name = rosterItem.Jid.User;
                                }
                                else
                                {
                                    ri.Name = rosterItem.Name;
                                }

                                ri.Jid = rosterItem.Jid;
                                ri.Subscription = SubscriptionType.none;

                                ///******************************************************
                                ///订阅用户的分组信息需要考虑?
                                ///******************************************************
                                foreach (Element groupItem in rosterItem.GetGroups())
                                {
                                    ri.AddGroup(groupItem.InnerXml);
                                }

                                newRosterIq.Query.AddRosterItem(ri);

                                //Push roster update to all client
                                //foreach (Account account in this.m_Server.ClientConnections.Keys)
                                //{
                                //    if (account.JID.Bare.ToLower() == this.m_ClientAccount.JID.Bare.ToLower())
                                //    {
                                //        //this.m_Server.ClientConnections[account].Send(newRosterIq);
                                //        SendToAllResource(account, newRosterIq);
                                //    }
                                //}

                                bSend = Send(this.m_ClientAccount, newRosterIq);
                                if (!bSend)
                                {

                                }

                            }
                        }
                        else
                        {
                            friend = this.m_ClientAccount.FindFriend(rosterItem.Jid.ToString());
                            if (friend == null)
                            {
                                friend = this.m_ClientAccount.AddFriend();

                                ///******************************************************
                                ///JID中已经包含有Company,Friend中是否还需要Company信息
                                ///******************************************************
                                friend.JID = rosterItem.Jid;
                                friend.SubscriptionType = SubscriptionType.none;
                                friend.SubscriptionStatus = -1;
                            }

                            friend.Nick = rosterItem.Name;

                            friend.Groups.Clear();

                            foreach (Element groupItem in rosterItem.GetGroups())
                            {
                                friend.AddGroup(groupItem.InnerXml);
                            }

                            friend.Save();

                            //if (friend.Groups.Count == 0)
                            //{
                            //    friend.AddGroup(friend.Company);
                            //}

                            // push roster set iq to all the resurce
                            RosterIq newRosterIq = new RosterIq(IqType.set);
                            newRosterIq.Namespace = agsXMPP.Uri.CLIENT;

                            RosterItem ri = new RosterItem();
                            if (rosterItem.Name == null || rosterItem.Name == string.Empty)
                            {
                                ri.Name = rosterItem.Jid.User;
                            }
                            else
                            {
                                ri.Name = rosterItem.Name;
                            }
                            ri.Jid = rosterItem.Jid;
                            ri.Subscription = friend.SubscriptionType;

                            ///******************************************************
                            ///订阅用户的分组信息需要考虑?
                            ///******************************************************
                            foreach (string strGroup in friend.Groups)
                            {
                                ri.AddGroup(strGroup);
                            }

                            newRosterIq.Query.AddRosterItem(ri);

                            //Push roster update to all client
                            //foreach (Account account in this.m_Server.ClientConnections.Keys)
                            //{
                            //    if (account.JID.Bare.ToLower() == this.m_ClientAccount.JID.Bare.ToLower())
                            //    {
                            //        //this.m_Server.ClientConnections[account].Send(newRosterIq);
                            //        SendToAllResource(account, newRosterIq);
                            //    }
                            //}

                            bSend = Send(this.m_ClientAccount, newRosterIq);
                            if (!bSend)
                            {

                            }

                        }


                        //Send Result IQ
                        IQ newIq = new IQ(IqType.result);
                        newIq.Namespace = agsXMPP.Uri.CLIENT;
                        newIq.Id = iq.Id;
                        //newIq.From = this.m_ClientAccount.JID;
                        //newIq.To = this.m_ClientAccount.JID;
                        Send(newIq);

                        ///Save friend Roster to Xml
                        this.m_Server.AccountManager.Save();
                    }

                }
            }
Ejemplo n.º 32
0
 private void xmppCon_OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item) // Este evento me trae TODOS mis contactos.
 {
     Contactos.Add(item);                                                                     // Agrego la lista de usuarios.
 }
Ejemplo n.º 33
0
 private void OnClientRosterItem(object sender, RosterItem item)
 {
     if (!_roster.ContainsKey(item.Jid.User))
     {
         _roster.Add(item.Jid.User, item.Name);
         Logger.Info(string.Format("User '{0}' logged in", item.Name));
     }
 }
Ejemplo n.º 34
0
 private void ProcessRosterIQ(IQ iq)
 {
     if (iq.Type == IqType.get)
     {
         // Send the roster
         // we send a dummy roster here, you should retrieve it from a
         // database or some kind of directory (LDAP, AD etc...)
         iq.SwitchDirection();
         iq.Type = IqType.result;
         for (int i=1; i<11;i++)
         {
             RosterItem ri = new RosterItem();
             ri.Name = "Item " + i.ToString();
             ri.Subscription = SubscriptionType.both;
             ri.Jid = new Jid("item" + i.ToString() + "@localhost");
             ri.AddGroup("localhost");
             iq.Query.AddChild(ri);
         }
         for (int i=1; i<11;i++)
         {
             RosterItem ri = new RosterItem();
             ri.Name = "Item JO " + i.ToString();
             ri.Subscription = SubscriptionType.both;
             ri.Jid = new Jid("item" + i.ToString() + "@jabber.org");
             ri.AddGroup("JO");
             iq.Query.AddChild(ri);
         }
         Send(iq);
     }
 }
Ejemplo n.º 35
0
        internal static void RostManager_OnRosterItem(object sender, RosterItem ri)
        {
            UpdatePlayers = true;
            if (AllPlayers.ContainsKey(ri.Jid.User))
                return;

            var player = new ChatPlayerItem
            {
                Id = ri.Jid.User,
                Group = "Online"
            };
            //using (XmlReader reader = XmlReader.Create(new StringReader(ri.OuterXml)))
            using (XmlReader reader = XmlReader.Create(new StringReader(ri.ToString())))
            {
                while (reader.Read())
                {
                    if (!reader.IsStartElement())
                        continue;

                    switch (reader.Name)
                    {
                        case "group":
                            reader.Read();
                            string TempGroup = reader.Value;
                            if (TempGroup != "**Default")
                                player.Group = TempGroup;
                            break;
                    }
                }
            }
            player.Username = ri.Name;
            AllPlayers.Add(ri.Jid.User, player);
        }
Ejemplo n.º 36
0
 public void OnRosterItem(object sender, RosterItem item)
 {
     App.InvokeSafe(App._dispatcherPriority,
                    new RosterItemCallback(OnRosterItem), item);
 }
Ejemplo n.º 37
0
 private void onRosterItem(object sender, RosterItem item)
 {
     m_Logger.log(ELogLevel.LVL_TRACE, "Add new Roster item!", m_sModuleName);
     //TODO: check if roster item is already in addressbook
     m_Contacts.Add(item.GetAttribute("jid").ToString(), item.GetAttribute("name").ToString());
     m_ClientConnection.MessageGrabber.Add(item.Jid, new BareJidComparer(), new MessageCB(MessageCallback), null);
 }
Ejemplo n.º 38
0
 public void AddRosterItem(RosterItem r)
 {
     this.ChildNodes.Add(r);
 }
 static void HipchatClient_OnRosterItem(object sender, RosterItem item)
 {
     Users.Add(item);
     Lobby.DoUserCheck();
 }
Ejemplo n.º 40
0
        private void OnRosterItem(RosterItem item)
        {
            lock (_items._syncObject)
            {
                Contact contact = FindContact(item.Jid);

                if (contact == null)
                {
                    AddRosterItem(item);
                }
                else if (item.Subscription == SubscriptionType.remove)
                {
                    RemoveRosterItem(contact);
                }
                else if (item.Ask == AskType.NONE)
                {
                    contact.RosterItem = item;
                }
            }
        }
Ejemplo n.º 41
0
        private void XmppOnOnRosterItem(object sender, RosterItem item)
        {
            //Friends.Add(item.);
            switch(item.Subscription)
            {
                case SubscriptionType.none:
					if (item.Jid.Server == "conference." + Host)
                    {
                        Chatting.GetRoom(new NewUser(item.Jid),true);
                    }
                    break;
                case SubscriptionType.to:
                    if(Friends.Count(x=>x.User.User == item.Jid.User) == 0)
                        Friends.Add(new NewUser(item.Jid));
                    break;
                case SubscriptionType.from:
                    if(Friends.Count(x=>x.User.User == item.Jid.User) == 0)
                    Friends.Add(new NewUser(item.Jid));
                    break;
                case SubscriptionType.both:
                    if(Friends.Count(x=>x.User.User == item.Jid.User) == 0)
                    Friends.Add(new NewUser(item.Jid));
                    break;
                case SubscriptionType.remove:
                    if (Friends.Contains(new NewUser(item.Jid)))
                        Friends.Remove(new NewUser(item.Jid));
                    break;
            }
        }
Ejemplo n.º 42
0
        private void onRosterItem(object sender, RosterItem item)
        {
            m_Logger.log(ELogLevel.LVL_TRACE, "Add new Roster item!", m_sModuleName);
            m_Contacts.Add(item.GetAttribute("jid").ToString(), item.GetAttribute("name").ToString());
            m_ClientConnection.MessageGrabber.Add(item.Jid, new BareJidComparer(), new MessageCB(MessageCallback), null);

            Contact _contact = m_ContactManager.getContactById (item.GetAttribute ("jid").ToString ());

            //checks if contact is in addressbook
            //TODO: check if this test works
            if (_contact.id == null) {
                Contact newContact = new Contact ();
                newContact.bIsXmppSupported = true;
                newContact.bIsEmailSupported = null;
                newContact.id = item.GetAttribute ("jid").ToString ();
                newContact.nickname = item.GetAttribute ("name").ToString ();

                return;
            }

            //Update contacts xmpp support
            _contact.bIsXmppSupported = true;

            //TODO: check if update contact is needed
            //m_ContactManager.updateContact (_contact);
        }