Пример #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());
        }
Пример #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();
        }
Пример #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();
                    }
                }
            });
        }
Пример #4
0
        /// <summary>
        /// 显示消息预览文字
        /// </summary>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static string getMessageShowTest(EMMessage message)
        {
            if (message == null)
            {
                return(string.Empty);
            }
            var bodys = message.bodies();

            if (bodys.Length < 1)
            {
                return("");
            }
            EMMessageBody body = bodys[0];
            string        text = "";

            if (body.type == EMMessageBodyType.TEXT)
            {
                EMTextMessageBody textMessageBody = (EMTextMessageBody)body;
                if (textMessageBody.text().EndsWith("_encode"))
                {
                    var arr = textMessageBody.text().Split('_');
                    text += DCEncrypt.Decrypt(arr[0], DCEncrypt.key);
                }
                else
                {
                    text += textMessageBody.text();
                }
            }
            if (body.type == EMMessageBodyType.VOICE)
            {
                text += "[语音]";
            }
            if (body.type == EMMessageBodyType.VIDEO)
            {
                text += "[视频]";
            }
            if (body.type == EMMessageBodyType.IMAGE)
            {
                text += "[图片]";
            }
            if (body.type == EMMessageBodyType.LOCATION)
            {
                text += "[位置]";
            }
            if (body.type == EMMessageBodyType.FILE)
            {
                text += "[文件]";
            }
            if (message.from() == SettingMenager.shard.userID)
            {
                return(text);
            }
            if (message.chatType() == EMChatType.SINGLE)
            {
                var friend = DBHelper.Instance.getFriend(message.from());
                if (friend == null)
                {
                    var stronger = DBHelper.Instance.GetStronger(message.from());
                    if (stronger != null)
                    {
                        text = stronger.nickName + ":" + text;
                    }
                }
                else
                {
                    text = string.IsNullOrEmpty(friend.target_user_nickname) ? friend.friend_self_name : friend.target_user_nickname + ":" + text;
                }
            }
            else
            {
                var groupUser = DBHelper.Instance.GetGroupUser(message.from(), message.conversationId());
                if (groupUser == null)
                {
                    if (DBHelper.Instance.checkFriend(message.from()))
                    {
                        var friend = DBHelper.Instance.getFriend(message.from());
                        if (!string.IsNullOrEmpty(friend.target_user_nickname))
                        {
                            text = friend.target_user_nickname + ":" + text;
                        }
                        else
                        {
                            text = friend.friend_self_name + ":" + text;
                        }
                    }
                    else
                    {
                        var stronger = DBHelper.Instance.GetStronger(message.from());
                        if (stronger != null)
                        {
                            text = stronger.nickName + ":" + text;
                        }
                    }
                }
                else
                {
                    if (DBHelper.Instance.checkFriend(message.from()))
                    {
                        text = groupUser.friend_name + ":" + text;
                    }
                    else if (!string.IsNullOrEmpty(groupUser.group_user_nickname))
                    {
                        text = groupUser.group_user_nickname + ":" + text;
                    }
                    else
                    {
                        text = groupUser.user_name + ":" + text;
                    }
                }
            }
            return(text);
        }
