onMessageRevoked method
Future<NIMResult<NIMMessage>>
onMessageRevoked(
- ChatMessage revokedMsg,
- String revokedMsgContent
)
Implementation
Future<NIMResult<NIMMessage>> onMessageRevoked(
ChatMessage revokedMsg, String revokedMsgContent) async {
//消息不准确,这种消息是离线时SDK返回的,但是iOS没有,所以统一不展示
if (revokedMsg.nimMessage.fromAccount != IMKitClient.account() &&
revokedMsg.nimMessage.messageDirection ==
NIMMessageDirection.outgoing) {
return NIMResult.failure(message: 'message error');
}
RevokedMessageInfo? revokedMessageInfo =
RevokedMessageInfo.getRevokedMessage(revokedMsg.nimMessage);
//创建一条特殊的占位消息
final msgResult = await MessageBuilder.createTextMessage(
sessionId: revokedMsg.nimMessage.sessionId!,
sessionType: revokedMsg.nimMessage.sessionType!,
text: revokedMsgContent);
if (msgResult.isSuccess && msgResult.data != null) {
//设置撤回标识
if (msgResult.data!.localExtension != null) {
msgResult.data!.localExtension![ChatMessage.keyRevokeMsg] = true;
msgResult.data!.localExtension![ChatMessage.keyRevokeMsgContent] =
revokedMessageInfo?.toMap();
} else {
msgResult.data!.localExtension = {
ChatMessage.keyRevokeMsg: true,
ChatMessage.keyRevokeMsgContent: revokedMessageInfo?.toMap()
};
}
msgResult.data!.config = NIMCustomMessageConfig(enableUnreadCount: false);
msgResult.data!.fromAccount = revokedMsg.nimMessage.fromAccount;
msgResult.data!.messageDirection =
revokedMsg.nimMessage.fromAccount == IMKitClient.account()
? NIMMessageDirection.outgoing
: NIMMessageDirection.received;
//将占位消息插入到本地
return NimCore.instance.messageService.saveMessageToLocalEx(
message: msgResult.data!, time: revokedMsg.nimMessage.timestamp);
}
return NIMResult.failure(message: 'build message error');
}