getItem method

FutureOr<Rx<ChatItem>?> getItem(
  1. ChatItemId id
)

Returns a reactive ChatItem by the provided id.

Implementation

FutureOr<Rx<ChatItem>?> getItem(ChatItemId id) {
  Rx<ChatItem>? item;

  item = chat?.messages.firstWhereOrNull((e) => e.value.id == id);
  item ??=
      _fragments
          .firstWhereOrNull((e) => e.items.keys.contains(id))
          ?.items[id];

  if (item == null) {
    final Future<Rx<ChatItem>?>? future = chat?.single(id).then((
      fragment,
    ) async {
      if (fragment != null) {
        await fragment.around();
        _fragments.add(fragment);
        return fragment.items.values.firstOrNull;
      }

      return null;
    });

    return future;
  }

  return item;
}