delete method
Deletes a user permanently by id.
The userId MUST be the caller's own id. The backend tightened
DELETE /users/{userId} to own-account-only: passing any other id
returns a 403 that surfaces as a ForbiddenFailure carrying the
ChatErrorTokens.cannotDeleteOtherUser token. For self-service
account deletion prefer deleteCurrentUser, which targets
DELETE /users/me and so can never hit the wrong account.
Use for hard account deletion flows (GDPR right-to-erasure or admin tools that genuinely operate on their own principal). Irreversible — the backend tombstones messages but removes the profile record; managed users belonging to the deleted parent are cascaded out too.
Implementation
@override
Future<ChatResult<void>> delete(String userId) async {
// Mirror the backend's own-account-only rule: deleting another user's
// id is forbidden with the cannot_delete_other_user token.
if (userId != _client.currentUserId) {
return const ChatFailureResult(
ForbiddenFailure(
message: 'Cannot delete another user',
errorToken: ChatErrorTokens.cannotDeleteOtherUser,
),
);
}
if (!_client._users.containsKey(userId)) {
return const ChatFailureResult(NotFoundFailure());
}
_client._users.remove(userId);
return const ChatSuccess(null);
}