update method

  1. @override
Future<ChatResult<ChatUser>> update(
  1. String userId, {
  2. String? displayName,
  3. String? avatarUrl,
  4. bool clearAvatar = false,
  5. String? bio,
  6. String? email,
  7. Map<String, dynamic>? custom,
  8. bool? active,
})
override

Updates profile fields for an existing user.

Call this from the profile editor when the user saves their changes. The backend emits a user_updated WS event so the authenticated principal's other devices (and rooms that render their avatar/name) see the change in real time.

Pass clearAvatar: true to explicitly remove the current avatar (sends an explicit JSON null so the backend wipes the field). Passing avatarUrl: null without the flag is a no-op — the field is omitted from the payload entirely.

Implementation

@override
Future<ChatResult<ChatUser>> update(
  String userId, {
  String? displayName,
  String? avatarUrl,
  bool clearAvatar = false,
  String? bio,
  String? email,
  Map<String, dynamic>? custom,
  bool? active,
}) async {
  final existing = _client._users[userId];
  if (existing == null) return const ChatFailureResult(NotFoundFailure());
  final updated = ChatUser(
    id: userId,
    displayName: displayName ?? existing.displayName,
    avatarUrl: clearAvatar ? null : (avatarUrl ?? existing.avatarUrl),
    bio: bio ?? existing.bio,
    email: email ?? existing.email,
    custom: custom ?? existing.custom,
    active: active ?? existing.active,
    role: existing.role,
    configuration: existing.configuration,
  );
  _client._users[userId] = updated;
  return ChatSuccess(updated);
}