Package io.meeds.chat.service
Class MatrixService
java.lang.Object
io.meeds.chat.service.MatrixService
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMatrixService(MatrixRoomStorage matrixRoomStorage, org.exoplatform.social.core.manager.IdentityManager identityManager, org.exoplatform.social.core.storage.api.IdentityStorage identityStorage, org.exoplatform.services.organization.OrganizationService organizationService, MatrixHttpClient matrixHttpClient, org.exoplatform.services.cache.CacheService cacheService) -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if the user able to access the roomcleanMatrixUsername(String userName) Cleans the username to be compatible with the usernames on Matrix servercreateDirectMessagingRoom(Room directMessagingRoom) createRoom(org.exoplatform.social.core.space.model.Space space) This function do : - Create a room on Matrix - Links the room to the space on Meeds - Update room permissionscreateRoomForSpaceOnMatrix(org.exoplatform.social.core.space.model.Space space) Creates a room on Matrix for the spacevoiddeleteMedia(String mediaId) Deletes synapse media by its IDvoiddeleteRoom(String roomId) Delete a Matrix roomvoiddisableAccount(String matrixUsername) enableSpaceChat(org.exoplatform.social.core.space.model.Space space, boolean enable) Enable the chat for the spaceextractRoomId(String fullMatrixUserId) Extracts the room ID from the full room Id on MatrixextractUserId(String fullMatrixUserId) Extracts the user ID from the full User Id on Matrixorg.exoplatform.social.core.identity.model.IdentityfindSpaceMemberByMatrixId(String matrixId, org.exoplatform.social.core.space.model.Space space) Finds the identity of a user based on its Matrix ID and a space where he is a memberfindUserByMatrixId(String userMatrixId) find the user on Meeds based on his id on MatrixgetAccessToken(String jwtToken) Retrieves an access token for a user using a JWT tokenGet a room by its technical IDGet a room by its technical IDgetDirectMessagingRoom(String firstParticipant, String secondParticipant) getJWTSessionToken(String userNameOnMatrix) Returns the JWT for user authenticationgetMatrixDMRoomsOfUser(String user) getMatrixIdForUser(String userName) Get the matrix ID of a defined usergetMediaInfo(String mediaId) Returns synapse media info by its IDString[]Returns the restricted group of users if it is configuredgetRoomBySpace(org.exoplatform.social.core.space.model.Space space) Returns the ID of the room linked to a spacegetRoomBySpace(org.exoplatform.social.core.space.model.Space space, boolean includeDisabled) Returns the ID of the room linked to a spacegetRoomBySpaceId(String spaceId) Returns the ID of the room linked to a spacegetRoomBySpaceId(String spaceId, boolean includeDisabled) Returns the ID of the room linked to a spacegetRoomEvent(String eventId, String roomId) Retrieves the message related to the event IDgetRoomEvent(String eventId, String roomId, String token) Retrieves the message related to the event IDgetRoomSettings(String roomId) Returns a list of all space roomsgetUserFullMatrixID(String userName) Convert the user id into the full Matrx ID formatvoidinit()booleaninvalidateAccessToken(String accessToken) Invalidate a specific access tokenbooleanisUserMemberOfGroups(String userName, String... groups) Checks if the user is a member of a group defined by its namevoidjoinUserToRoom(String roomId, String matrixIdOfUser) voidkickUserFromRoom(String roomId, String matrixIdOfUser, String message) linkSpaceToMatrixRoom(org.exoplatform.social.core.space.model.Space space, String roomId) records the matrix ID of the room linked to the spacevoidmakeUserAdminInRoom(String matrixRoomId, String matrixIdOfUser) voidoverrideAdminRateLimit(String adminUserId) Overrides the rate limits for the current administrator to unlimitedvoidrenameRoom(String roomId, String spaceDisplayName) saveUserAccount(org.exoplatform.social.core.identity.model.Identity user, boolean isNew) Saves a new user on MatrixsaveUserAccount(org.exoplatform.social.core.identity.model.Identity user, boolean isNew, boolean isEnableUserOperation, boolean isUserEnabled) Saves a new user on MatrixvoidupdateRoomAvatar(org.exoplatform.social.core.space.model.Space space, String roomId) booleanupdateRoomDescription(String roomId, String description) booleanupdateRoomSettings(String roomId, MatrixRoomPermissions matrixRoomPermissions) voidupdateUserAvatar(org.exoplatform.social.core.identity.model.Profile profile, String userMatrixID) voidupdateUserDisplayName(String matrixFullID, String newDisplayName) updateUserPresence(String userIdOnMatrix, String presence, String statusMessage) update the user presence status on MatrixuploadFileOnMatrix(String fileName, String mimeType, byte[] fileBytes)
-
Field Details
-
USER_MATRIX_ID_CACHE_NAME
- See Also:
-
-
Constructor Details
-
MatrixService
public MatrixService(MatrixRoomStorage matrixRoomStorage, org.exoplatform.social.core.manager.IdentityManager identityManager, org.exoplatform.social.core.storage.api.IdentityStorage identityStorage, org.exoplatform.services.organization.OrganizationService organizationService, MatrixHttpClient matrixHttpClient, org.exoplatform.services.cache.CacheService cacheService)
-
-
Method Details
-
init
@PostConstruct public void init() -
getUserFullMatrixID
Convert the user id into the full Matrx ID format- Parameters:
userName-- Returns:
- formatted username
-
getAccessToken
public String getAccessToken(String jwtToken) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException Retrieves an access token for a user using a JWT token- Parameters:
jwtToken-- Returns:
- String the access token
- Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
invalidateAccessToken
Invalidate a specific access token- Parameters:
accessToken-- Returns:
- true if success
-
updateUserDisplayName
-
getRoomBySpace
Returns the ID of the room linked to a space- Parameters:
space- the space- Returns:
- the roomId linked to the space
-
getRoomBySpace
public Room getRoomBySpace(org.exoplatform.social.core.space.model.Space space, boolean includeDisabled) Returns the ID of the room linked to a space- Parameters:
space- the space- Returns:
- the roomId linked to the space
-
getRoomBySpaceId
Returns the ID of the room linked to a space- Parameters:
spaceId- the space Id- Returns:
- the roomId linked to the space
-
getRoomBySpaceId
Returns the ID of the room linked to a space- Parameters:
spaceId- the space Id- Returns:
- the roomId linked to the space
-
getById
Get a room by its technical ID- Parameters:
roomId- the room technical ID- Returns:
- Room
-
getById
Get a room by its technical ID- Parameters:
roomId- the room technical IDincludeDisabled- return room even if it is disabled- Returns:
- Room
-
linkSpaceToMatrixRoom
public Room linkSpaceToMatrixRoom(org.exoplatform.social.core.space.model.Space space, String roomId) records the matrix ID of the room linked to the space- Parameters:
space- the SpaceroomId- the ID of the matrix room- Returns:
- the room ID
-
createRoomForSpaceOnMatrix
public String createRoomForSpaceOnMatrix(org.exoplatform.social.core.space.model.Space space) throws Exception Creates a room on Matrix for the space- Parameters:
space- the space- Returns:
- String representing the room id
- Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedExceptionException
-
getMatrixIdForUser
Get the matrix ID of a defined user- Parameters:
userName- of the user- Returns:
- the matrix ID
-
getJWTSessionToken
Returns the JWT for user authentication- Parameters:
userNameOnMatrix- the username of the current user- Returns:
- String
-
saveUserAccount
public String saveUserAccount(org.exoplatform.social.core.identity.model.Identity user, boolean isNew) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException Saves a new user on Matrix- Parameters:
user- the user identityisNew- if the user has been just created- Returns:
- the matrix user ID
- Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
saveUserAccount
public String saveUserAccount(org.exoplatform.social.core.identity.model.Identity user, boolean isNew, boolean isEnableUserOperation, boolean isUserEnabled) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException Saves a new user on Matrix- Parameters:
user- the user to create on MatrixisNew- boolean if the user is new, then true- Returns:
- String the matrix user ID
- Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
uploadFileOnMatrix
public String uploadFileOnMatrix(String fileName, String mimeType, byte[] fileBytes) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException - Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
updateUserAvatar
public void updateUserAvatar(org.exoplatform.social.core.identity.model.Profile profile, String userMatrixID) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException - Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
disableAccount
public void disableAccount(String matrixUsername) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException - Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
updateRoomDescription
public boolean updateRoomDescription(String roomId, String description) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException - Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
updateRoomAvatar
public void updateRoomAvatar(org.exoplatform.social.core.space.model.Space space, String roomId) throws Exception - Throws:
Exception
-
getRoomSettings
public MatrixRoomPermissions getRoomSettings(String roomId) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException - Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
updateRoomSettings
public boolean updateRoomSettings(String roomId, MatrixRoomPermissions matrixRoomPermissions) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException - Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
kickUserFromRoom
public void kickUserFromRoom(String roomId, String matrixIdOfUser, String message) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException - Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
joinUserToRoom
public void joinUserToRoom(String roomId, String matrixIdOfUser) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException - Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
renameRoom
public void renameRoom(String roomId, String spaceDisplayName) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException - Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
makeUserAdminInRoom
public void makeUserAdminInRoom(String matrixRoomId, String matrixIdOfUser) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException - Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
createRoom
This function do : - Create a room on Matrix - Links the room to the space on Meeds - Update room permissions- Parameters:
space- The space- Returns:
- The room ID
- Throws:
Exception
-
getDirectMessagingRoom
-
deleteRoom
public void deleteRoom(String roomId) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException Delete a Matrix room- Parameters:
roomId- the room identifier- Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
createDirectMessagingRoom
public Room createDirectMessagingRoom(Room directMessagingRoom) throws org.exoplatform.commons.ObjectAlreadyExistsException - Throws:
org.exoplatform.commons.ObjectAlreadyExistsException
-
getMatrixDMRoomsOfUser
-
isUserMemberOfGroups
Checks if the user is a member of a group defined by its name- Parameters:
userName- the userNamegroups- the list of groups- Returns:
- true if the user is a member of the group
- Throws:
Exception
-
getSpaceRooms
Returns a list of all space rooms- Returns:
- List of Space rooms
-
extractUserId
Extracts the user ID from the full User Id on Matrix- Parameters:
fullMatrixUserId- the full Matrix user Id- Returns:
- the user Identifier
-
extractRoomId
Extracts the room ID from the full room Id on Matrix- Parameters:
fullMatrixUserId- the full Matrix user Id- Returns:
- the user Identifier
-
updateUserPresence
update the user presence status on Matrix- Parameters:
userIdOnMatrix- the user Id on Matrixpresence- the presence value: online , unavailable, offlinestatusMessage- a personalized status message
-
canAccess
Checks if the user able to access the room- Parameters:
room- the roomuserName- the username of the user- Returns:
- true if he has access, false otherwise
-
enableSpaceChat
public Room enableSpaceChat(org.exoplatform.social.core.space.model.Space space, boolean enable) throws org.exoplatform.commons.exception.ObjectNotFoundException Enable the chat for the space- Parameters:
space- the space where the chat will be disabled/enabledenable- true to enable the room, false to disable it- Returns:
- Room the updated room
- Throws:
org.exoplatform.commons.exception.ObjectNotFoundException
-
overrideAdminRateLimit
Overrides the rate limits for the current administrator to unlimited- Parameters:
adminUserId- the admin username on Matrix
-
getRoomEvent
Retrieves the message related to the event ID- Parameters:
eventId- the event IDroomId- the room ID- Returns:
- MatrixMessage the received message
-
getRoomEvent
Retrieves the message related to the event ID- Parameters:
eventId- the event IDroomId- the room ID- Returns:
- MatrixMessage the received message
-
findSpaceMemberByMatrixId
public org.exoplatform.social.core.identity.model.Identity findSpaceMemberByMatrixId(String matrixId, org.exoplatform.social.core.space.model.Space space) Finds the identity of a user based on its Matrix ID and a space where he is a member- Parameters:
matrixId-space-- Returns:
-
findUserByMatrixId
find the user on Meeds based on his id on Matrix- Parameters:
userMatrixId- the ID of the user on Matrix- Returns:
- the user Identity
-
cleanMatrixUsername
Cleans the username to be compatible with the usernames on Matrix server- Parameters:
userName- the user identifier- Returns:
- String the cleaned username
-
getRestrictedGroups
Returns the restricted group of users if it is configured- Returns:
- Array of group names
-
getMediaInfo
public Optional<MediaInfo> getMediaInfo(String mediaId) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException Returns synapse media info by its ID- Parameters:
mediaId- synapse media id- Returns:
MediaInfowrapped inOptional, orOptional.empty()if mediaId is null or blank- Throws:
org.exoplatform.ws.frameworks.json.impl.JsonException- if there is an error parsing the JSON response from the serverIOException- if a network or I/O error occurs during the requestInterruptedException- if the thread executing the request is interrupted
-
deleteMedia
public void deleteMedia(String mediaId) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException Deletes synapse media by its ID- Parameters:
mediaId- synapse media id- Throws:
IllegalArgumentException- if mediaId is null or blankorg.exoplatform.ws.frameworks.json.impl.JsonException- if there is an error parsing the JSON response from the serverIOException- if a network or I/O error occurs during the requestInterruptedException- if the thread executing the request is interrupted
-