Class ChatHelper
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.workspaces.chat.ChatHelper
- All Implemented Interfaces:
LogEnabled
,Component
,Contextualizable
,Serviceable
public class ChatHelper
extends AbstractLogEnabled
implements Component, Serviceable, Contextualizable
Helper for chat
-
Field Summary
Modifier and TypeFieldDescriptionprotected CryptoHelper
Cryptographyprotected CurrentUserProvider
Current user providerprotected JSONUtils
JSON Utilsprotected UserManager
User Managerprotected UserPreferencesManager
User Preferencesstatic final String
The Avalon role -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
_isOperationSuccessful
(Map<String, Object> result) Read the JSON result to test for successvoid
addUserToRoom
(UserIdentity userIdentity, String roomName) Adds a user to the private group.void
contextualize
(Context context) void
deleteRoom
(String roomName) Remove a private group.Creates a new private group.getUser
(UserIdentity userIdentity, boolean create) Get (or create) a new user.Login the current user to the given roomvoid
removeAllUsersFromRoom
(String roomName, List<UserIdentity> except) Remove all existing userboolean
removeUserFromRoom
(UserIdentity user, String roomName) Removes a user from the private group.void
service
(ServiceManager manager) void
updateUserInfos
(UserIdentity userIdentity, boolean changePassword) Update user name, email, avatar...static String
userIdentitytoUserName
(UserIdentity userIdentity) Convert a useridentity to a chat server usernameMethods 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
-
ChatHelper
public ChatHelper()
-
-
Method Details
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
getRoom
Creates a new private group. If the group already exists the operation will succeed.- Parameters:
roomName
- name of the groupcreate
- Create if necessary- Returns:
- The group info. Can be null if no creation allowed
- Throws:
IOException
- something went wrong
-
deleteRoom
Remove a private group. If the group does not exist the operation will succeed.- Parameters:
roomName
- name of the group- Throws:
IOException
- something went wrong
-
getUser
public Map<String,Object> getUser(UserIdentity userIdentity, boolean create) throws IOException, UserPreferencesException Get (or create) a new user.- Parameters:
userIdentity
- the user that will be mirrored into chatcreate
- Create if missing- 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 preferences
-
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
-
addUserToRoom
public void addUserToRoom(UserIdentity userIdentity, String roomName) throws IOException, UserPreferencesException Adds a user to the private group.- Parameters:
userIdentity
- user to inviteroomName
- name of the group where to invite the user- Throws:
IOException
- something went wrongUserPreferencesException
- If the user need to be created and its password cannot be stored
-
removeAllUsersFromRoom
Remove all existing user- Parameters:
roomName
- The room nameexcept
- Do not remove these users- Throws:
IOException
- If an error occurred
-
removeUserFromRoom
public boolean removeUserFromRoom(UserIdentity user, String roomName) throws IOException, UserPreferencesException Removes a user from the private group.- Parameters:
user
- user to kickroomName
- name of the group from where to kick the user- Returns:
- true if success
- Throws:
IOException
- something went wrongUserPreferencesException
- If an error occurred with user password
-
userIdentitytoUserName
Convert a useridentity to a chat server username- Parameters:
userIdentity
- The user to convert- Returns:
- the chat username
-
_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(String roomName) throws IOException, UserPreferencesException, InterruptedException Login the current user to the given room- Parameters:
roomName
- The room to log in- 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
-