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
Fields Modifier and Type Field Description protected CryptoHelper_cryptoHelperCryptographyprotected CurrentUserProvider_currentUserProviderCurrent user providerprotected JSONUtils_jsonUtilsJSON Utilsprotected UserManager_userManagerUser Managerprotected UserPreferencesManager_userPreferencesManagerUser Preferencesstatic StringROLEThe Avalon role
-
Constructor Summary
Constructors Constructor Description ChatHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean_isOperationSuccessful(Map<String,Object> result)Read the JSON result to test for successvoidaddUserToRoom(UserIdentity userIdentity, String roomName)Adds a user to the private group.voidcontextualize(Context context)voiddeleteRoom(String roomName)Remove a private group.Map<String,Object>getRoom(String roomName, boolean create)Creates a new private group.Map<String,Object>getUser(UserIdentity userIdentity, boolean create)Get (or create) a new user.Map<String,Object>login(String roomName)Login the current user to the given roomvoidremoveAllUsersFromRoom(String roomName, List<UserIdentity> except)Remove all existing userbooleanremoveUserFromRoom(UserIdentity user, String roomName)Removes a user from the private group.voidservice(ServiceManager manager)voidupdateUserInfos(UserIdentity userIdentity, boolean changePassword)Update user name, email, avatar...static StringuserIdentitytoUserName(UserIdentity userIdentity)Convert a useridentity to a chat server username-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
_jsonUtils
protected JSONUtils _jsonUtils
JSON Utils
-
_userManager
protected UserManager _userManager
User Manager
-
_userPreferencesManager
protected UserPreferencesManager _userPreferencesManager
User Preferences
-
_cryptoHelper
protected CryptoHelper _cryptoHelper
Cryptography
-
_currentUserProvider
protected CurrentUserProvider _currentUserProvider
Current user provider
-
-
Constructor Detail
-
ChatHelper
public ChatHelper()
-
-
Method Detail
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualizein interfaceContextualizable- Throws:
ContextException
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
getRoom
public Map<String,Object> getRoom(String roomName, boolean create) throws IOException
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
public void deleteRoom(String roomName) throws IOException
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
public void removeAllUsersFromRoom(String roomName, List<UserIdentity> except) throws IOException
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
public static String userIdentitytoUserName(UserIdentity userIdentity)
Convert a useridentity to a chat server username- Parameters:
userIdentity- The user to convert- Returns:
- the chat username
-
_isOperationSuccessful
protected boolean _isOperationSuccessful(Map<String,Object> result)
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
-
-