Commit cc3a95fd authored by Nick Frazier's avatar Nick Frazier Committed by Joram Wilander

Added websocket event and webapp handler for updating user roles (#6953)

parent ac5dd4aa
......@@ -164,9 +164,18 @@ func UpdateTeamMemberRoles(teamId string, userId string, newRoles string) (*mode
ClearSessionCacheForUser(userId)
sendUpdatedMemberRoleEvent(userId, member)
return member, nil
}
func sendUpdatedMemberRoleEvent(userId string, member *model.TeamMember) {
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_MEMBERROLE_UPDATED, "", "", userId, nil)
message.Add("member", member.ToJson())
go Publish(message)
}
func AddUserToTeam(teamId string, userId string, userRequestorId string) (*model.Team, *model.AppError) {
tchan := Srv.Store.Team().Get(teamId)
uchan := Srv.Store.User().Get(userId)
......
......@@ -24,6 +24,7 @@ const (
WEBSOCKET_EVENT_UPDATE_TEAM = "update_team"
WEBSOCKET_EVENT_USER_ADDED = "user_added"
WEBSOCKET_EVENT_USER_UPDATED = "user_updated"
WEBSOCKET_EVENT_MEMBERROLE_UPDATED = "memberrole_updated"
WEBSOCKET_EVENT_USER_REMOVED = "user_removed"
WEBSOCKET_EVENT_PREFERENCE_CHANGED = "preference_changed"
WEBSOCKET_EVENT_PREFERENCES_CHANGED = "preferences_changed"
......
......@@ -170,6 +170,10 @@ function handleEvent(msg) {
handleUserUpdatedEvent(msg);
break;
case SocketEvents.MEMBERROLE_UPDATED:
handleUpdateMemberRoleEvent(msg);
break;
case SocketEvents.CHANNEL_CREATED:
handleChannelCreatedEvent(msg);
break;
......@@ -321,6 +325,11 @@ function handleUpdateTeamEvent(msg) {
TeamStore.updateTeam(msg.data.team);
}
function handleUpdateMemberRoleEvent(msg) {
const member = JSON.parse(msg.data.member);
TeamStore.updateMyRoles(member);
}
function handleDirectAddedEvent(msg) {
getChannelAndMyMember(msg.broadcast.channel_id)(dispatch, getState);
PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, msg.data.teammate_id, 'true');
......
......@@ -341,6 +341,22 @@ class TeamStoreClass extends EventEmitter {
return false;
}
updateMyRoles(member) {
const teamMembers = this.getMyTeamMembers();
const teamMember = teamMembers.find((m) => m.user_id === member.user_id && m.team_id === member.team_id);
if (teamMember) {
const newMember = Object.assign({}, teamMember, {
roles: member.roles
});
store.dispatch({
type: TeamTypes.RECEIVED_MY_TEAM_MEMBER,
data: newMember
});
}
}
subtractUnread(teamId, msgs, mentions) {
let member = this.getMyTeamMembers().filter((m) => m.team_id === teamId)[0];
if (member) {
......
......@@ -233,6 +233,7 @@ export const SocketEvents = {
USER_ADDED: 'user_added',
USER_REMOVED: 'user_removed',
USER_UPDATED: 'user_updated',
MEMBERROLE_UPDATED: 'memberrole_updated',
TYPING: 'typing',
PREFERENCE_CHANGED: 'preference_changed',
PREFERENCES_CHANGED: 'preferences_changed',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment