removeContact method
- ChatContactId contactId,
- UserId userId
Removes the provided ChatContactId from the User.contacts with the specified UserId.
Intended to be invoked from ContactRepository, as RxUser has no events of its User.contacts list changes.
Implementation
Future<void> removeContact(ChatContactId contactId, UserId userId) async {
Log.debug('removeContact($contactId, $userId)', '$runtimeType');
final DtoUser? dto = await _userLocal.read(userId);
if (dto != null) {
final NestedChatContact? existing = dto.value.contacts.firstWhereOrNull(
(e) => e.id == contactId,
);
if (existing != null) {
dto.value.contacts.remove(existing);
await _userLocal.upsert(dto);
}
}
}