private void downloadVideoThumbnailFileAttchment(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") + ".jpg"; HttpUitls.Instance.DownloadFile(body.thumbnailRemotePath(), path, (p) => { if (progress != null) { progress(p); } }, (b) => { if (b) { body.setThumbnailLocalPath(path); body.setThumbnailDownloadStatus(EMDownloadStatus.SUCCESSED); conversation.updateMessage(mMessage); complite(mMessage); } else { body.setThumbnailDownloadStatus(EMDownloadStatus.FAILED); conversation.updateMessage(mMessage); complite(mMessage); } }); }
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(); }