Merge branch 'main' into 'feat/41-add-serverside-logout-command'

This commit is contained in:
Lars Simon Winzer
2026-04-07 13:36:07 +02:00
@@ -31,6 +31,66 @@ public class UserRegistry {
return Optional.of(user);
}
/**
* Removes a user from the registry by user ID.
*
* @param userId the ID of the user to remove
* @return true if a user was removed, false if no user with that ID exists
*/
public synchronized boolean removeByUserId(UserId userId) {
User user = byId.get(userId);
if (user == null) {
return false;
}
byName.remove(user.getName());
user.getSessionId().ifPresent(bySessionId::remove);
return true;
}
/**
* Removes a user from the registry by session ID.
*
* @param sessionId the session ID associated with the user to remove
* @return true if a user was removed, false if no user with that session exists
*/
public synchronized boolean removeBySessionId(SessionId sessionId) {
User user = bySessionId.get(sessionId);
if (user == null) {
return false;
}
remove(user);
return true;
}
/**
* Removes a user from the registry by username.
*
* @param username the username associated with the user to remove
* @return true if a user was removed, false if no user with that session exists
*/
public synchronized boolean removeByUsername(String username) {
User user = byName.get(username);
if (user == null) {
return false;
}
remove(user);
return true;
}
/**
* Removes a user from the internals of the registry.
*
* @param user the user to remove
*/
private synchronized void remove(User user) {
byId.remove(user.getId());
byName.remove(user.getName());
user.getSessionId().ifPresent(bySessionId::remove);
}
/**
* Removes the user with the given ID, but only if they are still disconnected. This prevents
* removing a user who has reconnected between the cleanup job's check and its removal call.
@@ -47,8 +107,7 @@ public class UserRegistry {
return false;
}
byId.remove(user.getId());
byName.remove(user.getName());
remove(user);
return true;
}