renameChat method

  1. @override
Future<void> renameChat(
  1. ChatId id,
  2. ChatName? name
)
override

Renames the specified Chat by the authority of authenticated MyUser.

Removes the Chat.name of the Chat if the provided name is null.

Only Chat-groups can be named or renamed.

Implementation

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

  if (id.isLocalWith(me)) {
    await ensureRemoteMonolog(name: name);
    return;
  }

  final RxChatImpl? chat = chats[id];
  final ChatName? previous = chat?.chat.value.name;

  chat?.chat.update((c) => c?.name = name);

  try {
    await _graphQlProvider.renameChat(id, name);
  } catch (_) {
    chat?.chat.update((c) => c?.name = previous);
    rethrow;
  }
}