Class MatrixHttpClient

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

public class MatrixHttpClient extends Object
  • Method Details

    • getAdminAccessToken

      public static 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 static 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 static String createRoom(String name, String description, String token) throws Exception
      Throws:
      Exception
    • sendHttpGetRequest

      protected static HttpResponse<String> sendHttpGetRequest(String url, String token) throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException
    • sendHttpPostRequest

      protected static HttpResponse<String> sendHttpPostRequest(String url, String token, String contentAsJson) throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException
    • sendHttpPostRequest

      protected static HttpResponse<String> sendHttpPostRequest(String url, String token, String mimeType, byte[] fileContent) throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException
    • sendHttpPutRequest

      protected static HttpResponse<String> sendHttpPutRequest(String url, String token, String contentAsJson) throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException
    • sendInvitationToMembers

      public static void sendInvitationToMembers(ArrayList<String> strings, String matrixRoomId)
    • createUserAccount

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

      public static String saveUserAccount(org.exoplatform.services.organization.User user, String matrixUserId, boolean isNew, String token, boolean isEnableUserOperation)
    • disableAccount

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

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

      public static 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 static 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 static 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 static 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 static MatrixRoomPermissions getRoomSettings(String matrixRoomId, String accessToken)
      Get permissions settings of a room
      Parameters:
      matrixRoomId -
      Returns:
      MatrixRoomPermissions object containing settings of the room
    • updateRoomSettings

      public static String updateRoomSettings(String matrixRoomId, MatrixRoomPermissions roomSettings, String accessToken)
      Updates the room settings
      Parameters:
      matrixRoomId - the Id of the room
      Returns:
      MatrixRoomPermissions updated room settings
    • uploadFile

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

      public static 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 static 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 static 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
    • cleanMatrixUsername

      public static String cleanMatrixUsername(String userName)