updateMessageLocalUrlInMemory static method

void updateMessageLocalUrlInMemory(
  1. V2TimMessageDownloadProgress progress
)

Implementation

static void updateMessageLocalUrlInMemory(V2TimMessageDownloadProgress progress) {
  String messageIdentfif = "${progress.msgID}_${progress.type}_${progress.isSnapshot}";

  int idx = currentDownloadingList.indexWhere((ele) => ele.getUniqueueKey() == messageIdentfif);

  String msgID = progress.msgID;
  if (idx > -1) {
    DownloadMessageQueueData currentProgressData = currentDownloadingList[idx];
    String currentDownloadMsgID = currentProgressData.msgID;
    if (currentDownloadMsgID == msgID) {
      var msgList = TencentCloudChat.instance.dataInstance.messageData.getMessageList(key: currentProgressData.key);
      var idx = msgList.indexWhere((element) => element.msgID == msgID);
      if (idx > -1) {
        var msg = msgList[idx];
        // add local url
        if (msg.elemType == MessageElemType.V2TIM_ELEM_TYPE_FILE) {
          if (msg.fileElem != null) {
            msg.fileElem!.localUrl = progress.path;
            console("update memery file message local snanp path $msgID");
          }
        } else if (msg.elemType == MessageElemType.V2TIM_ELEM_TYPE_IMAGE) {
          if (msg.imageElem != null) {
            List<V2TimImage?> images = msg.imageElem!.imageList ?? [];
            for (var i = 0; i < images.length; i++) {
              V2TimImage? image = images[i];
              if (image != null) {
                if (image.type == currentProgressData.imageType) {
                  image.localUrl = progress.path;
                  console("update memery image message local path $msgID");
                }
              }
            }
          }
        } else if (msg.elemType == MessageElemType.V2TIM_ELEM_TYPE_SOUND) {
          if (msg.soundElem != null) {
            msg.soundElem!.localUrl = progress.path;
            console("update memery sound message local snanp path $msgID");
          }
        } else if (msg.elemType == MessageElemType.V2TIM_ELEM_TYPE_VIDEO) {
          if (msg.videoElem != null) {
            if (currentProgressData.isSnapshot == true) {
              msg.videoElem!.localSnapshotUrl = progress.path;
              console("update memery video message local snanp path $msgID");
            } else {
              msg.videoElem!.localVideoUrl = progress.path;
              console("update memery video message local path $msgID");
            }
          }
        }
        var replacements = [msg];
        msgList.replaceRange(idx, (idx + 1), replacements);
        TencentCloudChat.instance.dataInstance.messageData.updateMessageList(
          messageList: msgList,
          userID: currentProgressData.conversationType == ConversationType.V2TIM_C2C ? currentProgressData.key : null,
          groupID: currentProgressData.conversationType == ConversationType.V2TIM_GROUP ? currentProgressData.key : null,
          disableNotify: true, // disable this time notify. use widget state .
        );
      }
    }
  } else {
    console("updateMessageLocalUrlInMemory failed. no downloading message");
  }
}