MM-56060: Create base scaffolding for websocket pub-sub (#25654)

We create a new websocket action called "presence" which
can contain the active_channel and the active_team for a given
client connection.

On the client side, for every channel or team switch, we send
out this message.

https://mattermost.atlassian.net/browse/MM-56060

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2023-12-12 08:49:09 +05:30
коммит произвёл GitHub
родитель f35b0a3781
Коммит e0b5b951f1
9 изменённых файлов: 120 добавлений и 9 удалений

Просмотреть файл

@@ -73,6 +73,25 @@ func (wr *WebSocketRouter) ServeWebSocket(conn *WebConn, r *model.WebSocketReque
return
}
if r.Action == string(model.WebsocketPresenceIndicator) {
if chID, ok := r.Data["channel_id"].(string); ok {
// Set active channel
conn.SetActiveChannelID(chID)
}
if teamID, ok := r.Data["team_id"].(string); ok {
// Set active team
conn.SetActiveTeamID(teamID)
}
resp := model.NewWebSocketResponse(model.StatusOk, r.Seq, nil)
hub := conn.Platform.GetHubForUserId(conn.UserId)
if hub == nil {
return
}
hub.SendMessage(conn, resp)
return
}
if !conn.IsAuthenticated() {
err := model.NewAppError("ServeWebSocket", "api.web_socket_router.not_authenticated.app_error", nil, "", http.StatusUnauthorized)
returnWebSocketError(conn.Platform, conn, r, err)