Esempio n. 1
0
 private void OnReceivedSysNotification(object sender, NIMSysMsgEventArgs e)
 {
     if (e.Message == null || e.Message.Content == null)
     {
         return;
     }
     DemoTrace.WriteLine("系统通知:" + e.Dump());
     if (e.Message.Content.MsgType == NIMSysMsgType.kNIMSysMsgTypeTeamInvite)
     {
         NIM.Team.TeamAPI.AcceptTeamInvitation(e.Message.Content.ReceiverId, e.Message.Content.SenderId, (x) =>
         {
         });
     }
 }
        private void okBtn_Click(object sender, EventArgs e)
        {
            Action <string> createTeam = (url) =>
            {
                NIM.Team.NIMTeamInfo tinfo = new NIM.Team.NIMTeamInfo();
                tinfo.Name             = teamNameBox.Text;
                tinfo.Introduce        = teamIntroBox.Text;
                tinfo.TeamIcon         = url;;
                tinfo.JoinMode         = (NIM.Team.NIMTeamJoinMode)joinModeCombox.SelectedIndex;
                tinfo.BeInvitedMode    = (NIM.Team.NIMTeamBeInviteMode)neddAgreeCombox.SelectedIndex;
                tinfo.InvitedMode      = (NIM.Team.NIMTeamInviteMode)inviteModeCombox.SelectedIndex;
                tinfo.UpdateMode       = (NIM.Team.NIMTeamUpdateInfoMode)modifyModeCombox.SelectedIndex;
                tinfo.UpdateCustomMode = (NIM.Team.NIMTeamUpdateCustomMode)modifyPropertyModeCombox.SelectedIndex;
                tinfo.TeamType         = NIM.Team.NIMTeamType.kNIMTeamTypeAdvanced;
                string[] uids = teamMemberBox.Text.Replace("\r\n", "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (uids.Any())
                {
                    NIM.Team.TeamAPI.CreateTeam(tinfo, uids, textBox1.Text, (a) =>
                    {
                        DemoTrace.WriteLine(a.Dump());
                        if (a.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess ||
                            a.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResTeamInviteSuccess)
                        {
                            _teamlist.AddTeamItem(a.TeamEvent.TeamId);
                        }
                    });
                }
            };

            if (!string.IsNullOrEmpty(teamIconPathBox.Text))
            {
                NIM.Nos.NosAPI.Upload(teamIconPathBox.Text, (x, y) =>
                {
                    var url = x == 200 ? y : "";
                    this.Invoke(createTeam, url);
                }, null);
            }
            else
            {
                createTeam("");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 登录结果处理
        /// </summary>
        /// <param name="result"></param>
        private void HandleLoginResult(NIM.NIMLoginResult result)
        {
            DemoTrace.WriteLine(result.LoginStep.ToString());
            Action action = () =>
            {
                if (result.LoginStep == NIM.NIMLoginStep.kNIMLoginStepLogin)
                {
                    if (result.Code == NIM.ResponseCode.kNIMResSuccess)
                    {
                        this.Hide();
                        new MainForm(_userName).Show();


                        //PublishLoginEvent();
                    }
                    else
                    {
                        // NIM.ClientAPI.Logout(NIM.NIMLogoutType.kNIMLogoutChangeAccout, HandleLogoutResult);
                    }
                }
            };

            this.Invoke(action);
        }
Esempio n. 4
0
        private void _teamListView_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }
            var         items       = _teamListView.SelectedItems;
            ContextMenu contextMenu = new ContextMenu();

            if (items.Count == 0)
            {
                MenuItem mi = new MenuItem("创建群", (s, args) =>
                {
                    CreateTeamForm f    = new CreateTeamForm(FormType.CreateTeam);
                    f.MembersIDSelected = (n, ids) =>
                    {
                        NIM.Team.NIMTeamInfo i = new NIM.Team.NIMTeamInfo();
                        i.TeamType             = NIMTeamType.kNIMTeamTypeNormal;
                        i.Name = n;

                        NIM.Team.TeamAPI.CreateTeam(i, ids, "", (ret) =>
                        {
                            if (ret.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
                            {
                                AddTeamItem(ret.TeamEvent.TeamId);
                                if (ret.TeamEvent.InvalidIDList != null && ret.TeamEvent.InvalidIDList.Count > 0)
                                {
                                    var failed = ret.TeamEvent.InvalidIDList.Aggregate((a, b) => { return(a + "  " + b); });
                                    MessageBox.Show(string.Format("{0} 加入群 {1} 失败", failed, ret.TeamEvent.TeamId));
                                }
                            }
                            else
                            {
                                MessageBox.Show("创建群失败:" + ret.TeamEvent.ResponseCode.ToString());
                            }
                        });
                    };
                    f.Show();
                });
                MenuItem mi2 = new MenuItem("创建高级群", (s, args) =>
                {
                    CreateAdvancedTeamForm f = new CreateAdvancedTeamForm(this);
                    f.Show();
                });

                MenuItem mi3 = new MenuItem("查询自己在群中的信息", (s, args) =>
                {
                    NIM.Team.TeamAPI.QueryMyInfoInEachTeam((list) =>
                    {
                    });
                });

                contextMenu.MenuItems.Add(mi);
                contextMenu.MenuItems.Add(mi2);
                contextMenu.MenuItems.Add(mi3);
            }
            else
            {
                var tid   = items[0].Name;
                var tinfo = NIM.Team.TeamAPI.QueryCachedTeamInfo(tid);
                if (tinfo.TeamType == NIMTeamType.kNIMTeamTypeAdvanced)
                {
                    var mt = new MenuItem("解散群", (s, args) =>
                    {
                        NIM.Team.TeamAPI.DismissTeam(tid, (ret) =>
                        {
                            if (ret.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
                            {
                                RemoveTeamItem(tid);
                            }
                            else
                            {
                                MessageBox.Show("解散群失败:" + ret.TeamEvent.ResponseCode.ToString());
                            }
                        });
                    });
                    contextMenu.MenuItems.Add(mt);
                }

                var m1 = new MenuItem("退群", (s, args) =>
                {
                    NIM.Team.TeamAPI.LeaveTeam(tid, (ret) =>
                    {
                        if (ret != null && ret.TeamEvent != null && ret.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
                        {
                            RemoveTeamItem(tid);
                        }
                        else
                        {
                            MessageBox.Show("退出群失败:" + ret.TeamEvent.ResponseCode.ToString());
                        }
                    });
                });

                MenuItem m3 = new MenuItem("群信息", (s, args) =>
                {
                    Action <NIM.Team.NIMTeamInfo, string> action = (info, text) =>
                    {
                        ObjectPropertyInfoForm form = new ObjectPropertyInfoForm();
                        form.TargetObject           = info;
                        form.Text = text;
                        form.UpdateObjectAction = (obj) =>
                        {
                            var newInfo      = obj as NIMTeamInfo;
                            var tmp          = new NIMTeamInfo();
                            tmp.TeamId       = newInfo.TeamId;
                            tmp.Name         = newInfo.Name;
                            tmp.Announcement = newInfo.Announcement;
                            tmp.Custom       = newInfo.Custom;
                            tmp.TeamType     = newInfo.TeamType;
                            NIM.Team.TeamAPI.UpdateTeamInfo(tid, tmp, (ret) =>
                            {
                                if (ret.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
                                {
                                    UpdateTeamItem(ret.TeamEvent.TeamInfo);
                                }
                            });
                        };
                        form.Show();
                    };
                    Action <NIM.Team.NIMTeamInfo, string> show = (info, text) =>
                    {
                        _actionWrapper.InvokeAction(action, info, text);
                    };
                    NIM.Team.TeamAPI.QueryCachedTeamInfo(tid, (id, info) =>
                    {
                        show(info, "本地群信息");
                    });
                    NIM.Team.TeamAPI.QueryTeamInfoOnline(tid, (info) =>
                    {
                        show(info.TeamEvent.TeamInfo, "在线群信息");
                    });
                });
                MenuItem m4 = new MenuItem("群成员", (s, args) =>
                {
                    new TeamMembersForm(tid).Show();
                });

                MenuItem m5 = new MenuItem("聊天记录", (s, args) =>
                {
                    NIM.Messagelog.MessagelogAPI.QueryMsglogOnline(tid, NIM.Session.NIMSessionType.kNIMSessionTypeTeam, 10, 0, 0, 0, false, false,
                                                                   (ResponseCode code, string accountId, NIM.Session.NIMSessionType sType, MsglogQueryResult result) =>
                    {
                        DemoTrace.WriteLine(result.Dump());
                    });
                });

                MenuItem m6 = new MenuItem("获取禁言列表", (s, args) =>
                {
                    NIM.Team.TeamAPI.QueryMutedListOnlineAsync(tid, (res, count, id, members) =>
                    {
                        DemoTrace.WriteLine("禁言列表:", res, count, id, members.Dump());
                    });
                });
                contextMenu.MenuItems.AddRange(new MenuItem[] { m1, m3, m4, m5, m6 });
            }
            contextMenu.Show(_teamListView, e.Location);
        }
Esempio n. 5
0
        private void TreeView1_MouseUp(object sender, MouseEventArgs e)
        {
            if (treeView1.Nodes.Count == 0)
            {
                return;
            }
            var root = treeView1.Nodes[0];

            if (e.Button == MouseButtons.Left)
            {
                var node = treeView1.SelectedNode;
                if (node != null && node.Level > 0)
                {
                    NIM.Team.TeamAPI.QuerySingleMemberInfo(_teamId, node.Name, (info) =>
                    {
                        Action action = () =>
                        {
                            this.flowLayoutPanel1.Controls.Clear();
                            ObjectPropertyInfoForm.CreateFormContent(info, this.flowLayoutPanel1);
                        };
                        this.Invoke(action);
                    });
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                List <TreeNode> treeNodes = new List <TreeNode>();
                foreach (var n in root.Nodes)
                {
                    TreeNode nd = n as TreeNode;
                    if (nd.Checked)
                    {
                        treeNodes.Add(nd);
                    }
                }
                if (treeNodes.Count == 1)
                {
                    var      node = treeNodes[0];
                    MenuItem menu = new MenuItem("移出群", (s, args) =>
                    {
                        NIM.Team.TeamAPI.KickMemberOutFromTeam(_teamId, new string[] { node.Name }, (a) =>
                        {
                            if (a.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
                            {
                                foreach (var id in a.TeamEvent.IdCollection)
                                {
                                    _memberCollection.Remove(id);
                                    _teamMmebers.Remove(id);
                                }
                                UpdateTreeView();
                            }
                            else
                            {
                                MessageBox.Show("操作失败:" + a.TeamEvent.ResponseCode.ToString());
                            }
                        });
                    });
                    ContextMenu m   = new ContextMenu();
                    string      uid = node.Name;
                    if (_teamMmebers.ContainsKey(uid))
                    {
                        var      memInfo      = _teamMmebers[uid];
                        bool     normalMember = memInfo.Type == NIM.Team.NIMTeamUserType.kNIMTeamUserTypeNomal;
                        string   txt          = normalMember ? "设为管理员" : "取消管理员";
                        MenuItem item         = new MenuItem(txt, (s, args) =>
                        {
                            if (normalMember)
                            {
                                NIM.Team.TeamAPI.AddTeamManagers(_teamId, new string[] { uid }, (ret) =>
                                {
                                    DemoTrace.WriteLine(txt, ret.Dump());
                                });
                            }
                            else
                            {
                                NIM.Team.TeamAPI.RemoveTeamManagers(_teamId, new string[] { uid }, (ret) =>
                                {
                                    DemoTrace.WriteLine(txt, ret.Dump());
                                });
                            }
                        });
                        var      text1 = memInfo.IsMuted ? "取消禁言" : "禁言";
                        MenuItem item1 = new MenuItem(text1, (s, args) =>
                        {
                            if (memInfo.IsMuted)
                            {
                                NIM.Team.TeamAPI.SetMemberMuted(_teamId, uid, false, (ret) =>
                                {
                                    DemoTrace.WriteLine(text1, ret.Dump());
                                    if (ret.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
                                    {
                                        memInfo.SetMuted(false);
                                        _teamMmebers[uid] = memInfo;
                                    }
                                });
                            }
                            else
                            {
                                NIM.Team.TeamAPI.SetMemberMuted(_teamId, uid, true, (ret) =>
                                {
                                    DemoTrace.WriteLine(text1, ret.Dump());
                                    if (ret.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
                                    {
                                        memInfo.SetMuted(true);
                                        _teamMmebers[uid] = memInfo;
                                    }
                                });
                            }
                        });
                        MenuItem item2 = new MenuItem("修改群昵称", (s, args) =>
                        {
                            var member      = NIM.Team.TeamAPI.QuerySingleMemberInfo(_teamId, uid);
                            member.NickName = "nickname:" + new Random().Next();
                            NIM.Team.TeamAPI.UpdateMemberNickName(member, null);
                        });
                        m.MenuItems.Add(item);
                        var myInfo = _teamMmebers[MainForm.SelfId];
                        if (myInfo.Type == NIM.Team.NIMTeamUserType.kNIMTeamUserTypeCreator || myInfo.Type == NIM.Team.NIMTeamUserType.kNIMTeamUserTypeManager)
                        {
                            m.MenuItems.Add(item1);
                            m.MenuItems.Add(item2);
                        }
                    }
                    m.MenuItems.Add(menu);
                    m.Show(treeView1, e.Location);
                }
                else if (treeNodes.Count > 1)
                {
                    MenuItem menu = new MenuItem("群推送测试", (s, args) =>
                    {
                        NIM.TeamForecePushMessage forceMsg = new NIM.TeamForecePushMessage();
                        forceMsg.Content = string.Format("群推送测试:" + DateTime.Now.ToLongTimeString());
                        if (treeNodes.Count < root.Nodes.Count)
                        {
                            forceMsg.ReceiverList = new List <string>();
                            foreach (TreeNode t in treeNodes)
                            {
                                forceMsg.ReceiverList.Add(t.Text);
                            }
                        }
                        NIM.NIMTextMessage msg = new NIM.NIMTextMessage();
                        msg.ReceiverID         = root.Text;
                        msg.SessionType        = NIM.Session.NIMSessionType.kNIMSessionTypeTeam;
                        msg.TextContent        = "群推送消息..." + new Random().NextDouble().ToString();
                        NIM.TalkAPI.SendTeamFrocePushMessage(msg, forceMsg);
                    });
                    ContextMenu m = new ContextMenu();
                    m.MenuItems.Add(menu);
                    m.Show(treeView1, e.Location);
                }
                else
                {
                    MenuItem menu = new MenuItem("邀请入群", (s, args) =>
                    {
                        CreateTeamForm form    = new CreateTeamForm(FormType.InviteMemeber);
                        form.MembersIDSelected = (n, i) =>
                        {
                            NIM.Team.TeamAPI.Invite(_teamId, i, n, (r) =>
                            {
                                if (r.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResTeamInviteSuccess)
                                {
                                    MessageBox.Show("邀请成功,等待对方验证: " + r.TeamEvent.ResponseCode.ToString());
                                }
                                else if (r.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
                                {
                                    foreach (var id in r.TeamEvent.IdCollection)
                                    {
                                        NIM.Team.TeamAPI.QuerySingleMemberInfo(_teamId, id, (ret) =>
                                        {
                                            _teamMmebers[id] = ret;
                                        });
                                    }
                                    UpdateTreeView();
                                }
                                else
                                {
                                    MessageBox.Show("邀请失败:" + r.TeamEvent.ResponseCode.ToString());
                                }
                            });
                        };
                        form.Show();
                    });
                    ContextMenu m = new ContextMenu();

                    m.MenuItems.Add(menu);
                    m.Show(treeView1, e.Location);
                }
            }
        }