resolverV2TIMMessage static method
Implementation
static BaseMessage resolverV2TIMMessage(V2TimMessage message) {
ChatMessageBean chatMessageBean = ChatMessageBean();
V2TimMessage v2timMessage = message;
chatMessageBean.v2timMessage = message;
//过滤(消息被删除,没有元素)
if (v2timMessage.status == TIMConstants.V2TIM_MSG_STATUS_HAS_DELETED ||
v2timMessage.status == TIMConstants.V2TIM_ELEM_TYPE_NONE) {
switch (v2timMessage.elemType) {
case TIMConstants.V2TIM_ELEM_TYPE_CUSTOM:
String? result = message.customElem?.data;
if (result != null && result.isNotEmpty) {
Map parsedMap = json.decode(result);
chatMessageBean.tips = parsedMap["placeholder"];
}
//自定义消息
break;
case TIMConstants.V2TIM_ELEM_TYPE_TEXT:
chatMessageBean.tips = message.textElem?.text;
//文本消息
break;
case TIMConstants.V2TIM_ELEM_TYPE_SOUND:
chatMessageBean.tips = "[Voice]";
//音频消息
break;
case TIMConstants.V2TIM_ELEM_TYPE_IMAGE:
chatMessageBean.tips = "[Photo]";
//图片消息
break;
case TIMConstants.V2TIM_ELEM_TYPE_VIDEO:
chatMessageBean.tips = "[Voice]";
//视频消息
break;
default:
break;
}
}
//消息撤回
if (v2timMessage.status == TIMConstants.V2TIM_MSG_STATUS_LOCAL_REVOKED) {
if (v2timMessage.isSelf!) {
//判断是否是自己撤回消息
chatMessageBean.tips = "Release to end";
} else if (v2timMessage.groupID!.isNotEmpty) {
String name = "";
if (v2timMessage.nameCard!.isEmpty) {
name = covert2HTMLString(v2timMessage.nickName,
tips: "Recall a message.");
} else {
name = covert2HTMLString(v2timMessage.nameCard,
tips: "Recall a message.");
}
chatMessageBean.tips = name;
} else {
chatMessageBean.tips = "He/She recalled a message.";
}
}
return chatMessageBean;
}