hideChat method

  1. @override
Future<void> hideChat(
  1. ChatId id
)
override

Marks the specified Chat as hidden for the authenticated MyUser.

Implementation

@override
Future<void> hideChat(ChatId id) async {
  Log.debug('hideChat($id)', '$runtimeType');

  RxChatImpl? chat = chats[id];
  ChatData? monologData;

  chat?.chat.update((c) => c?.isHidden = true);

  try {
    // If this [Chat] is local monolog, make it remote first.
    if (id.isLocalWith(me)) {
      monologData = _chat(
        await _graphQlProvider.createMonologChat(isHidden: true),
      );

      // Dispose and delete local monolog, since it's just been replaced with
      // a remote one.
      await remove(id);

      id = monologData.chat.value.id;
      await _monologLocal.upsert(me, monolog = id);
    }

    if (chat == null || chat.chat.value.favoritePosition != null) {
      await unfavoriteChat(id);
    }

    // [Chat.isHidden] will be changed by [RxChatImpl]'s own remote event
    // handler. Chat will be removed from [paginated] via [RxChatImpl].
    await _graphQlProvider.hideChat(id);
  } catch (_) {
    chat?.chat.update((c) => c?.isHidden = false);

    rethrow;
  }
}