toggleChatMute method

  1. @override
Future<void> toggleChatMute(
  1. ChatId id,
  2. MuteDuration? mute
)
override

Mutes or unmutes the specified Chat for the authenticated MyUser. Overrides an existing mute even if it's longer.

Implementation

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

  final RxChatImpl? chat = chats[id];
  final MuteDuration? muted = chat?.chat.value.muted;

  final Muting? muting =
      mute == null
          ? null
          : Muting(duration: mute.forever == true ? null : mute.until);

  chat?.chat.update((c) => c?.muted = muting?.toModel());

  try {
    await _graphQlProvider.toggleChatMute(id, muting);
  } catch (e) {
    chat?.chat.update((c) => c?.muted = muted);
    rethrow;
  }
}