Class SessionRegistryService

java.lang.Object
com.arms.api.wiki.service.SessionRegistryService

@Service public class SessionRegistryService extends Object
  • Constructor Details

    • SessionRegistryService

      @Autowired public SessionRegistryService(org.springframework.data.redis.core.RedisTemplate<String,Object> redisTemplate)
  • Method Details

    • userJoined

      public void userJoined(String sessionId, String documentId, UserInfoDTO userInfo)
      Adds or updates a user's information for a specific document within a specific session in Redis. Also resets the TTL for the session/document key.
      Parameters:
      sessionId - The ID of the session the user joined.
      documentId - The ID of the document the user joined.
      userInfo - The user's information.
    • userLeftDocument

      public boolean userLeftDocument(String sessionId, String documentId, String userId)
      Removes a user from a specific document session they were in. This version requires sessionId and documentId, unlike the previous version. The disconnect event handler should ideally provide this context. If not possible, the `userLeft(String userId)` method needs a different approach (scanning keys).
      Parameters:
      sessionId - The ID of the session the user left.
      documentId - The ID of the document the user left.
      userId - The ID of the user who disconnected.
      Returns:
      true if the user was found and removed, false otherwise.
    • updateUserState

      public void updateUserState(String sessionId, String documentId, String userId, Map<String,Integer> cursorPosition, SelectionInfo selection)
      Updates the cursor/selection state for an active user in Redis. Fetches the user, updates the DTO, and puts it back. Also resets the TTL for the session/document key.
      Parameters:
      sessionId - The session ID.
      documentId - The document ID.
      userId - The user ID.
      cursorPosition - The new cursor position (can be null).
      selection - The new selection (can be null).
    • getActiveParticipantsForDocument

      public List<UserInfoDTO> getActiveParticipantsForDocument(String sessionId, String documentId, String requestingUserId)
      Gets the list of active participants (UserInfoDTO) from Redis for a specific document/session, excluding the user making the request.
      Parameters:
      sessionId - The ID of the session.
      documentId - The ID of the document.
      requestingUserId - The ID of the user requesting the list (to exclude them). Can be null.
      Returns:
      A List of UserInfoDTO for other active participants, or an empty list.
    • userLeftAllSessions

      public List<Map.Entry<String,String>> userLeftAllSessions(String userId)
      Removes a user from ALL sessions/documents they might be in. WARNING: This requires scanning keys and can be inefficient on large Redis instances. Prefer `userLeftDocument` if possible.
      Parameters:
      userId - The ID of the user who disconnected.
      Returns:
      A list of Map.Entry where key is sessionId and value is documentId that the user left.