getDialogMessages method

Future<List<QBMessage?>> getDialogMessages(
  1. String dialogId, {
  2. QBSort? sort,
  3. QBFilter? filter,
  4. int limit = 100,
  5. int skip = 0,
  6. bool markAsRead = false,
})

Implementation

Future<List<QBMessage?>> getDialogMessages(String dialogId,
    {QBSort? sort, QBFilter? filter, int limit = 100, int skip = 0, bool markAsRead = false}) async {
  Map<String, Object> data = Map();

  data["dialogId"] = dialogId;
  data["limit"] = limit;
  data["skip"] = skip;
  data["markAsRead"] = markAsRead;

  if (sort != null) {
    data["sort"] = QBSortMapper.sortToMap(sort)!;
  }
  if (filter != null) {
    data["filter"] = QBFilterMapper.filterToMap(filter)!;
  }

  Map<Object?, Object?> map = await _chatModule.invokeMethod(GET_DIALOG_MESSAGES_METHOD, data);

  List<Object?> list = map["messages"] as List<Object?>;

  List<QBMessage?> messagesList = [];

  for (final messageMap in list) {
    QBMessage? qbMessage = QBMessageMapper.mapToQBMessage(messageMap as Map<Object?, Object?>);
    messagesList.add(qbMessage);
  }

  return messagesList;
}