Example #1
0
        /// <summary>
        /// 加入群组
        /// </summary>
        /// <param name="group"></param>
        /// <param name="inviter"></param>
        /// <param name="inviteMessage"></param>
        private void onAutoAcceptInvitationFromGroup(EMGroup group, string inviter, string inviteMessage)
        {
            EMConversation    conversation = EaseHelper.shard.client.getChatManager().conversationWithType(group.groupId(), EMConversationType.GROUPCHAT, true);
            EMTextMessageBody body         = new EMTextMessageBody("你加入了群聊");
            EMMessage         message      = EMMessage.createSendMessage(SettingMenager.shard.userID, group.groupId(), body, EMChatType.GROUP);

            conversation.insertMessage(message);
            MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];

            if (main == null)
            {
                return;
            }
            main.refreshGroupInfo(group.groupId());
        }
Example #2
0
        /// <summary>
        /// 好友添加成功
        /// </summary>
        /// <param name="user"></param>
        private void onContactAdded(string user)
        {
            AudioPlayer.shard.playTips();
            EMConversation    conversation = EaseHelper.shard.client.getChatManager().conversationWithType(user, EMConversationType.CHAT, true);
            EMTextMessageBody body         = new EMTextMessageBody("我们成为了好友");
            EMMessage         message      = EMMessage.createSendMessage(SettingMenager.shard.userID, user, body, EMChatType.GROUP);

            conversation.insertMessage(message);
            MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];

            if (main == null)
            {
                return;
            }
            main.refreshFriendFromServer();
        }
Example #3
0
        private void Form_oked(string obj)
        {
            int type = 0;

            if (dSkinRadioButton1.Checked)
            {
                type = 2;
            }
            else if (dSkinRadioButton2.Checked)
            {
                type = 1;
            }
            CreateGroupSendModel model = new CreateGroupSendModel();

            model.group_name     = dSkinTextBox1.Text;
            model.group_portrait = "pc_defalt_group_photo.jpg";
            model.group_type     = type;
            HttpUitls.Instance.get <CreateGroupReciveModel>("group/create", model, (json) =>
            {
                if (json.code == 200)
                {
                    EaseHelper.shard.createdGroupId = json.data;
                    AddGroupUserSendModel addGroup  = new AddGroupUserSendModel();
                    addGroup.group_id       = json.data;
                    addGroup.group_user_ids = obj;
                    HttpUitls.Instance.get <BaseReciveModel>("groupUser/addBatch", addGroup, (js) =>
                    {
                        if (js.code == 200)
                        {
                            GroupInfoSendModel m = new GroupInfoSendModel();
                            m.group_id           = json.data;
                            HttpUitls.Instance.get <GroupInfoReciveModel>("group/detail", m, (jso) =>
                            {
                                if (js.code == 200)
                                {
                                    EMConversation conversation = EaseHelper.shard.client.getChatManager().conversationWithType(json.data, EMConversationType.GROUPCHAT, true);
                                    EMTextMessageBody body      = new EMTextMessageBody("你创建了群聊");
                                    EMMessage message           = EMMessage.createSendMessage(SettingMenager.shard.userID, json.data, body, EMChatType.GROUP);
                                    conversation.insertMessage(message);
                                    DBHelper.Instance.addGroupAndFocus(jso.data);
                                    ThreadPool.QueueUserWorkItem(getGroupMembers, json.data);
                                    MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                                    if (main != null)
                                    {
                                        main.refreshConversationList();
                                    }
                                    this.BeginInvoke(new EventHandler((s, e) =>
                                    {
                                        this.Close();
                                    }));
                                }
                                else
                                {
                                    if (js.message.Contains("重新登录"))
                                    {
                                        MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                                        if (main != null)
                                        {
                                            main.gotoLogin();
                                        }
                                    }
                                }
                            }, (s) =>
                            {
                                if (s < 503 && s > 500)
                                {
                                    MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                                    if (main != null)
                                    {
                                        main.gotoLogin();
                                    }
                                }
                            });
                        }
                        else
                        {
                            if (js.message.Contains("重新登录"))
                            {
                                MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                                if (main != null)
                                {
                                    main.gotoLogin();
                                }
                            }
                        }
                    }, (code) =>
                    {
                        if (code < 503 && code > 500)
                        {
                            MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                            if (main != null)
                            {
                                main.gotoLogin();
                            }
                        }
                    });
                }
                else
                {
                    if (json.message.Contains("重新登录"))
                    {
                        MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                        if (main != null)
                        {
                            main.gotoLogin();
                        }
                    }
                }
            }, (code) =>
            {
                if (code < 503 && code > 500)
                {
                    MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                    if (main != null)
                    {
                        main.gotoLogin();
                    }
                }
            });
        }
