unfavoriteChat method

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

Removes the specified Chat from the favorites list of the authenticated MyUser.

Implementation

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

  if (id.isLocal) {
    return;
  }

  final RxChatImpl? chat = chats[id];
  final ChatFavoritePosition? oldPosition = chat?.chat.value.favoritePosition;

  chat?.chat.update((c) => c?.favoritePosition = null);
  paginated.emit(MapChangeNotification.updated(chat?.id, chat?.id, chat));

  try {
    try {
      await _graphQlProvider.unfavoriteChat(id);
    } on UnfavoriteChatException catch (e) {
      switch (e.code) {
        case UnfavoriteChatErrorCode.unknownChat:
          await remove(id);
          break;

        case UnfavoriteChatErrorCode.artemisUnknown:
          rethrow;
      }
    }
  } catch (e) {
    chat?.chat.update((c) => c?.favoritePosition = oldPosition);
    paginated.emit(MapChangeNotification.updated(chat?.id, chat?.id, chat));
    rethrow;
  }
}