From 90884172ae6920a5843694efe40b5101680585be Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Wed, 7 Aug 2024 07:29:36 -0400 Subject: [PATCH] [MM-59911] Force individual users to receive the `user_added` and `group_added` events instead of relying on the channel membership (#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 --- server/channels/app/channel.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/server/channels/app/channel.go b/server/channels/app/channel.go index 05aa3f4fa3f..338c42b3604 100644 --- a/server/channels/app/channel.go +++ b/server/channels/app/channel.go @@ -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 } @@ -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 }