Example #4
0
 /// <summary>
 /// EMConversationType转EMChatType
 /// </summary>
 /// <param name="conversation"></param>
 /// <returns></returns>
 public static EMChatType GetChatType(EMConversation conversation)
 {
     return(conversation.conversationType() == EMConversationType.GROUPCHAT ? EMChatType.GROUP : EMChatType.SINGLE);
 }
Example #5
0
 /// <summary>
 /// 接收Cmd消息
 /// </summary>
 /// <param name="messages"></param>
 private void onReciveCmdMessage(EMMessage[] messages)
 {
     foreach (EMMessage message in messages)
     {
         string own = "";
         if (message.getAttribute("own", out own))
         {
             var data = JsonConvert.DeserializeObject <List <DeleteMessageDataModel> >(own);
             foreach (var item in data)
             {
                 EMConversation conversation = client.getChatManager().conversationWithType(item.userid, EMConversationType.CHAT, false);
                 if (conversation != null)
                 {
                     conversation.removeMessage(item.messageId);
                 }
                 MainFrm m = (MainFrm)Application.OpenForms["MainFrm"];
                 if (m == null)
                 {
                     continue;
                 }
                 m.deleteMesssage(item.userid, item.messageId);
             }
             MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
             if (main == null)
             {
                 return;
             }
             main.refreshConversationList();
         }
         string type;
         if (message.getAttribute("type", out type))
         {
             if (type == "personMSG")
             {
                 string userid = "";
                 string nsid   = "";
                 message.getAttribute("userid", out userid);
                 message.getAttribute("msgid", out nsid);
                 EMConversation conversation = client.getChatManager().conversationWithType(message.conversationId(), EMConversationType.CHAT, false);
                 if (conversation != null)
                 {
                     EMMessage mMessage = conversation.loadMessage(nsid);
                     if (mMessage != null)
                     {
                         conversation.removeMessage(mMessage);
                     }
                 }
                 MainFrm m = (MainFrm)Application.OpenForms["MainFrm"];
                 if (m == null)
                 {
                     continue;
                 }
                 m.deleteMesssage(userid, nsid);
                 m.refreshConversationList();
             }
             if (type == "deleteMSG")
             {
                 string userid = "";
                 string nsid   = "";
                 message.getAttribute("userid", out userid);
                 message.getAttribute("msgid", out nsid);
                 EMConversation conversation = client.getChatManager().conversationWithType(message.conversationId(), EMConversationType.GROUPCHAT, false);
                 if (conversation != null)
                 {
                     EMMessage mMessage = conversation.loadMessage(nsid);
                     if (mMessage != null)
                     {
                         conversation.removeMessage(mMessage);
                     }
                 }
                 MainFrm m = (MainFrm)Application.OpenForms["MainFrm"];
                 if (m == null)
                 {
                     continue;
                 }
                 m.deleteMesssage(userid, nsid);
                 m.refreshConversationList();
             }
             if (type == "qunAdmin" || type == "qun" || type == "qun_shield")
             {
                 MainFrm m = (MainFrm)Application.OpenForms["MainFrm"];
                 if (m == null)
                 {
                     continue;
                 }
                 string id = "";
                 message.getAttribute("id", out id);
                 m.refreshGroupInfo(id);
             }
         }
     }
 }
