updateArchiveRecentChat method

dynamic updateArchiveRecentChat(
  1. String jid
)

Implementation

updateArchiveRecentChat(String jid) {
  mirrorFlyLog("archived chat update", jid);
  getRecentChatOfJid(jid).then((recent) {
    final index = archivedChats.indexWhere((chat) => chat.jid == jid);
    if (recent != null) {
      //if(recent.isChatArchived.checkNull()) {
      if (index.isNegative) {
        archivedChats.insert(0, recent);
      } else {
        var lastPinnedChat =
            archivedChats.lastIndexWhere((element) => element.isChatPinned!);
        var nxtIndex = lastPinnedChat.isNegative ? 0 : (lastPinnedChat + 1);
        if (archivedChats[index].isChatPinned!) {
          archivedChats.removeAt(index);
          archivedChats.insert(index, recent);
        } else {
          archivedChats.removeAt(index);
          archivedChats.insert(nxtIndex, recent);
          archivedChats.refresh();
        }
      }
      /*}else{
        if (!index.isNegative) {
          archivedChats.removeAt(index);
        }
        checkArchiveList(recent);
      }*/
    } else {
      if (!index.isNegative) {
        archivedChats.removeAt(index);
      }
    }
    archivedChats.refresh();
  });
}