startDownload static method

dynamic startDownload(
  1. Timer timer
)

Implementation

static startDownload(Timer timer) {
  List<String> convIDs = downloadQueue.keys.toList();
  if (convIDs.isEmpty) {
    return;
  }
  for (var i = 0; i < convIDs.length; i++) {
    String convID = convIDs[i];
    if (downloadQueue.containsKey(convID)) {
      List<DownloadMessageQueueData> convDownloadList = downloadQueue[convID] ?? [];
      if (convDownloadList.isEmpty) {
        continue;
      }
      console("current download queue convIDs is ${json.encode(convIDs)}");
      int indexForConvID = currentDownloadingList.indexWhere((ele) => ele.convID == convID);
      if (indexForConvID > -1) {
        console("$convID has downloading message. break. the message is ${currentDownloadingList[indexForConvID].path}");
        continue;
      }
      if (convDownloadList.isNotEmpty) {
        DownloadMessageQueueData downloaddata = convDownloadList.removeAt(0);
        downloadQueue[convID] = convDownloadList;
        currentDownloadingList.add(downloaddata);
        downloadMessage(
          msgID: downloaddata.msgID,
          messageType: downloaddata.messageType,
          imageType: downloaddata.imageType,
          isSnapshot: downloaddata.isSnapshot,
        );
      } else {
        console("$convID has no message waiting for download");
      }
    }
  }
}