Example #6
0
 public ConversationModel(EMConversation mConversation)
 {
     conversation = mConversation;
     if (conversation == null)
     {
         throw new AggregateException("The conversation not be null");
     }
     conversationType = conversation.conversationType();
     if (conversation.conversationType() == EMConversationType.CHAT)
     {
         var friend = DBHelper.Instance.getFriend(conversation.conversationId());
         if (friend != null)
         {
             name      = string.IsNullOrEmpty(friend.target_user_nickname) ? friend.friend_self_name : friend.target_user_nickname;
             avatarURL = friend.portrait;
             DCWebImageMaanager.shard.downloadImageAsync(avatarURL, (image, b) =>
             {
                 avatarImage = image;
             });
             isWorkGroup = false;
             if (friend.is_shield == 1)
             {
                 isSheild = true;
             }
             else
             {
                 isSheild = false;
             }
         }
         else
         {
             var stonger = DBHelper.Instance.GetStronger(conversation.conversationId());
             if (stonger != null)
             {
                 name      = stonger.nickName;
                 avatarURL = stonger.avatar;
                 DCWebImageMaanager.shard.downloadImageAsync(avatarURL, (image, b) =>
                 {
                     avatarImage = image;
                 });
                 isWorkGroup = false;
                 isSheild    = false;
             }
             else
             {
                 avatarImage = Properties.Resources.moren;
             }
         }
     }
     else
     {
         var group = DBHelper.Instance.GetGroup(conversation.conversationId());
         if (group != null)
         {
             name      = group.groupName;
             avatarURL = group.avatar;
             DCWebImageMaanager.shard.downloadImageAsync(avatarURL, (image, b) =>
             {
                 avatarImage = image;
             });
             if (group.is_pingbi == 1)
             {
                 isSheild = true;
             }
             else
             {
                 isSheild = false;
             }
             if (group.group_type == 1)
             {
                 isWorkGroup = true;
             }
             else
             {
                 isWorkGroup = false;
             }
         }
         else
         {
             var gt = DBHelper.Instance.GetGroupCache(conversation.conversationId());
             if (gt != null)
             {
                 name      = gt.groupName;
                 avatarURL = gt.avatar;
                 DCWebImageMaanager.shard.downloadImageAsync(avatarURL, (image, b) =>
                 {
                     avatarImage = image;
                 });
                 isSheild    = false;
                 isWorkGroup = false;
             }
             else
             {
                 avatarImage = Properties.Resources.moren;
             }
         }
     }
     if (avatarImage == null)
     {
         avatarImage = Properties.Resources.moren;
     }
     time            = DCUtilTool.GetMessageTime(conversation.latestMessage());
     lastMessageText = DCUtilTool.getMessageShowTest(conversation.latestMessage());
 }
Example #7
0
 public void Dispose()
 {
     conversation = null;
 }
Example #8
0
 public UnreadTipsItem(EMConversation conversation)
 {
     InitializeComponent();
     if (conversation.conversationType() == EMConversationType.GROUPCHAT)
     {
         var group = DBHelper.Instance.GetGroup(conversation.conversationId());
         if (group != null)
         {
             DCWebImageMaanager.shard.downloadImageAsync(group.avatar, (image, b) =>
             {
                 if (image != null)
                 {
                     this.BeginInvoke(() =>
                     {
                         duiPictureBox1.Image = image;
                     });
                 }
             });
             this.BeginInvoke(() =>
             {
                 duiLabel1.Text = group.groupName;
                 duiLabel2.Text = DCUtilTool.getMessageShowTest(conversation.latestMessage());
             });
         }
         else
         {
             var g = DBHelper.Instance.GetGroupCache(conversation.conversationId());
             if (g != null)
             {
                 DCWebImageMaanager.shard.downloadImageAsync(g.avatar, (image, b) =>
                 {
                     if (image != null)
                     {
                         this.BeginInvoke(() =>
                         {
                             duiPictureBox1.Image = image;
                         });
                     }
                 });
                 this.BeginInvoke(() =>
                 {
                     duiLabel1.Text = g.groupName;
                     duiLabel2.Text = DCUtilTool.getMessageShowTest(conversation.latestMessage());
                 });
             }
         }
     }
     else
     {
         var friend = DBHelper.Instance.getFriend(conversation.conversationId());
         if (friend != null)
         {
             DCWebImageMaanager.shard.downloadImageAsync(friend.portrait, (image, b) =>
             {
                 if (image != null)
                 {
                     this.BeginInvoke(() =>
                     {
                         duiPictureBox1.Image = image;
                     });
                 }
             });
             this.BeginInvoke(() =>
             {
                 duiLabel1.Text = string.IsNullOrEmpty(friend.target_user_nickname) ? friend.friend_self_name : friend.target_user_nickname;
                 duiLabel2.Text = DCUtilTool.getMessageShowTest(conversation.latestMessage());
             });
         }
         else
         {
             var user = DBHelper.Instance.GetStronger(conversation.conversationId());
             if (user != null)
             {
                 DCWebImageMaanager.shard.downloadImageAsync(user.avatar, (image, b) =>
                 {
                     if (image != null)
                     {
                         this.BeginInvoke(() =>
                         {
                             duiPictureBox1.Image = image;
                         });
                     }
                 });
                 this.BeginInvoke(() =>
                 {
                     duiLabel1.Text = user.nickName;
                     duiLabel2.Text = DCUtilTool.getMessageShowTest(conversation.latestMessage());
                 });
             }
         }
     }
 }