addToContacts method

Future<void> addToContacts(
  1. RxChat chat
)

Adds the User from this chat to the contacts list of the authenticated MyUser.

Only meaningful, if chat is dialog.

Implementation

Future<void> addToContacts(RxChat chat) async {
  if (inContacts(chat)) {
    return;
  }

  final User? user =
      chat.members.values
          .firstWhereOrNull((e) => e.user.id != me)
          ?.user
          .user
          .value;
  if (user == null) {
    return;
  }

  try {
    await _contactService.createChatContact(user);
  } catch (e) {
    MessagePopup.error(e);
    rethrow;
  }
}