コード例 #1
0
        private void MyProfileBtn_Click(object sender, EventArgs e)
        {
            //GlobalAPI.GetCacheFileInfo("wangpengtest", CacheFileType.Image, 0, (info) =>
            //{

            //});
            ObjectPropertyInfoForm form = new ObjectPropertyInfoForm();

            form.Text               = "我的信息";
            form.TargetObject       = _selfNameCard;
            form.UpdateObjectAction = (o) =>
            {
                NIM.User.UserAPI.UpdateMyCard(o as UserNameCard, (a) =>
                {
                    if (a == ResponseCode.kNIMResSuccess)
                    {
                        UserAPI.GetUserNameCard(new List <string>()
                        {
                            SelfId
                        }, (ret) =>
                        {
                            if (ret.Any())
                            {
                                _selfNameCard = ret[0];
                                DisplayMyProfile(_selfNameCard);
                            }
                        });
                    }
                });
            };
            form.Show();
        }
コード例 #2
0
        private void TreeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Button != MouseButtons.Right || string.IsNullOrEmpty(e.Node.Name))
            {
                return;
            }
            var         roomId = long.Parse(e.Node.Name);
            ContextMenu menu   = new ContextMenu();
            MenuItem    item1  = null;

            if (!_joinedRoomIdSet.Contains(roomId))
            {
                item1 = new MenuItem("进入聊天室", (s, arg) =>
                {
                    NIM.Plugin.ChatRoom.RequestLoginInfo(roomId, (response, authResult) =>
                    {
                        if (response == NIM.ResponseCode.kNIMResSuccess)
                        {
                            NIMChatRoom.LoginData data = new NIMChatRoom.LoginData();
                            data.Icon = "http://image.baidu.com/search/detail?ct=503316480&z=&tn=baiduimagedetail&ipn=d&word=%E5%AE%A0%E7%89%A9&step_word=&ie=utf-8&in=&cl=2&lm=-1&st=-1&cs=69099631,2544305882&os=4219122898,2688632801&simid=&pn=0&rn=1&di=0&ln=1000&fr=&fmq=1461830763275_R_D&fm=&ic=0&s=undefined&se=&sme=&tab=0&width=&height=&face=undefined&is=&istype=2&ist=&jit=&bdtype=-1&gsm=0&objurl=http%3A%2F%2Fimg.taopic.com%2Fuploads%2Fallimg%2F110906%2F1382-110Z611025585.jpg&rpstart=0&rpnum=0";
                            data.Nick = "【C# Client】";
                            NIMChatRoom.ChatRoomApi.Login(roomId, authResult, data);
                        }
                    });
                });
            }
            else
            {
                item1 = new MenuItem("离开聊天室", (s, arg) =>
                {
                    NIMChatRoom.ChatRoomApi.Exit(roomId);
                });

                MenuItem item2 = new MenuItem("聊天室信息", (s, arg) =>
                {
                    NIMChatRoom.ChatRoomApi.GetRoomInfo(roomId, (a, b, c) =>
                    {
                        Action action = () =>
                        {
                            ObjectPropertyInfoForm form = new ObjectPropertyInfoForm();
                            form.TargetObject           = c;
                            form.Show();
                        };
                        this.Invoke(action);
                    });
                });

                MenuItem item3 = new MenuItem("聊天室成员", (s, arg) =>
                {
                    QueryMembers(roomId);
                });

                MenuItem item4 = new MenuItem("消息历史", (s, arg) =>
                {
                    NIMChatRoom.ChatRoomApi.QueryMessageHistoryOnline(roomId, 0, 50, (a, b, c) =>
                    {
                        if (b == NIM.ResponseCode.kNIMResSuccess)
                        {
                            OutputForm.SetText(c.Dump());
                        }
                    });
                });

                MenuItem item5 = new MenuItem("发送测试消息", (s, arg) =>
                {
                    NIMChatRoom.Message msg = new NIMChatRoom.Message();
                    msg.MessageType         = NIMChatRoom.NIMChatRoomMsgType.kNIMChatRoomMsgTypeText;
                    msg.MessageAttachment   = "这是一条测试消息 " + DateTime.Now.ToString() + " " + new Random().NextDouble().ToString();
                    NIMChatRoom.ChatRoomApi.SendMessage(roomId, msg);
                });

                menu.MenuItems.Add(item2);
                menu.MenuItems.Add(item3);
                menu.MenuItems.Add(item4);
                menu.MenuItems.Add(item5);

                menu.MenuItems.Add("发送文件", (s, arg) =>
                {
                    var files = System.IO.Directory.GetFiles(".");
                    if (files != null && files.Any())
                    {
                        NIM.Nos.NosAPI.Upload(files[0], (ret, url) =>
                        {
                            if (ret == 200)
                            {
                                NIM.NIMMessageAttachment attach = new NIM.NIMMessageAttachment();
                                attach.RemoteUrl        = url;
                                attach.DisplayName      = System.IO.Path.GetFileName(files[0]);
                                attach.FileExtension    = System.IO.Path.GetExtension(files[0]);
                                NIMChatRoom.Message msg = new NIMChatRoom.Message();
                                msg.MessageType         = NIMChatRoomMsgType.kNIMChatRoomMsgTypeFile;
                                msg.RoomId            = roomId;
                                msg.MessageAttachment = attach.Serialize();
                                NIMChatRoom.ChatRoomApi.SendMessage(roomId, msg);
                            }
                        }, null);
                    }
                });
            }

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