Esempio n. 1
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);
        }
Esempio n. 2
0
 private void setupUserInfo()
 {
     if (isSender)
     {
         avatarURL = SettingMenager.shard.avatar;
         DCWebImageMaanager.shard.downloadImageAsync(avatarURL, (image, b) =>
         {
             avatarImage = image;
             if (avatarImage == null)
             {
                 avatarImage = Properties.Resources.moren;
             }
         });
         return;
     }
     if (message.chatType() == EMChatType.SINGLE)
     {
         using (var friend = DBHelper.Instance.getFriend(message.conversationId()))
         {
             if (friend != null)
             {
                 nickName  = 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;
                 });
             }
             else
             {
                 using (var stonger = DBHelper.Instance.GetStronger(message.conversationId()))
                 {
                     if (stonger != null)
                     {
                         nickName  = stonger.nickName;
                         avatarURL = stonger.avatar;
                         DCWebImageMaanager.shard.downloadImageAsync(stonger.avatar, (image, b) =>
                         {
                             avatarImage = image;
                         });
                     }
                     else
                     {
                         isNotLoadData = true;
                         avatarImage   = Properties.Resources.moren;
                         UserInfoMenager.shard.GetUser(message.from(), (data) =>
                         {
                             avatarURL = data.portrait;
                             DCWebImageMaanager.shard.downloadImageAsync(avatarURL, (image, b) =>
                             {
                                 avatarImage = image;
                             });
                         });
                     }
                 }
             }
         }
     }
     else
     {
         using (var group = DBHelper.Instance.GetGroupUser(message.from(), message.conversationId()))
         {
             if (group != null)
             {
                 if (DBHelper.Instance.checkFriend(message.from()))
                 {
                     nickName = string.IsNullOrEmpty(group.friend_name) ? (string.IsNullOrEmpty(group.group_user_nickname) ? group.user_name : group.group_user_nickname) : group.friend_name;
                 }
                 else
                 {
                     nickName = string.IsNullOrEmpty(group.group_user_nickname) ? group.user_name : group.group_user_nickname;
                 }
                 avatarURL = group.avatar;
                 DCWebImageMaanager.shard.downloadImageAsync(avatarURL, (image, b) =>
                 {
                     avatarImage = image;
                     if (avatarImage == null)
                     {
                         avatarImage = Properties.Resources.moren;
                     }
                 });
             }
             else
             {
                 using (var gt = DBHelper.Instance.GetStronger(message.from(), message.conversationId()))
                 {
                     if (gt != null)
                     {
                         nickName  = gt.nickName;
                         avatarURL = gt.avatar;
                         DCWebImageMaanager.shard.downloadImageAsync(avatarURL, (image, b) =>
                         {
                             avatarImage = image;
                             if (avatarImage == null)
                             {
                                 avatarImage = Properties.Resources.moren;
                             }
                         });
                     }
                     else
                     {
                         isNotLoadData = true;
                         avatarImage   = Properties.Resources.moren;
                         UserInfoMenager.shard.getGroupUser(message.conversationId(), message.from(), (data) =>
                         {
                             nickName  = string.IsNullOrEmpty(data.group_user_nickname) ? data.user_name : data.group_user_nickname;
                             avatarURL = data.portrait;
                             DCWebImageMaanager.shard.downloadImageAsync(avatarURL, (image, b) =>
                             {
                                 avatarImage = image;
                                 if (avatarImage == null)
                                 {
                                     avatarImage = Properties.Resources.moren;
                                 }
                             });
                         });
                     }
                 }
             }
         }
     }
 }
Esempio n. 3
0
        private void downloadVideoMainAttchment(EMMessage mMessage, DownloadMessageAttchmentProgress progress, DownloadMessageAttchmentComplite complite)
        {
            EMVideoMessageBody body = mMessage.bodies()[0] as EMVideoMessageBody;

            body.setDownloadStatus(EMDownloadStatus.DOWNLOADING);
            mMessage.clearBodies();
            mMessage.addBody(body);
            var conversation = EaseHelper.shard.client.getChatManager().conversationWithType(mMessage.conversationId(), DCUtilTool.GetMConversationType(mMessage.chatType()), true);

            conversation.updateMessage(mMessage);
            string dir = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\Changliao" + "\\ChangLiao\\" + SettingMenager.shard.idCard;

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string path = dir + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".mp4";

            HttpUitls.Instance.DownloadFile(body.remotePath(), path, (p) =>
            {
                Console.WriteLine(p);
                if (progress != null)
                {
                    progress(p);
                }
            }, (b) =>
            {
                if (b)
                {
                    var fi = new FileInfo(path);
                    body.setFileLength(fi.Length);
                    body.setLocalPath(path);
                    body.setDownloadStatus(EMDownloadStatus.SUCCESSED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
                else
                {
                    body.setDownloadStatus(EMDownloadStatus.FAILED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
            });
        }
Esempio n. 4
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();
 }
Esempio n. 5
0
        private void downloadFileMainAttchment(EMMessage mMessage, DownloadMessageAttchmentProgress progress, DownloadMessageAttchmentComplite complite)
        {
            EMFileMessageBody body = mMessage.bodies()[0] as EMFileMessageBody;

            body.setDownloadStatus(EMDownloadStatus.DOWNLOADING);
            mMessage.clearBodies();
            mMessage.addBody(body);
            var conversation = EaseHelper.shard.client.getChatManager().conversationWithType(mMessage.conversationId(), DCUtilTool.GetMConversationType(mMessage.chatType()), true);

            conversation.updateMessage(mMessage);
            string dir = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\Changliao" + "\\ChangLiao\\" + SettingMenager.shard.idCard;

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string path = dir + "\\" + body.displayName();
            var    p    = path;
            int    i    = 0;

            while (File.Exists(p))
            {
                i += 1;
                var arr = path.Split('.');
                if (arr.Length > 2)
                {
                    p = "";
                    for (int j = 0; j < arr.Length - 1; j++)
                    {
                        p += arr[j];
                    }
                    p = p + "(" + i + ")." + arr[arr.Length - 1];
                }
                else if (arr.Length == 2)
                {
                    p = arr[0] + "(" + i + ")." + arr[1];
                }
                else
                {
                    p = path + "(" + i + ")";
                }
            }
            HttpUitls.Instance.DownloadFile(body.remotePath(), p, (p1) =>
            {
                if (progress != null)
                {
                    progress(p1);
                }
            }, (b) =>
            {
                if (b)
                {
                    var fi = new FileInfo(path);
                    body.setFileLength(fi.Length);
                    body.setLocalPath(path);
                    body.setDownloadStatus(EMDownloadStatus.SUCCESSED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
                else
                {
                    body.setDownloadStatus(EMDownloadStatus.FAILED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
            });
        }