get method

  1. @override
FutureOr<RxChatContact?> get(
  1. ChatContactId id
)
override

Returns a ChatContact by the provided id.

Implementation

@override
FutureOr<RxChatContact?> get(ChatContactId id) async {
  Log.debug('get($id)', '$runtimeType');

  RxChatContactImpl? contact = contacts[id];
  if (contact != null) {
    return contact;
  }

  // If [contact] doesn't exists, we should lock the [mutex] to avoid remote
  // double invoking.
  Mutex? mutex = _getGuards[id];
  if (mutex == null) {
    mutex = Mutex();
    _getGuards[id] = mutex;
  }

  return mutex.protect(() async {
    contact = contacts[id];
    if (contact == null) {
      // TODO: Fetch from local storage, if any.
      // final DtoChatContact? dto = await _contactLocal.get(id);
      // if (dto != null) {
      //   contact = RxChatContactImpl(_userRepo, dto);
      //   contact!.init();
      // }

      if (contact == null) {
        // final query = (await _graphQlProvider.chatContact(id)).chatContact;
        // if (query != null) {
        //   contact = await _putChatContact(query.toDto());
        // }
      }

      if (contact != null) {
        contacts[id] = contact!;
      }
    }

    return contact;
  });
}