checkCleanOldMessagesFromServer method

void checkCleanOldMessagesFromServer({
  1. int removeCount = 10,
})

Implementation

void checkCleanOldMessagesFromServer({int removeCount = 10}) {
  if(lastMessagesFromServer.length > startCheckingLastMessagesFromServerAfterSize){
    logger("Start of removing old messages received from server... (total: ${lastMessagesFromServer.length})");
    final List<LastServerMessage> remove = [];
    for(int i=lastMessagesFromServer.length-1; i >= 0 && remove.length < removeCount; i--){
      final messageReceivedFromServer = lastMessagesFromServer[i];
      if(messageReceivedFromServer.shouldBeRemoved) {
        remove.add(messageReceivedFromServer);
      }
    }
    for (final LastServerMessage element in remove) {
      lastMessagesFromServer.remove(element);
    }
    logger("...end of removing old messages received from server (removed: ${remove.length})");
  }
}