Package org.ametys.plugins.rocket.chat
Class RocketChatHelper
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.rocket.chat.RocketChatHelper
- All Implemented Interfaces:
LogEnabled
,Initializable
,Component
,Contextualizable
,Serviceable
public class RocketChatHelper
extends AbstractLogEnabled
implements Component, Serviceable, Contextualizable, Initializable
Helper for the rocket.chat link
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
A Rocket.Chat messagestatic final record
A Rocket.Chat room info for a user -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CryptoHelper
Cryptographyprotected CurrentUserProvider
Current user providerprotected JSONUtils
JSON Utilsprotected UserManager
User Managerprotected UserPreferencesManager
User Preferencesstatic final String
The Avalon role -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Creates the cachesprotected boolean
_isOperationSuccessful
(Map<String, Object> result) Read the JSON result to test for successvoid
contextualize
(Context context) createChat
(List<String> users) Creates a new chat with the current user and the given usersgetAmetysUserInfo
(User user, boolean externalUrl, int imageSize) Get the user infoGet the last messages of the current usergetLastMessages
(UserIdentity user, String roomId, int count, ZonedDateTime since) Get the n last messages of the user in the roomGet the current cache statusgetThreadsWithUnreadMessages
(UserIdentity user, ZonedDateTime since) List the unread messages of a user in the given time windowgetUser
(UserIdentity userIdentity, boolean updateIfNotNew) Get (or create) a new user.List all the users with messages in the given time windowvoid
login()
Login the current uservoid
service
(ServiceManager manager) void
Set the current user new statusvoid
updateUserInfos
(UserIdentity userIdentity, boolean changePassword) Update user name, email, avatar...Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
The Avalon role -
_jsonUtils
JSON Utils -
_userManager
User Manager -
_userPreferencesManager
User Preferences -
_cryptoHelper
Cryptography -
_currentUserProvider
Current user provider
-
-
Constructor Details
-
RocketChatHelper
public RocketChatHelper()
-
-
Method Details
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
_createCaches
Creates the caches -
getUser
public Map<String,Object> getUser(UserIdentity userIdentity, boolean updateIfNotNew) throws IOException, UserPreferencesException, InterruptedException Get (or create) a new user.- Parameters:
userIdentity
- the user that will be mirrored into chatupdateIfNotNew
- If the user was already existing, should it be updated (except password)?- Returns:
- the user info or null if user does not exist in chat and create was not required
- Throws:
IOException
- something went wrongUserPreferencesException
- error while reading the user preferencesInterruptedException
- error while reading the user preferences
-
getAmetysUserInfo
Get the user info- Parameters:
user
- The userexternalUrl
- Is the image url external?imageSize
- The size of the avatar- Returns:
- The name, email and avatar
-
updateUserInfos
public void updateUserInfos(UserIdentity userIdentity, boolean changePassword) throws IOException, UserPreferencesException, InterruptedException Update user name, email, avatar... on chat server- Parameters:
userIdentity
- The user to updatechangePassword
- Update the user password (slow)- Throws:
UserPreferencesException
- If an error occurred while getting user infosIOException
- If an error occurred while updatingInterruptedException
- If an error occurred while updating
-
_isOperationSuccessful
Read the JSON result to test for success- Parameters:
result
- the JSON result of a rest call- Returns:
- true if success
-
login
public Map<String,Object> login() throws IOException, UserPreferencesException, InterruptedExceptionLogin the current user- Returns:
- The info about the user
- Throws:
UserPreferencesException
- If the user password stored in prefs has an issueIOException
- If an error occurredInterruptedException
- If an error occurred
-
getStatusCache
public Map<String,String> getStatusCache() throws UserPreferencesException, IOException, InterruptedExceptionGet the current cache status- Returns:
- The association login#populationId <-> status (online, offline...)
- Throws:
InterruptedException
- If an error occurredIOException
- If an error occurredUserPreferencesException
- If an error occurred
-
setStatus
public void setStatus(String newStatus) throws UserPreferencesException, IOException, InterruptedException Set the current user new status- Parameters:
newStatus
- The new status between online, offline, busy or away- Throws:
InterruptedException
- If an error occurredIOException
- If an error occurredUserPreferencesException
- If an error occurred
-
getLastMessages
public Collection<Map<String,Object>> getLastMessages() throws IOException, UserPreferencesException, InterruptedExceptionGet the last messages of the current user- Returns:
- The messages
- Throws:
IOException
- something went wrongUserPreferencesException
- something went wrongInterruptedException
- something went wrong
-
createChat
public String createChat(List<String> users) throws UserPreferencesException, IOException, InterruptedException Creates a new chat with the current user and the given users- Parameters:
users
- The parteners- Returns:
- The chat id
- Throws:
InterruptedException
- If an error occurredIOException
- If an error occurredUserPreferencesException
- If an error occurred
-
getUsersWithRecentMessages
List all the users with messages in the given time window- Parameters:
since
- The date since the messages should be considered- Returns:
- The list of users
- Throws:
IOException
- If an error occurred
-
getThreadsWithUnreadMessages
public Set<RocketChatHelper.RoomInfo> getThreadsWithUnreadMessages(UserIdentity user, ZonedDateTime since) throws IOException, UserPreferencesException, InterruptedException List the unread messages of a user in the given time window- Parameters:
user
- The user to considersince
- The date to consider- Returns:
- The ids of the room containing unread messages
- Throws:
IOException
- If an error occurredUserPreferencesException
- If an error occurredInterruptedException
- If an error occurred
-
getLastMessages
public List<RocketChatHelper.Message> getLastMessages(UserIdentity user, String roomId, int count, ZonedDateTime since) throws IOException, UserPreferencesException, InterruptedException Get the n last messages of the user in the room- Parameters:
user
- The user to considerroomId
- The room id to considercount
- The number of messages to retrievesince
- Since the max date- Returns:
- The message
- Throws:
IOException
- If an error occurredUserPreferencesException
- If an error occurredInterruptedException
- If an error occurred
-