Пример #5
0
 public MessageModel(EMMessage mMessage)
 {
     this.message = mMessage;
     if (message.bodies().Length < 1)
     {
         return;
     }
     bodyType  = message.bodies()[0].type;
     chatType  = message.chatType();
     messageId = message.msgId();
     firstbody = message.bodies()[0];
     isRead    = message.isRead();
     if (message.msgDirection() == EMMessageDirection.SEND)
     {
         isSender = true;
     }
     else
     {
         isSender = false;
     }
     nickName = message.from();
     if (bodyType == EMMessageBodyType.TEXT)
     {
         if (message.getAttribute("jpzim_is_big_expression", out isGifFace))
         {
             if (isGifFace)
             {
                 message.getAttribute("jpzim_big_expression_path", out gitFaceURL);
                 message.getAttribute("faceH", out faceH);
                 message.getAttribute("faceW", out faceW);
                 if (!string.IsNullOrEmpty(gitFaceURL))
                 {
                     DCWebImageMaanager.shard.downloadImageAsync(gitFaceURL, (image, b) =>
                     {
                         this.image = image;
                         if (faceH < 1 || faceW < 1)
                         {
                             faceW = image.Width;
                             faceH = image.Height;
                         }
                     });
                 }
                 text   = "[动画表情]";
                 isRead = message.isRead();
                 setupUserInfo();
                 return;
             }
         }
         string typ;
         if (message.getAttribute("type", out typ))
         {
             if (typ.Equals("person"))
             {
                 isIDCard = true;
                 isRead   = message.isRead();
                 message.getAttribute("id", out IDCardID);
                 return;
             }
         }
         EMTextMessageBody body = (EMTextMessageBody)message.bodies()[0];
         text   = body.text();
         isRead = message.isRead();
         if (text.EndsWith("_encode"))
         {
             var arr = text.Split('_');
             text = DCEncrypt.Decrypt(arr[0], DCEncrypt.key);
             if (string.IsNullOrEmpty(text))
             {
                 text = body.text();
             }
         }
     }
     else if (bodyType == EMMessageBodyType.IMAGE)
     {
         EMImageMessageBody body = (EMImageMessageBody)message.bodies()[0];
         var file = body.localPath();
         if (!string.IsNullOrEmpty(body.localPath()) && File.Exists(body.localPath()))
         {
             image = new Bitmap(body.localPath());
         }
         fileLocalPath          = body.localPath();
         thumbnailFileLocalPath = body.thumbnailLocalPath();
         fileURLPath            = body.remotePath();
         thumbnailFileURLPath   = body.thumbnailRemotePath();
         fileSize           = body.fileLength();
         imageSize          = new Size(Convert.ToInt32(body.size().mWidth), Convert.ToInt32(body.size().mHeight));
         thumbnailImageSize = new Size(Convert.ToInt32(body.thumbnailSize().mWidth), Convert.ToInt32(body.thumbnailSize().mWidth));
     }
     else if (bodyType == EMMessageBodyType.VOICE)
     {
         EMVoiceMessageBody body = (EMVoiceMessageBody)message.bodies()[0];
         fileLocalPath = body.localPath();
         fileURLPath   = body.remotePath();
         fileSize      = body.fileLength();
         mediaDuration = body.duration();
     }
     else if (bodyType == EMMessageBodyType.VIDEO)
     {
         EMVideoMessageBody body = (EMVideoMessageBody)message.bodies()[0];
         fileLocalPath          = body.localPath();
         thumbnailFileLocalPath = body.thumbnailLocalPath();
         fileURLPath            = body.remotePath();
         thumbnailFileURLPath   = body.thumbnailRemotePath();
         fileSize = body.fileLength();
         if (string.IsNullOrEmpty(thumbnailFileLocalPath) && File.Exists(body.thumbnailLocalPath()))
         {
             thumbnailImage = Image.FromFile(thumbnailFileLocalPath);
         }
         thumbnailImageSize = new Size(Convert.ToInt32(body.size().mWidth), Convert.ToInt32(body.size().mHeight));
     }
     else
     {
         if (bodyType == EMMessageBodyType.COMMAND)
         {
             return;
         }
         if (bodyType == EMMessageBodyType.LOCATION)
         {
             EMLocationMessageBody body1 = firstbody as EMLocationMessageBody;
             latitude  = body1.latitude();
             longitude = body1.longitude();
             address   = body1.address();
             return;
         }
         EMFileMessageBody body = (EMFileMessageBody)message.bodies()[0];
         fileLocalPath = body.localPath();
         fileURLPath   = body.remotePath();
         fileSize      = body.fileLength();
         displayName   = body.displayName();
         fileSizeDes   = getFileSize();
     }
     isRead = message.isRead();
     setupUserInfo();
 }