Class MatrixService

java.lang.Object
io.meeds.chat.service.MatrixService

@Service public class MatrixService extends Object
  • 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)
  • Method Details

    • init

      @PostConstruct public void init()
    • updateUserDisplayName

      public void updateUserDisplayName(String matrixFullID, String newDisplayName)
    • getRoomBySpace

      public Room getRoomBySpace(org.exoplatform.social.core.space.model.Space space)
      Returns the ID of the room linked to a space
      Parameters:
      space -
      Returns:
      the roomId linked to the space
    • getById

      public Room getById(String roomId)
      Get a room by its technical ID
      Parameters:
      roomId - the room technical ID
      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 Space
      roomId - 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.JsonException
      IOException
      InterruptedException
      Exception
    • getMatrixIdForUser

      public String getMatrixIdForUser(String userName)
      Get the matrix ID of a defined user
      Parameters:
      userName - of the user
      Returns:
      the matrix ID
    • getJWTSessionToken

      public String getJWTSessionToken(String userNameOnMatrix)
      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 identity
      isNew - if the user has been just created
      Returns:
      the matrix user ID
      Throws:
      org.exoplatform.ws.frameworks.json.impl.JsonException
      IOException
      InterruptedException
    • 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 Matrix
      isNew - boolean if the user is new, then true
      Returns:
      String the matrix user ID
      Throws:
      org.exoplatform.ws.frameworks.json.impl.JsonException
      IOException
      InterruptedException
    • 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.JsonException
      IOException
      InterruptedException
    • 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.JsonException
      IOException
      InterruptedException
    • disableAccount

      public void disableAccount(String matrixUsername) throws org.exoplatform.ws.frameworks.json.impl.JsonException, IOException, InterruptedException
      Throws:
      org.exoplatform.ws.frameworks.json.impl.JsonException
      IOException
      InterruptedException
    • 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.JsonException
      IOException
      InterruptedException
    • 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.JsonException
      IOException
      InterruptedException
    • 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.JsonException
      IOException
      InterruptedException
    • 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.JsonException
      IOException
      InterruptedException
    • 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.JsonException
      IOException
      InterruptedException
    • 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.JsonException
      IOException
      InterruptedException
    • 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.JsonException
      IOException
      InterruptedException
    • createRoom

      public String createRoom(org.exoplatform.social.core.space.model.Space space) throws Exception
      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
    • getAllLinkedRooms

      public long getAllLinkedRooms()
    • getDirectMessagingRoom

      public Room getDirectMessagingRoom(String firstParticipant, String secondParticipant)
    • 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.JsonException
      IOException
      InterruptedException
    • createDirectMessagingRoom

      public Room createDirectMessagingRoom(Room directMessagingRoom) throws org.exoplatform.commons.ObjectAlreadyExistsException
      Throws:
      org.exoplatform.commons.ObjectAlreadyExistsException
    • getMatrixDMRoomsOfUser

      public List<Room> getMatrixDMRoomsOfUser(String user)
    • isUserMemberOfGroup

      public boolean isUserMemberOfGroup(String userName, String groupId) throws Exception
      Throws:
      Exception
    • getSpaceRooms

      public List<Room> getSpaceRooms()
      Returns a list of all space rooms
      Returns:
      List of Space rooms
    • findUserByMatrixId

      public org.exoplatform.social.core.identity.model.Identity findUserByMatrixId(String userIdOnMatrix)
      Searches for a user having the provided Matrix ID
      Parameters:
      userIdOnMatrix - the ID of the user on Matrix
      Returns:
      The identity of the user
    • extractUserId

      public String extractUserId(String fullMatrixUserId)
      Extracts the user ID from the full User Id on Matrix
      Parameters:
      fullMatrixUserId - the full Matrix user Id
      Returns:
      the user Identifier
    • updateUserPresence

      public String updateUserPresence(String userIdOnMatrix, String presence, String statusMessage)
      update the user presence status on Matrix
      Parameters:
      userIdOnMatrix - the user Id on Matrix
      presence - the presence value: online , unavailable, offline
      statusMessage - a personalized status message
    • canAccess

      public boolean canAccess(Room room, String userName)
      Checks if the user able to access the room
      Parameters:
      room - the room
      userName - the username of the user
      Returns:
      true if he has access, false otherwise