void UpdateRelationshipView(HashSet <string> set, string group) { listView1.BeginUpdate(); foreach (var key in set) { NIM.Friend.NIMFriendProfile profile = null; if (_friendsDictionary.ContainsKey(key)) { profile = _friendsDictionary[key]; } else { profile = new NIM.Friend.NIMFriendProfile(); profile.AccountId = key; } if (listView1.Items.ContainsKey(key + "_" + group)) { listView1.Items.RemoveByKey(key + "_" + group); } AddFriendListItem(profile, int.Parse(group)); } for (int i = 0; i < listView1.Items.Count; i++) { var item = listView1.Items[i] as ListViewItem; if (item.Group != _groups[int.Parse(group)]) { continue; } if (!set.Contains(item.Tag.ToString())) { listView1.Items.RemoveByKey(item.Name); } } listView1.EndUpdate(); }
private void UserCard_Load(object sender, EventArgs e) { NIM.Friend.FriendAPI.GetFriendProfile(_userId, (id, ret) => { Action <NIM.Friend.NIMFriendProfile> action = (profile) => { _profile = profile; if (profile != null) { var p1 = CreateFormContent(profile); _contentPanel = p1; Button btn1 = new Button(); btn1.Dock = DockStyle.Bottom; btn1.Text = "更新"; btn1.Click += (s, args) => { UpdateFriendProfile(); }; p1.Height += 50; p1.Controls.Add(btn1); this.splitContainer1.Panel1.Controls.Add(p1); this.splitContainer1.Panel1.SetBounds(0, 0, p1.Width, p1.Height); } }; this.Invoke(action, ret); }); NIM.User.UserAPI.QueryUserNameCardOnline(new List <string>() { _userId }, (ret) => { if (ret == null || !ret.Any()) { return; } _userCard = ret[0]; Action action = () => { var p = CreateFormContent(_userCard); _cardPanel = p; //Button btn1 = new Button(); //btn1.Dock = DockStyle.Bottom; //btn1.Text = "更新"; //btn1.Click += (s, args) => //{ // UpdateCard(); //}; //p.Controls.Add(btn1); this.splitContainer1.Panel2.Controls.Add(p); this.splitContainer1.Panel2.SetBounds(0, 0, p.Width, p.Height); }; this.Invoke(action); }); }
void AddFriendListItem(NIM.Friend.NIMFriendProfile profile, int group = 0) { ListViewItem item = new ListViewItem(); item.SubItems.Add(profile.AccountId); item.Text = profile.AccountId; item.Tag = profile.AccountId; item.Name = string.Format("{0}_{1}", profile.AccountId, group); item.Group = _groups[group]; listView1.Items.Add(item); UpdateFriendLoginState(profile.AccountId, 2); NIM.NIMSubscribeApi.Subscribe(1, 24 * 60 * 60, NIMEventSubscribeSyncEventType.kNIMEventSubscribeSyncTypeSync, new List <string> { profile.AccountId }, (ResponseCode code, int type, List <string> failedIDList) => { }); }