Skip to content

Commit

Permalink
[MM-59911] Force individual users to receive the user_added and `gr…
Browse files Browse the repository at this point in the history
…oup_added` events instead of relying on the channel membership (mattermost#27846)

* [MM-59911] Force individual users to receive the `user_added` and `group_added` events instead of relying on the channel membership

* Fix redundant JSON serializing
  • Loading branch information
devinbinnie authored Aug 7, 2024
1 parent 5011d45 commit 9088417
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions server/channels/app/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,14 @@ func (a *App) CreateGroupChannel(c request.CTX, userIDs []string, creatorId stri
return nil, err
}

jsonIDs := model.ArrayToJSON(userIDs)
for _, userID := range userIDs {
a.InvalidateCacheForUser(userID)
}

message := model.NewWebSocketEvent(model.WebsocketEventGroupAdded, "", channel.Id, "", nil, "")
message.Add("teammate_ids", model.ArrayToJSON(userIDs))
a.Publish(message)
message := model.NewWebSocketEvent(model.WebsocketEventGroupAdded, "", channel.Id, userID, nil, "")
message.Add("teammate_ids", jsonIDs)
a.Publish(message)
}

return channel, nil
}
Expand Down Expand Up @@ -1597,11 +1598,18 @@ func (a *App) AddUserToChannel(c request.CTX, user *model.User, channel *model.C
return nil, err
}

message := model.NewWebSocketEvent(model.WebsocketEventUserAdded, "", channel.Id, "", nil, "")
// We are sending separate websocket events to the user added and to the channel
// This is to get around potential cluster syncing issues where other nodes may not receive the most up to date channel members
message := model.NewWebSocketEvent(model.WebsocketEventUserAdded, "", channel.Id, "", map[string]bool{user.Id: true}, "")
message.Add("user_id", user.Id)
message.Add("team_id", channel.TeamId)
a.Publish(message)

userMessage := model.NewWebSocketEvent(model.WebsocketEventUserAdded, "", channel.Id, user.Id, nil, "")
userMessage.Add("user_id", user.Id)
userMessage.Add("team_id", channel.TeamId)
a.Publish(userMessage)

return newMember, nil
}

Expand Down

0 comments on commit 9088417

Please sign in to comment.