示例#1
0
文件: DCUtilTool.cs 项目: wuearl/imPC
        /// <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);
        }
示例#2
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();
 }