sendMessage method
Implementation
Future<void> sendMessage(Message message) async {
Message? willSendMsg = message;
if (willSendHandler != null) {
willSendMsg = await willSendHandler!(willSendMsg);
if (willSendMsg == null) {
return Future(() => null);
}
}
willSendMsg.addProfile();
if (ChatUIKitProvider.instance.currentUserProfile != null) {
userMap[ChatUIKit.instance.currentUserId!] =
ChatUIKitProvider.instance.currentUserProfile!;
}
// 插入缓存中的消息
addAllCacheToList();
String? url;
if (willSendMsg.bodyType == MessageType.TXT) {
url = ChatUIKitURLHelper().getUrlFromText(willSendMsg.textContent);
if (url?.isNotEmpty == true) {
willSendMsg.status = MessageStatus.FAIL;
await ChatUIKit.instance.insertMessage(message: willSendMsg);
willSendMsg.status = MessageStatus.PROGRESS;
msgModelList.insert(0, MessageModel(message: willSendMsg));
hasNew = true;
lastActionType = MessageLastActionType.bottomPosition;
refresh();
ChatUIKitPreviewObj? obj = await ChatUIKitURLHelper()
.fetchPreview(url!, messageId: willSendMsg.msgId);
willSendMsg.addPreview(obj);
ChatUIKit.instance.sendMessage(message: willSendMsg);
}
}
if (url == null) {
final msg = await ChatUIKit.instance.sendMessage(message: willSendMsg);
msgModelList.insert(0, MessageModel(message: msg));
hasNew = true;
lastActionType = MessageLastActionType.bottomPosition;
refresh();
}
debugPrint(willSendMsg.toString());
}