Package io.meeds.chat.service.utils
Class MatrixHttpClient
java.lang.Object
io.meeds.chat.service.utils.MatrixHttpClient
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionauthenticateUser(String userName, String password) Authenticates a user using his userName and passwordcreateRoom(String name, String description, String token) createUserAccount(org.exoplatform.services.organization.User user, String token) deleteMedia(String mediaId, String accessToken) booleandeleteRoom(String matrixRoomId, String accessToken) Deletes a Matrix roomdisableAccount(String userName, boolean eraseData, String token) getAccessToken(String userJWTToken) Get an authenticated access token for the administrative tasksgetEventById(String eventId, String roomId, String accessToken) Retrieves an event from Matrix by its IdgetMediaInfo(String mediaId, String accessToken) getOverriddenRateLimitForUser(String userIdOnMatrix, String accessToken) Gets the overridden the rate limits for a given usergetRoomSettings(String matrixRoomId, String accessToken) Get permissions settings of a roomRetrieve the user details from Matrix servergetUserDisplayName(String userMatrixId, String matrixAccessToken) getUserPresence(String matrixIdOfUser, String accessToken) Retrieve the user presence from Matrix serverbooleaninvalidateAccessToken(String accessToken) Invalidates an access token on Matrix serverbooleaninviteUserToRoom(String roomId, String userMatrixId, String invitationMessage, String token) Invites a user to a specific room on MatrixbooleanjoinUserToRoom(String matrixRoomId, String matrixIdOfUser, String token) Adds directly a user to a roombooleankickUserFromRoom(String roomId, String userMatrixId, String raisonMessage, String token) Kicks a user out of a specific room on MatrixbooleanmakeUserAdminInRoom(String matrixRoomId, String matrixIdOfUser, String token) Make user an admin of the roomoverrideRateLimitForUser(String userIdOnMatrix, int messagesPerSecond, int burstCount, String accessToken) Overrides the rate limits for a given userrenameRoom(String roomId, String newRoomName, String token) saveUserAccount(org.exoplatform.social.core.identity.model.Identity user, String matrixUserId, boolean isNew, String token) Saves the user account on MatrixsaveUserAccount(org.exoplatform.social.core.identity.model.Identity user, String matrixUserId, boolean isNew, String token, boolean isEnableUserOperation, boolean isUserEnabled) Saves the user accountsetUserPresence(String matrixIdOfUser, String presence, String statusMessage, String accessToken) Set the user presence on Matrix serverbooleanupdateRoomAvatar(String matrixRoomId, String avatarURL, String accessToken) Update room avatarbooleanupdateRoomDescription(String matrixRoomId, String description, String accessToken) Updates the room descriptionupdateRoomSettings(String matrixRoomId, MatrixRoomPermissions roomSettings, String accessToken) Updates the room settingsbooleanupdateUserAvatar(String userMatrixId, String avatarURL, String accessToken) Update the user avatarvoidupdateUserDisplayName(String userMatrixId, String displayName, String token) Sets a new display name for the useruploadFile(String fileName, String mimeType, byte[] imageBytes, String accessToken)
-
Constructor Details
-
MatrixHttpClient
public MatrixHttpClient()
-
-
Method Details
-
getAccessToken
public String getAccessToken(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 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
-
createUserAccount
-
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 MatrixdisplayName- the new display nametoken- the access token- Throws:
IOExceptionInterruptedExceptionorg.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 identitymatrixUserId- the user Matrix ID to setisNew- if the user has been just createdtoken- 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 UsermatrixUserId- the corresponding matrix IDisNew- if the user account is onetoken- the access tokenisEnableUserOperation- is this an operation to enable/disable the user on Matrix- Returns:
- the user Matrix ID
-
disableAccount
-
renameRoom
-
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 roomuserMatrixId- the Matrix id of the userinvitationMessage- a custom invitation message- Returns:
-
kickUserFromRoom
public boolean 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
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:
IOExceptionInterruptedExceptionorg.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:
IOExceptionInterruptedExceptionorg.exoplatform.ws.frameworks.json.impl.JsonException
-
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
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
-
getUserDisplayName
public String getUserDisplayName(String userMatrixId, String matrixAccessToken) throws IOException, InterruptedException, org.exoplatform.ws.frameworks.json.impl.JsonException - Throws:
IOExceptionInterruptedExceptionorg.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 MatrixaccessToken- the access token- Returns:
- the value of the presence
- Throws:
IOExceptionInterruptedExceptionorg.exoplatform.ws.frameworks.json.impl.JsonException
-
getUser
public String getUser(String matrixIdOfUser, String accessToken) throws IOException, InterruptedException Retrieve the user details from Matrix server- Parameters:
matrixIdOfUser- the ID of the user on MatrixaccessToken- the access token- Returns:
- String representing JSON of the user
- Throws:
IOExceptionInterruptedException
-
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 Matrixpresence- the presence value : 'online, offline , unavailable"statusMessage- : the personalized status messageaccessToken- the access token- Returns:
- Throws:
IOExceptionInterruptedExceptionorg.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 MatrixmessagesPerSecond- the allowed number of messages per secondburstCount- how many actions that can be performed before being limitedaccessToken- the access token- Returns:
- String the applied rate limits configuration
- Throws:
IOExceptionInterruptedException
-
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 MatrixaccessToken- the access token- Returns:
- String the applied rate limits configuration
- Throws:
IOExceptionInterruptedException
-
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:
IOExceptionInterruptedExceptionorg.exoplatform.ws.frameworks.json.impl.JsonException
-
invalidateAccessToken
Invalidates an access token on Matrix server- Parameters:
accessToken-- Returns:
- Throws:
IOExceptionInterruptedException
-
getMediaInfo
public Optional<MediaInfo> getMediaInfo(String mediaId, String accessToken) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
deleteMedia
public HttpResponse<String> deleteMedia(String mediaId, String accessToken) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-