Package io.meeds.chat.service.utils
Class MatrixHttpClient
java.lang.Object
io.meeds.chat.service.utils.MatrixHttpClient
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringauthenticateUser(String userName, String password) Authenticates a user using his userName and passwordstatic StringcleanMatrixUsername(String userName) Cleans the username to be compatible with the usernames on Matrix serverstatic StringcreateRoom(String name, String description, String token) static StringcreateUserAccount(org.exoplatform.services.organization.User user, String token) static booleandeleteRoom(String matrixRoomId, String accessToken) Deletes a Matrix roomstatic StringdisableAccount(String userName, boolean eraseData, String token) static StringgetAdminAccessToken(String userJWTToken) Get an authenticated access token for the administrative tasksstatic MatrixRoomPermissionsgetRoomSettings(String matrixRoomId, String accessToken) Get permissions settings of a roomstatic booleaninviteUserToRoom(String roomId, String userMatrixId, String invitationMessage, String token) Invites a user to a specific room on Matrixstatic booleanjoinUserToRoom(String matrixRoomId, String matrixIdOfUser, String token) Adds directly a user to a roomstatic voidkickUserFromRoom(String roomId, String userMatrixId, String raisonMessage, String token) Kicks a user out of a specific room on Matrixstatic booleanmakeUserAdminInRoom(String matrixRoomId, String matrixIdOfUser, String token) Make user an admin of the roomstatic StringrenameRoom(String roomId, String newRoomName, String token) static StringsaveUserAccount(org.exoplatform.services.organization.User user, String matrixUserId, boolean isNew, String token, boolean isEnableUserOperation) protected static HttpResponse<String> sendHttpDeleteRequest(String url, String token, String contentAsJson) protected static HttpResponse<String> sendHttpGetRequest(String url, String token) protected static HttpResponse<String> sendHttpPostRequest(String url, String token, String contentAsJson) protected static HttpResponse<String> sendHttpPostRequest(String url, String token, String mimeType, byte[] fileContent) protected static HttpResponse<String> sendHttpPutRequest(String url, String token, String contentAsJson) static voidsendInvitationToMembers(ArrayList<String> strings, String matrixRoomId) static booleanupdateRoomAvatar(String matrixRoomId, String avatarURL, String accessToken) Update room avatarstatic booleanupdateRoomDescription(String matrixRoomId, String description, String accessToken) Updates the room descriptionstatic StringupdateRoomSettings(String matrixRoomId, MatrixRoomPermissions roomSettings, String accessToken) Updates the room settingsstatic booleanupdateUserAvatar(String userMatrixId, String avatarURL, String accessToken) Update the user avatarstatic StringuploadFile(String fileName, String mimeType, byte[] imageBytes, String accessToken)
-
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.JsonExceptionIOExceptionInterruptedException
-
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 usernamepassword- the user password- Returns:
- String : access token for the authenticated user
- Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
createRoom
- Throws:
Exception
-
sendHttpGetRequest
protected static HttpResponse<String> sendHttpGetRequest(String url, String token) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
sendHttpPostRequest
protected static HttpResponse<String> sendHttpPostRequest(String url, String token, String contentAsJson) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
sendHttpPostRequest
protected static HttpResponse<String> sendHttpPostRequest(String url, String token, String mimeType, byte[] fileContent) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
sendHttpPutRequest
protected static HttpResponse<String> sendHttpPutRequest(String url, String token, String contentAsJson) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
sendHttpDeleteRequest
protected static HttpResponse<String> sendHttpDeleteRequest(String url, String token, String contentAsJson) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
sendInvitationToMembers
-
createUserAccount
-
saveUserAccount
-
disableAccount
-
renameRoom
-
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 roomuserMatrixId- the Matrix id of the userinvitationMessage- 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 roomuserMatrixId- the Matrix id of the userraisonMessage- the raison message
-
joinUserToRoom
Adds directly a user to a room- Parameters:
matrixRoomId- the room IDmatrixIdOfUser- the ID of the user of Matrix- Returns:
- Boolean true if operation succeeded
-
makeUserAdminInRoom
Make user an admin of the room- Parameters:
matrixRoomId- the room IDmatrixIdOfUser- the id of the user- Returns:
- Boolean true if succeeded
-
getRoomSettings
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
-
updateRoomAvatar
Update room avatar- Parameters:
matrixRoomId- the room IDavatarURL- the Avatar URL on- Returns:
- true if succeeded otherwise false
-
updateUserAvatar
Update the user avatar- Parameters:
userMatrixId- the Matrix room IDavatarURL- 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 Matrixdescription- the updated description- Returns:
- true if the operation is successful, false otherwise
-
deleteRoom
Deletes a Matrix room- Parameters:
matrixRoomId- the ID of the roomaccessToken- the access token- Returns:
- boolean True if the deletion is successful otherwise False
-
cleanMatrixUsername
Cleans the username to be compatible with the usernames on Matrix server- Parameters:
userName- the user identifier- Returns:
- String the cleaned username
-