Ejemplo n.º 1
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.º 2
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);
        }
        /// <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=>});
        }