getMessageBody static method
Implementation
static MessageBody? getMessageBody(V2TimMessage imMessage) {
if (imMessage.status == sdk_status.MessageStatus.V2TIM_MSG_STATUS_LOCAL_REVOKED) {
MessageBody messageBody = MessageBody();
messageBody.systemMessage = [ChatUtil.convertToSystemInfoFromRecall(imMessage, null, null)];
return messageBody;
}
switch (imMessage.elemType) {
case MessageElemType.V2TIM_ELEM_TYPE_TEXT:
MessageBody messageBody = MessageBody();
messageBody.text = imMessage.textElem?.text;
return messageBody;
case MessageElemType.V2TIM_ELEM_TYPE_IMAGE:
if (imMessage.imageElem != null) {
MessageBody messageBody = MessageBody();
if (imMessage.imageElem?.imageList != null) {
for (var image in imMessage.imageElem!.imageList!) {
if (image?.type == V2TIM_IMAGE_TYPE.V2TIM_IMAGE_TYPE_ORIGIN) {
messageBody.originalImageSize = image?.size ?? 0;
messageBody.originalImageWidth = image?.width ?? 0;
messageBody.originalImageHeight = image?.height ?? 0;
final originalImageResult =
getActualMediaPath(MessageType.image, imMessage.imageElem!.path, image?.uuid ?? "", "origin_");
final originalImagePath = originalImageResult[filePathKey];
bool isLocalExist = originalImageResult[localExistKey];
if (isLocalExist) {
messageBody.originalImagePath = originalImagePath;
}
} else if (image?.type == V2TIM_IMAGE_TYPE.V2TIM_IMAGE_TYPE_THUMB) {
final thumbImageResult =
getActualMediaPath(MessageType.image, image?.localUrl ?? "", image?.uuid ?? "", "thumb_");
final thumbImagePath = thumbImageResult[filePathKey];
bool isLocalExist = thumbImageResult[localExistKey];
if (isLocalExist) {
messageBody.thumbImagePath = thumbImagePath;
}
} else if (image?.type == V2TIM_IMAGE_TYPE.V2TIM_IMAGE_TYPE_LARGE) {
final largeImageResult =
getActualMediaPath(MessageType.image, image?.localUrl ?? "", image?.uuid ?? '', "large_");
final largeImagePath = largeImageResult[filePathKey];
bool isLocalExist = largeImageResult[localExistKey];
if (isLocalExist) {
messageBody.largeImagePath = largeImagePath;
}
}
}
}
return messageBody;
}
break;
case MessageElemType.V2TIM_ELEM_TYPE_SOUND:
if (imMessage.soundElem != null) {
MessageBody messageBody = MessageBody();
messageBody.soundSize = imMessage.soundElem?.dataSize ?? 0;
messageBody.soundDuration = imMessage.soundElem?.duration ?? 0;
final soundPathResult = getActualMediaPath(
MessageType.sound,
imMessage.soundElem!.path,
imMessage.soundElem!.UUID ?? '',
null,
);
final soundPath = soundPathResult[filePathKey];
bool isLocalExist = soundPathResult[localExistKey];
if (isLocalExist) {
messageBody.soundPath = soundPath;
}
return messageBody;
}
break;
case MessageElemType.V2TIM_ELEM_TYPE_FILE:
if (imMessage.fileElem != null) {
MessageBody messageBody = MessageBody();
messageBody.fileName = imMessage.fileElem?.fileName;
messageBody.fileSize = imMessage.fileElem?.fileSize ?? 0;
final filePathResult = getActualMediaPath(
MessageType.file,
imMessage.fileElem!.path,
imMessage.fileElem!.UUID ?? '',
null,
);
final filePath = filePathResult[filePathKey];
bool isLocalExist = filePathResult[localExistKey];
if (isLocalExist) {
messageBody.filePath = filePath;
}
return messageBody;
}
break;
case MessageElemType.V2TIM_ELEM_TYPE_VIDEO:
if (imMessage.videoElem != null) {
MessageBody messageBody = MessageBody();
messageBody.videoSnapshotSize = imMessage.videoElem?.snapshotSize ?? 0;
messageBody.videoSnapshotWidth = imMessage.videoElem?.snapshotWidth ?? 0;
messageBody.videoSnapshotHeight = imMessage.videoElem?.snapshotHeight ?? 0;
final snapshotPathResult = getActualMediaPath(
MessageType.video,
imMessage.videoElem!.snapshotPath,
imMessage.videoElem!.snapshotUUID ?? '',
null,
);
final snapshotPath = snapshotPathResult[filePathKey];
bool isSnapshotLocalExist = snapshotPathResult[localExistKey];
if (isSnapshotLocalExist) {
messageBody.videoSnapshotPath = snapshotPath;
}
messageBody.videoSize = imMessage.videoElem?.videoSize ?? 0;
messageBody.videoDuration = imMessage.videoElem?.duration ?? 0;
final videoPathResult = getActualMediaPath(
MessageType.video,
imMessage.videoElem!.videoPath,
imMessage.videoElem!.UUID ?? '',
null,
);
final videoPath = videoPathResult[filePathKey];
bool isVideoLocalExist = videoPathResult[localExistKey];
if (isVideoLocalExist) {
messageBody.videoPath = videoPath;
}
return messageBody;
}
break;
case MessageElemType.V2TIM_ELEM_TYPE_FACE:
if (imMessage.faceElem != null) {
MessageBody messageBody = MessageBody();
messageBody.faceIndex = imMessage.faceElem?.index ?? 0;
messageBody.faceName = imMessage.faceElem?.data;
return messageBody;
}
break;
case MessageElemType.V2TIM_ELEM_TYPE_CUSTOM:
if (imMessage.customElem != null) {
MessageBody messageBody = MessageBody();
messageBody.customMessage = CustomMessageInfo(
data: imMessage.customElem!.data ?? '',
description: imMessage.customElem!.desc ?? '',
extensionInfo: imMessage.customElem!.extension ?? '');
return messageBody;
}
break;
case MessageElemType.V2TIM_ELEM_TYPE_GROUP_TIPS:
if (imMessage.groupTipsElem != null) {
final tipsElem = imMessage.groupTipsElem!;
if (tipsElem.type == GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_JOIN ||
tipsElem.type == GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_INVITE ||
tipsElem.type == GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_KICKED ||
tipsElem.type == GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_QUIT ||
tipsElem.type == GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_GROUP_INFO_CHANGE ||
tipsElem.type == GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_SET_ADMIN ||
tipsElem.type == GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_CANCEL_ADMIN ||
tipsElem.type == GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_MEMBER_INFO_CHANGE ||
tipsElem.type == GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_PINNED_MESSAGE_ADDED ||
tipsElem.type == GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_PINNED_MESSAGE_DELETED) {
MessageBody messageBody = MessageBody();
messageBody.systemMessage = ChatUtil.convertToSystemInfoFromGroupTips(tipsElem);
return messageBody;
}
}
break;
default:
return null;
}
return null;
}