Class MatrixHttpClient

java.lang.Object
io.meeds.chat.service.utils.MatrixHttpClient

@Component public class MatrixHttpClient extends Object
  • Constructor Details

    • MatrixHttpClient

      public MatrixHttpClient()
  • Method Details

    • getAdminAccessToken

      public String getAdminAccessToken(String userJWTToken) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException
      Get an authenticated access token for the administrative tasks
      Parameters:
      userJWTToken - JWT token used to authenticate the admin user
      Returns:
      String the access token for the authenticated user
      Throws:
      org.exoplatform.ws.frameworks.json.impl.JsonException
      IOException
      InterruptedException
    • authenticateUser

      public String authenticateUser(String userName, String password) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException
      Authenticates a user using his userName and password
      Parameters:
      userName - the username
      password - the user password
      Returns:
      String : access token for the authenticated user
      Throws:
      org.exoplatform.ws.frameworks.json.impl.JsonException
      IOException
      InterruptedException
    • createRoom

      public String createRoom(String name, String description, String token) throws Exception
      Throws:
      Exception
    • createUserAccount

      public String createUserAccount(org.exoplatform.services.organization.User user, String token)
    • updateUserDisplayName

      public void updateUserDisplayName(String userMatrixId, String displayName, String token) throws IOException, InterruptedException, org.exoplatform.ws.frameworks.json.impl.JsonException
      Sets a new display name for the user
      Parameters:
      userMatrixId - the ID of the user on Matrix
      displayName - the new display name
      token - the access token
      Throws:
      IOException
      InterruptedException
      org.exoplatform.ws.frameworks.json.impl.JsonException
    • saveUserAccount

      public String saveUserAccount(org.exoplatform.social.core.identity.model.Identity user, String matrixUserId, boolean isNew, String token)
      Saves the user account on Matrix
      Parameters:
      user - the user identity
      matrixUserId - the user Matrix ID to set
      isNew - if the user has been just created
      token - the authorization token
      Returns:
      the user Matrix ID
    • saveUserAccount

      public String saveUserAccount(org.exoplatform.social.core.identity.model.Identity user, String matrixUserId, boolean isNew, String token, boolean isEnableUserOperation, boolean isUserEnabled)
      Saves the user account
      Parameters:
      user - the User
      matrixUserId - the corresponding matrix ID
      isNew - if the user account is one
      token - the access token
      isEnableUserOperation - is this an operation to enable/disable the user on Matrix
      Returns:
      the user Matrix ID
    • disableAccount

      public String disableAccount(String userName, boolean eraseData, String token)
    • renameRoom

      public String renameRoom(String roomId, String newRoomName, String token)
    • inviteUserToRoom

      public boolean inviteUserToRoom(String roomId, String userMatrixId, String invitationMessage, String token)
      Invites a user to a specific room on Matrix
      Parameters:
      roomId - the Id of the room
      userMatrixId - the Matrix id of the user
      invitationMessage - a custom invitation message
      Returns:
    • kickUserFromRoom

      public void kickUserFromRoom(String roomId, String userMatrixId, String raisonMessage, String token)
      Kicks a user out of a specific room on Matrix
      Parameters:
      roomId - the Id of the room
      userMatrixId - the Matrix id of the user
      raisonMessage - the raison message
    • joinUserToRoom

      public boolean joinUserToRoom(String matrixRoomId, String matrixIdOfUser, String token)
      Adds directly a user to a room
      Parameters:
      matrixRoomId - the room ID
      matrixIdOfUser - the ID of the user of Matrix
      Returns:
      Boolean true if operation succeeded
    • makeUserAdminInRoom

      public boolean makeUserAdminInRoom(String matrixRoomId, String matrixIdOfUser, String token)
      Make user an admin of the room
      Parameters:
      matrixRoomId - the room ID
      matrixIdOfUser - the id of the user
      Returns:
      Boolean true if succeeded
    • getRoomSettings

      public MatrixRoomPermissions getRoomSettings(String matrixRoomId, String accessToken) throws IOException, InterruptedException, org.exoplatform.ws.frameworks.json.impl.JsonException
      Get permissions settings of a room
      Parameters:
      matrixRoomId -
      Returns:
      MatrixRoomPermissions object containing settings of the room
      Throws:
      IOException
      InterruptedException
      org.exoplatform.ws.frameworks.json.impl.JsonException
    • updateRoomSettings

      public String updateRoomSettings(String matrixRoomId, MatrixRoomPermissions roomSettings, String accessToken) throws IOException, InterruptedException, org.exoplatform.ws.frameworks.json.impl.JsonException
      Updates the room settings
      Parameters:
      matrixRoomId - the Id of the room
      Returns:
      MatrixRoomPermissions updated room settings
      Throws:
      IOException
      InterruptedException
      org.exoplatform.ws.frameworks.json.impl.JsonException
    • uploadFile

      public String uploadFile(String fileName, String mimeType, byte[] imageBytes, String accessToken)
    • updateRoomAvatar

      public boolean updateRoomAvatar(String matrixRoomId, String avatarURL, String accessToken)
      Update room avatar
      Parameters:
      matrixRoomId - the room ID
      avatarURL - the Avatar URL on
      Returns:
      true if succeeded otherwise false
    • updateUserAvatar

      public boolean updateUserAvatar(String userMatrixId, String avatarURL, String accessToken)
      Update the user avatar
      Parameters:
      userMatrixId - the Matrix room ID
      avatarURL - the avatar URL on Matrix
      Returns:
      true if updated, false otherwise
    • updateRoomDescription

      public boolean updateRoomDescription(String matrixRoomId, String description, String accessToken)
      Updates the room description
      Parameters:
      matrixRoomId - the ID of the room on Matrix
      description - the updated description
      Returns:
      true if the operation is successful, false otherwise
    • deleteRoom

      public boolean deleteRoom(String matrixRoomId, String accessToken)
      Deletes a Matrix room
      Parameters:
      matrixRoomId - the ID of the room
      accessToken - the access token
      Returns:
      boolean True if the deletion is successful otherwise False
    • cleanMatrixUsername

      public String cleanMatrixUsername(String userName)
      Cleans the username to be compatible with the usernames on Matrix server
      Parameters:
      userName - the user identifier
      Returns:
      String the cleaned username
    • getUserDisplayName

      public String getUserDisplayName(String userMatrixId, String matrixAccessToken) throws IOException, InterruptedException, org.exoplatform.ws.frameworks.json.impl.JsonException
      Throws:
      IOException
      InterruptedException
      org.exoplatform.ws.frameworks.json.impl.JsonException
    • getUserPresence

      public String getUserPresence(String matrixIdOfUser, String accessToken) throws IOException, InterruptedException, org.exoplatform.ws.frameworks.json.impl.JsonException
      Retrieve the user presence from Matrix server
      Parameters:
      matrixIdOfUser - the ID of the user on Matrix
      accessToken - the access token
      Returns:
      the value of the presence
      Throws:
      IOException
      InterruptedException
      org.exoplatform.ws.frameworks.json.impl.JsonException
    • setUserPresence

      public String setUserPresence(String matrixIdOfUser, String presence, String statusMessage, String accessToken) throws IOException, InterruptedException, org.exoplatform.ws.frameworks.json.impl.JsonException
      Set the user presence on Matrix server
      Parameters:
      matrixIdOfUser - the ID of the user n Matrix
      presence - the presence value : 'online, offline , unavailable"
      statusMessage - : the personalized status message
      accessToken - the access token
      Returns:
      Throws:
      IOException
      InterruptedException
      org.exoplatform.ws.frameworks.json.impl.JsonException
    • overrideRateLimitForUser

      public String overrideRateLimitForUser(String userIdOnMatrix, int messagesPerSecond, int burstCount, String accessToken) throws IOException, InterruptedException
      Overrides the rate limits for a given user
      Parameters:
      userIdOnMatrix - the user Id on Matrix
      messagesPerSecond - the allowed number of messages per second
      burstCount - how many actions that can be performed before being limited
      accessToken - the access token
      Returns:
      String the applied rate limits configuration
      Throws:
      IOException
      InterruptedException
    • getOverriddenRateLimitForUser

      public String getOverriddenRateLimitForUser(String userIdOnMatrix, String accessToken) throws IOException, InterruptedException
      Gets the overridden the rate limits for a given user
      Parameters:
      userIdOnMatrix - the user Id on Matrix
      accessToken - the access token
      Returns:
      String the applied rate limits configuration
      Throws:
      IOException
      InterruptedException
    • getEventById

      public MatrixMessage getEventById(String eventId, String roomId, String accessToken) throws IOException, InterruptedException, org.exoplatform.ws.frameworks.json.impl.JsonException
      Retrieves an event from Matrix by its Id
      Parameters:
      eventId - the event ID
      Returns:
      Map representing the message
      Throws:
      IOException
      InterruptedException
      org.exoplatform.ws.frameworks.json.impl.JsonException