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, org.exoplatform.commons.api.settings.SettingService settingService, io.meeds.social.space.template.service.SpaceTemplateService spaceTemplateService) -
Method Summary
Modifier and TypeMethodDescription<T> TcallAsUserOrThrow(String userName, String matrixId, Duration timeout, MatrixUserCall<T> operation) Executes a Matrix operation on behalf of the given user likecallAsUserOrThrow(String, Duration, MatrixUserCall), with the user's Matrix id as the caller knows it: a listener's request may not have committed the profile write that stores it yet.<T> TcallAsUserOrThrow(String userName, Duration timeout, MatrixUserCall<T> operation) Executes a Matrix operation on behalf of the given user likecallAsUser(String, T, MatrixUserCall), but propagates every failure instead of answering a fallback, so a caller tells a timeout or an error from an empty result.booleanChecks if the user able to access the roomvoidchangeChatRoomReadability(String roomId, boolean readOnly) Sets the room to readOnlycleanMatrixUsername(String userName) Cleans the username to be compatible with the usernames on Matrix servercreateDirectMessagingRoom(Room directMessagingRoom) Creates a one to one roomcreateRoom(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 MatrixfindUserByMatrixIdOrThrow(String userMatrixId, Duration timeout) Finds the platform user of a Matrix id likefindUserByMatrixId(String), every request bounded bytimeout(the administrator login, when its token is not cached yet, and the user read) and every failure propagated.getAccessToken(String jwtToken) Retrieves an access token for a user using a JWT tokenLists the groups of the account kinds the add-ons declare.Get 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) Loads all the one to one rooms of a defined usergetMatrixIdForUser(String userName) Get the matrix ID of a defined usergetMediaInfo(String mediaId) Returns synapse media info by its IDgetOrCreateDirectMessagingRoom(String userName, String recipientUserName) Returns the direct messaging room between a user and another one, and creates it when it does not exist yet, as the web chat does: the room is created on Matrix as the user, the other participant invited, then it is recorded on the platform and the user'sm.directaccount data is updated.String[]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(Long spaceId) Returns the ID of the room linked to a spacegetRoomBySpaceId(Long 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 IDgetRoomEventAsUser(String userName, String roomId, String eventId) Reads one event back with the user's own Matrix identity, so an event of a room the administrator account cannot see (a direct message) resolves too.getRoomEventOrThrow(String eventId, String roomId, Duration timeout) Reads one message event with the administrator account, every request bounded bytimeout: the administrator login, when its token is not cached yet, and the read.getRoomMessages(String userName, String roomId, int limit) Returns the most recent messages of a conversation, in chronological order, read as the given user so that Synapse enforces exactly what that user is allowed to see (membership, history visibility, redactions).getRoomMessages(String userName, String roomId, int limit, Duration timeout) Returns the most recent messages of a conversation likegetRoomMessages(String, String, int), every request bounded bytimeoutand every failure propagated: a timeout, an unreachable Matrix or a user without a Matrix account is thrown, so the caller tells it from a conversation with nothing to read.getRoomSettings(String roomId) Returns a list of all space roomsgetUnreadConversations(String userName) Returns the unread conversations of the given user, read as that user via a Matrix/sync, so only the rooms the user has joined are considered.getUserConversations(String userName) Lists the conversations the given user participates in: their direct messaging rooms and the rooms of the spaces they are a member of.getUserConversations(String userName, String type, String query, Integer limit) Lists the conversations the given user participates in, asgetUserConversations(String)does, keeping those of a type and those whose title, or for a direct message the other participant's username, contains a text.getUserFullMatrixID(String userName) Convert the user id into the full Matrix ID formatvoidinit()Kicks off the connection to the Matrix server on a background thread so that the (possibly slow, possibly retried) handshake never blocks the WAR deployment / server startup.booleaninvalidateAccessToken(String accessToken) Invalidate a specific access tokenbooleanisChatAuthorizedByAdministration(org.exoplatform.social.core.space.model.Space space) Checks if the Chat is authorized from the administration for the spacebooleanisChatAuthorizedForSpace(Long spaceId) Check if Chat application is authorized for the space based on its templatebooleanisChatAuthorizedForSpace(org.exoplatform.social.core.space.model.Space space) Check if Chat application is authorized for the space based on its templatebooleanisChatAuthorizedForSpaceTemplate(org.exoplatform.social.core.space.model.Space space) Checks if the Chat is authorized for the template used to create the spacebooleanisChatEnabledByDefault(org.exoplatform.social.core.space.model.Space space) Check if the chat is enabled and synched be default for the provided spacebooleanisChatUser(String userName) Tells whether a user may have a chat account: chat is restricted to no group, the user is a member of one of the restricted groups, or the user's account is of a kind an add-on declares (a digital worker), which uses chat wherever chat is restricted.booleanChecks if the Chat feature is enabled and that the Matrix service is availablebooleanisUserMemberOfGroups(String userName, String... groups) Checks if the user is a member of a group defined by its namebooleanisUserMemberOfRoom(String roomId, String matrixIdOfUser) Checks if the user is a member of the roomvoidjoinUserToRoom(String roomId, String matrixIdOfUser) voidkickUserFromRoom(String roomId, String matrixIdOfUser, String message) linkSpaceToMatrixRoom(long spaceId, String roomId, RoomStatus roomStatus) records the matrix ID of the room linked to the spacelinkSpaceToMatrixRoom(org.exoplatform.social.core.space.model.Space space, String roomId) records the matrix ID of the room linked to the spaceretrieves the chat settingsloadChatSettings(String userName, Locale locale) retrieves the chat settingsvoidmakeUserAdminInRoom(String matrixRoomId, String matrixIdOfUser) booleanmarkRoomAsRead(String userName, String roomId, String eventId) Marks a room as read for a user up to an event, with the user's own Matrix identity (server-side read anchor): posts them.readreceipt so every client of the user converges through Matrix sync.voidoverrideAdminRateLimit(String adminUserId) Overrides the rate limits for the current administrator to unlimitedvoidrenameRoom(String roomId, String spaceDisplayName) voidsaveChatSettings(ChatSettings chatSettings) Sets the settings of the chat featuresaveUserAccount(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 MatrixsearchChatMessages(String userName, String query, String conversationId, int limit) Runs a full-text search of message bodies as the given user, either across all their conversations (whenconversationIdis blank) or scoped to a single conversation.sendDirectMessage(String userName, String recipientUserName, String text) Sends a text message to another user as the given user, in their direct messaging room, which is created first when they have none.sendMessage(String userName, String roomId, String text) Sends a textual message to a conversation as the given user, after checking that the user participates in it.sendReply(String userName, String roomId, String body, String formattedBody, String inReplyToEventId, List<String> mentionedMatrixIds, Duration timeout) Posts a reply as the given user, quoting the event it answers and mentioning the given Matrix users, with the content the web composer sends:m.in_reply_to, an HTMLformatted_bodyandm.mentions.voidupdateRoomAvatar(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
-
CHAT_APPLICATION_ID
- See Also:
-
USER_MATRIX_ID_CACHE_NAME
- See Also:
-
defaultAuthorizedSpaceTemplates
-
USER_ACCESS_TOKEN_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, org.exoplatform.commons.api.settings.SettingService settingService, io.meeds.social.space.template.service.SpaceTemplateService spaceTemplateService)
-
-
Method Details
-
init
@PostConstruct public void init()Kicks off the connection to the Matrix server on a background thread so that the (possibly slow, possibly retried) handshake never blocks the WAR deployment / server startup. SeeAsyncTaskUtils.runAsync(String, Runnable)for the escape hatch used by tests to run it synchronously instead. -
isServiceEnabled
public boolean isServiceEnabled()Checks if the Chat feature is enabled and that the Matrix service is available- Returns:
- the status fo the chat service and feature
-
getUserFullMatrixID
-
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- the Json Web Token- Returns:
- String the access token
- Throws:
org.exoplatform.ws.frameworks.json.impl.JsonExceptionIOExceptionInterruptedException
-
invalidateAccessToken
Invalidate a specific access token- Parameters:
accessToken- the access token to be invalidated- 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
-
getRoomBySpaceId
-
getById
-
getById
-
linkSpaceToMatrixRoom
-
linkSpaceToMatrixRoom
records the matrix ID of the room linked to the space- Parameters:
spaceId- the Space identifierroomId- the ID of the matrix room- Returns:
- the room ID
-
createRoomForSpaceOnMatrix
-
getMatrixIdForUser
-
getJWTSessionToken
-
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
-
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
-
isUserMemberOfRoom
public boolean isUserMemberOfRoom(String roomId, String matrixIdOfUser) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException Checks if the user is a member of the room- Parameters:
roomId- the room IDmatrixIdOfUser- the ID of the user on Matrix- Returns:
- true if the user is a member of the room, false otherwise
- 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
-
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 Creates a one to one room- Parameters:
directMessagingRoom- the Object representation of a one to one room- Returns:
- the created Room
- Throws:
org.exoplatform.commons.ObjectAlreadyExistsException- in case a room between the same users is already created
-
getOrCreateDirectMessagingRoom
public Room getOrCreateDirectMessagingRoom(String userName, String recipientUserName) throws Exception Returns the direct messaging room between a user and another one, and creates it when it does not exist yet, as the web chat does: the room is created on Matrix as the user, the other participant invited, then it is recorded on the platform and the user'sm.directaccount data is updated. When a parallel call records the pair while the room is created on Matrix, its room is returned and the user'sm.directupdated to it. The room just created is not recorded, but it stays on Matrix: the user is joined to it and the other participant holds a pending direct-message invite to it, as for the web chat's own duplicate. As increateDirectMessagingRoom(Room), only the database check and save remain unguarded. The user may open a direct message only where the chat lets them: direct messages are enabled, both users may use the chat (isChatUser(String)), and the other participant is an enabled user with a chat account.- Parameters:
userName- the username of the user opening the conversationrecipientUserName- the username of the other participant- Returns:
- the direct messaging room
- Throws:
org.exoplatform.commons.exception.ObjectNotFoundException- when no user has that usernameIllegalAccessException- when the user may not message that user, the message saying why: direct messages disabled, a user outside the chat, a disabled or deleted recipient, or one with no chat accountIllegalArgumentException- when a username is blank or both are the sameException- any failure of the room creation on Matrix
-
sendDirectMessage
public String sendDirectMessage(String userName, String recipientUserName, String text) throws Exception Sends a text message to another user as the given user, in their direct messaging room, which is created first when they have none. Used by thesend_direct_messageMCP tool.- Parameters:
userName- the username of the user sending the messagerecipientUserName- the username of the recipienttext- the plain text message to send- Returns:
- the created event id, or
nullwhen the text is blank or the message could not be sent - Throws:
org.exoplatform.commons.exception.ObjectNotFoundException- when no user has that usernameIllegalAccessException- when the user may not message that user, the message saying whyIllegalArgumentException- when a username is blank or both are the sameException- any failure of the room creation on Matrix
-
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- error finding the user
-
getSpaceRooms
-
extractUserId
-
extractRoomId
-
updateUserPresence
-
canAccess
-
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
-
getRoomEventOrThrow
public MatrixMessage getRoomEventOrThrow(String eventId, String roomId, Duration timeout) throws Exception Reads one message event with the administrator account, every request bounded bytimeout: the administrator login, when its token is not cached yet, and the read. Propagates every failure. A room ID stored as its local part is completed with the server name, as the send and history reads do; a full room ID is read as given.- Parameters:
eventId- the event IDroomId- the room ID, as its local part or in fulltimeout- the timeout of each request- Returns:
- the message, null when the event is missing or not an
m.room.message - Throws:
Exception- when the login or the read fails or times out
-
findUserByMatrixIdOrThrow
Finds the platform user of a Matrix id likefindUserByMatrixId(String), every request bounded bytimeout(the administrator login, when its token is not cached yet, and the user read) and every failure propagated.- Parameters:
userMatrixId- the Matrix idtimeout- the timeout of each request- Returns:
- the platform login, null when no platform user has the Matrix account's email
- Throws:
Exception- when the login or the read fails or times out
-
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- the Matrix identifier of the userspace- the space- Returns:
- the identity of the space member
-
findUserByMatrixId
-
cleanMatrixUsername
-
isChatUser
Tells whether a user may have a chat account: chat is restricted to no group, the user is a member of one of the restricted groups, or the user's account is of a kind an add-on declares (a digital worker), which uses chat wherever chat is restricted.- Parameters:
userName- the user name- Returns:
- true when the user may have a chat account
- Throws:
Exception- when the user's memberships cannot be read
-
getAccountKindGroups
-
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
-
loadChatSettings
retrieves the chat settings- Returns:
- the status of the chat feature
-
loadChatSettings
retrieves the chat settings- Parameters:
userName- the caller usernamelocale- the caller Locale- Returns:
- the Chat settings
-
saveChatSettings
Sets the settings of the chat feature- Parameters:
chatSettings- the new status fo the chat enabled/disabled
-
isChatAuthorizedForSpace
Check if Chat application is authorized for the space based on its template- Parameters:
spaceId- The space identifier- Returns:
- boolean : true if the chat is authorized
-
isChatAuthorizedForSpace
public boolean isChatAuthorizedForSpace(org.exoplatform.social.core.space.model.Space space) Check if Chat application is authorized for the space based on its template- Parameters:
space- The space- Returns:
- boolean : true if the chat is authorized
-
isChatAuthorizedForSpaceTemplate
public boolean isChatAuthorizedForSpaceTemplate(org.exoplatform.social.core.space.model.Space space) Checks if the Chat is authorized for the template used to create the space- Parameters:
space- The given space- Returns:
- True if the chat was authorized for this space template
-
isChatAuthorizedByAdministration
public boolean isChatAuthorizedByAdministration(org.exoplatform.social.core.space.model.Space space) Checks if the Chat is authorized from the administration for the space- Parameters:
space- The given space- Returns:
- True if the chat was authorized for this space
-
isChatEnabledByDefault
public boolean isChatEnabledByDefault(org.exoplatform.social.core.space.model.Space space) Check if the chat is enabled and synched be default for the provided space- Parameters:
space- the related space- Returns:
- boolean True if the chat is enabled by default
-
changeChatRoomReadability
Sets the room to readOnly- Parameters:
roomId- the room identifierreadOnly- true if the room will be set readonly
-
getUserConversations
Lists the conversations the given user participates in: their direct messaging rooms and the rooms of the spaces they are a member of. Used by thelist_chat_conversationsMCP tool to give AI agents the user's chat context.- Parameters:
userName- the Meeds username- Returns:
- the user's conversations, never
null
-
getUserConversations
public List<ChatConversation> getUserConversations(String userName, String type, String query, Integer limit) Lists the conversations the given user participates in, asgetUserConversations(String)does, keeping those of a type and those whose title, or for a direct message the other participant's username, contains a text. The match ignores case and accents.- Parameters:
userName- the Meeds usernametype-"dm"or"space"to keep one type only, blank to keep bothquery- the text to look for, blank to keep every conversationlimit- the maximum number of conversations to return,nullfor no maximum- Returns:
- the matching conversations, never
null
-
getRoomEventAsUser
Reads one event back with the user's own Matrix identity, so an event of a room the administrator account cannot see (a direct message) resolves too. A room ID stored as its local part is completed with the server name.- Parameters:
userName- the platform userroomId- the room (local or full id)eventId- the event to read back- Returns:
- the event, or null when it cannot be read
-
markRoomAsRead
Marks a room as read for a user up to an event, with the user's own Matrix identity (server-side read anchor): posts them.readreceipt so every client of the user converges through Matrix sync.- Parameters:
userName- the platform userroomId- the room (local or full id)eventId- the event read up to (high-water mark)- Returns:
- true when the receipt was posted
-
callAsUserOrThrow
public <T> T callAsUserOrThrow(String userName, Duration timeout, MatrixUserCall<T> operation) throws Exception Executes a Matrix operation on behalf of the given user likecallAsUser(String, T, MatrixUserCall), but propagates every failure instead of answering a fallback, so a caller tells a timeout or an error from an empty result. A login it needs is bounded bytimeout; the operation bounds its own requests. A token Synapse rejects (HTTP 401) is refreshed once and the operation retried once.- Type Parameters:
T- the operation result type- Parameters:
userName- the Meeds username actingtimeout- the login request timeoutoperation- the operation to run with a valid access token- Returns:
- the operation result
- Throws:
MatrixException- when the user has no Matrix accountException- any failure of the login or of the operation
-
callAsUserOrThrow
public <T> T callAsUserOrThrow(String userName, String matrixId, Duration timeout, MatrixUserCall<T> operation) throws Exception Executes a Matrix operation on behalf of the given user likecallAsUserOrThrow(String, Duration, MatrixUserCall), with the user's Matrix id as the caller knows it: a listener's request may not have committed the profile write that stores it yet.- Type Parameters:
T- the operation result type- Parameters:
userName- the Meeds username actingmatrixId- the user's Matrix id, null to read it from the profiletimeout- the login request timeoutoperation- the operation to run with a valid access token- Returns:
- the operation result
- Throws:
MatrixException- when the user has no Matrix accountException- any failure of the login or of the operation
-
getRoomMessages
Returns the most recent messages of a conversation, in chronological order, read as the given user so that Synapse enforces exactly what that user is allowed to see (membership, history visibility, redactions). A cheap participant pre-check avoids reading conversations the user is obviously not part of. Used by theget_chat_messagesMCP tool.- Parameters:
userName- the Meeds username actingroomId- the Matrix room id of the conversationlimit- the maximum number of messages to return (clamped to [1, 200])- Returns:
- the conversation messages, oldest first, never
null
-
getRoomMessages
public List<ChatMessage> getRoomMessages(String userName, String roomId, int limit, Duration timeout) throws Exception Returns the most recent messages of a conversation likegetRoomMessages(String, String, int), every request bounded bytimeoutand every failure propagated: a timeout, an unreachable Matrix or a user without a Matrix account is thrown, so the caller tells it from a conversation with nothing to read. A user who does not participate in the conversation reads nothing, as in the unbounded read.- Parameters:
userName- the Meeds username actingroomId- the Matrix room id of the conversation, local part or full idlimit- the maximum number of messages to return (clamped to [1, 200])timeout- the bound of each request- Returns:
- the conversation messages, edits merged, oldest first, never
null - Throws:
Exception- any failure of the login or of the read
-
getUnreadConversations
Returns the unread conversations of the given user, read as that user via a Matrix/sync, so only the rooms the user has joined are considered. Each entry carries the unread count and the recent messages, edits merged into the message they replace as in the room read, with a human readable title resolved from the user's conversations. Used by theget_unread_chat_messagesMCP tool.- Parameters:
userName- the Meeds username acting- Returns:
- the user's unread conversations, never
null
-
sendMessage
Sends a textual message to a conversation as the given user, after checking that the user participates in it. Synapse additionally enforces that the user is allowed to post. Used by thesend_chat_messageMCP tool, e.g. to let an AI agent post a real-time reply on the user's behalf.- Parameters:
userName- the Meeds username actingroomId- the Matrix room id of the conversationtext- the plain text message to send- Returns:
- the created event id, or
nullwhen the message could not be sent
-
sendReply
public String sendReply(String userName, String roomId, String body, String formattedBody, String inReplyToEventId, List<String> mentionedMatrixIds, Duration timeout) throws Exception Posts a reply as the given user, quoting the event it answers and mentioning the given Matrix users, with the content the web composer sends:m.in_reply_to, an HTMLformatted_bodyandm.mentions. The mentions are exactlymentionedMatrixIds, chosen by the caller, never read from the text. The transaction id is derived from the replied-to event and the user, so Synapse posts a reply retried with the same access token once; a retry after the token was refreshed is a new device, and Synapse posts it again. The request is bounded bytimeoutand a failure is thrown.- Parameters:
userName- the Meeds username replyingroomId- the Matrix room id of the conversation, local part or full idbody- the plain text bodyformattedBody- the HTML body, null or blank to send the plain body onlyinReplyToEventId- the event id the reply answersmentionedMatrixIds- the Matrix ids the reply mentionstimeout- the bound of each request- Returns:
- the created event id, or
nullwhen nothing was sent because an argument is blank or the user does not participate in the conversation - Throws:
Exception- any failure of the login or of the send
-
searchChatMessages
public List<ChatSearchResult> searchChatMessages(String userName, String query, String conversationId, int limit) Runs a full-text search of message bodies as the given user, either across all their conversations (whenconversationIdis blank) or scoped to a single conversation. Synapse enforces the user's Matrix visibility, and the hits are then restricted to the conversations that are tracked by the platform and accessible to the user — the same rooms the chat list shows and the row can open — so a room they still belong to on Matrix but not in the chat (created from another Matrix client, left behind by a failed space kick) is never returned. Each hit is resolved to a human readable conversation title. Backs thesearch_chat_messagesMCP tool and the chat UI search.- Parameters:
userName- the Meeds username actingquery- the free-text search termconversationId- the Matrix room id to scope the search to, ornull/blank to search across all the user's conversationslimit- the maximum number of hits to return (clamped to [1, 100])- Returns:
- the matching messages, most recent first, never
null
-