getMessages method

  1. @override
List<RuutMessage> getMessages()
override

Implementation

@override
List<RuutMessage> getMessages() {
  final messageClientInstancekey = _clientInstanceKey;

  //filter current client instance message ids
  Set<int> clientMessageIds = _messageIdToClientInstanceKeyBox.keys
      .map((e) => e as int)
      .where((key) =>
          _messageIdToClientInstanceKeyBox.get(key) ==
          messageClientInstancekey)
      .toSet();

  //retrieve messages with ids
  List<RuutMessage> sortedMessages = _box.values
      .where((message) => clientMessageIds.contains(message.id))
      .toList(growable: false);

  //sort message using creation dates
  sortedMessages.sort((a, b) {
    return b.createdAt.compareTo(a.createdAt);
  });

  return sortedMessages;
}