saveToLocalAndUpdate static method

Future<void> saveToLocalAndUpdate(
  1. V2TimMessage message,
  2. LocalCustomDataModel previewItem,
  3. ValueChanged<V2TimMessage> onUpdateMessage
)

save the link info to local and call updating the message on UI, only works with onUpdateMessage

Implementation

static Future<void> saveToLocalAndUpdate(V2TimMessage message,
    LocalCustomDataModel previewItem, ValueChanged<V2TimMessage> onUpdateMessage) async {
  if (message.msgID != null) {
    String saveInfo = LinkPreviewEntry.linkInfoToString(previewItem);
    final currentInfo = message.localCustomData;
    if (currentInfo != null && currentInfo.isNotEmpty) {
      final Map<String, dynamic> data = json.decode(currentInfo);
      data['url'] = previewItem.url;
      data['image'] = previewItem.image;
      data['title'] = previewItem.title;
      data['description'] = previewItem.description;
      saveInfo = json.encode(data);
    }
    message.localCustomData = saveInfo;
    if(saveInfo != currentInfo){
      final result = await TencentImSDKPlugin.v2TIMManager.v2TIMMessageManager
          .setLocalCustomData(msgID: message.msgID!, localCustomData: saveInfo);
      if (result.code == 0) {
        onUpdateMessage(message);
      }
    }
  }
}