deleteChatDirectLink method

  1. @override
Future<void> deleteChatDirectLink(
  1. ChatId groupId
)
override

Deletes the current ChatDirectLink of the given Chat-group.

Implementation

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

  final RxChatImpl? chat = chats[groupId];
  final ChatDirectLink? link = chat?.chat.value.directLink;

  chat?.chat.update((c) => c?.directLink = null);

  try {
    try {
      await _graphQlProvider.deleteChatDirectLink(groupId: groupId);
    } on DeleteChatDirectLinkException catch (e) {
      switch (e.code) {
        case DeleteChatDirectLinkErrorCode.artemisUnknown:
          rethrow;

        case DeleteChatDirectLinkErrorCode.notGroup:
          // No-op.
          break;

        case DeleteChatDirectLinkErrorCode.unknownChat:
          await remove(groupId);
          break;
      }
    }
  } catch (_) {
    chat?.chat.update((c) => c?.directLink = link);
    rethrow;
  }
}