editMessage method
Implementation
Future<void> editMessage(Message message, String content) async {
TextMessageBody msgBody = TextMessageBody(content: content);
try {
Message msg = await ChatUIKit.instance.modifyMessage(
messageId: message.msgId,
msgBody: msgBody,
);
msg.setHasTranslate(false);
String? url = ChatUIKitURLHelper().getUrlFromText(content);
ChatUIKitPreviewObj? obj = message.getPreview();
if (obj?.url != url) {
msg.removePreview();
}
ChatUIKit.instance.updateMessage(message: msg);
final index = msgModelList
.indexWhere((element) => msg.msgId == element.message.msgId);
if (index != -1) {
msgModelList[index] = msgModelList[index].copyWith(message: msg);
refresh();
}
if (url != null) {
try {
ChatUIKitPreviewObj? obj =
await ChatUIKitURLHelper().fetchPreview(url);
msg.addPreview(obj);
ChatUIKit.instance.updateMessage(message: msg);
final index = msgModelList
.indexWhere((element) => msg.msgId == element.message.msgId);
if (index != -1) {
msgModelList[index] = msgModelList[index].copyWith(message: msg);
refresh();
}
} catch (e) {
debugPrint('fetchPreview: $e');
}
}
// ignore: empty_catches
} catch (e) {}
}