MM-56071: Track multiple threads (#25775)

We can have 2 types of threads open at the same time. One from
the thread view, and another from RHS.

We add another variable to distinguish between the 2 states.

In future, if we have the ability for more than 2 threads, then
we would need to track by threadID.

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

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2023-12-21 08:42:58 +05:30
коммит произвёл GitHub
родитель 3f2351c71f
Коммит 7dcf5f85a5
7 изменённых файлов: 48 добавлений и 24 удалений

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

@@ -441,7 +441,12 @@ func TestWebSocketPresence(t *testing.T) {
require.Nil(t, resp.Error)
require.Equal(t, resp.SeqReply, wsClient.Sequence-1, "bad sequence number")
wsClient.UpdateActiveThread("threadID")
wsClient.UpdateActiveThread(true, "threadID")
resp = <-wsClient.ResponseChannel
require.Nil(t, resp.Error)
require.Equal(t, resp.SeqReply, wsClient.Sequence-1, "bad sequence number")
wsClient.UpdateActiveThread(false, "threadID")
resp = <-wsClient.ResponseChannel
require.Nil(t, resp.Error)
require.Equal(t, resp.SeqReply, wsClient.Sequence-1, "bad sequence number")

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

@@ -105,16 +105,17 @@ type WebConn struct {
// a reused connection.
// It's theoretically possible for this number to wrap around. But we
// leave that as an edge-case.
reuseCount int
sessionToken atomic.Value
session atomic.Pointer[model.Session]
connectionID atomic.Value
activeChannelID atomic.Value
activeTeamID atomic.Value
activeThreadChannelID atomic.Value
endWritePump chan struct{}
pumpFinished chan struct{}
pluginPosted chan pluginWSPostedHook
reuseCount int
sessionToken atomic.Value
session atomic.Pointer[model.Session]
connectionID atomic.Value
activeChannelID atomic.Value
activeTeamID atomic.Value
activeRHSThreadChannelID atomic.Value
activeThreadViewThreadChannelID atomic.Value
endWritePump chan struct{}
pumpFinished chan struct{}
pluginPosted chan pluginWSPostedHook
// These counters are to suppress spammy websocket.slow
// and websocket.full logs which happen continuously, if they
@@ -237,7 +238,8 @@ func (ps *PlatformService) NewWebConn(cfg *WebConnConfig, suite SuiteIFace, runn
wc.SetConnectionID(cfg.ConnectionID)
wc.SetActiveChannelID("")
wc.SetActiveTeamID("")
wc.SetActiveThreadChannelID("")
wc.SetActiveRHSThreadChannelID("")
wc.SetActiveThreadViewThreadChannelID("")
ps.Go(func() {
runner.RunMultiHook(func(hooks plugin.Hooks) bool {
@@ -316,14 +318,24 @@ func (wc *WebConn) GetActiveTeamID() string {
return wc.activeTeamID.Load().(string)
}
// GetActiveThreadChannelID returns the channel id of the active thread of the connection.
func (wc *WebConn) GetActiveThreadChannelID() string {
return wc.activeThreadChannelID.Load().(string)
// GetActiveRHSThreadChannelID returns the channel id of the active thread of the connection.
func (wc *WebConn) GetActiveRHSThreadChannelID() string {
return wc.activeRHSThreadChannelID.Load().(string)
}
// SetActiveThreadChannelID sets the channel id of the active thread of the connection.
func (wc *WebConn) SetActiveThreadChannelID(id string) {
wc.activeThreadChannelID.Store(id)
// SetActiveRHSThreadChannelID sets the channel id of the active thread of the connection.
func (wc *WebConn) SetActiveRHSThreadChannelID(id string) {
wc.activeRHSThreadChannelID.Store(id)
}
// GetActiveThreadViewThreadChannelID returns the channel id of the active thread of the connection.
func (wc *WebConn) GetActiveThreadViewThreadChannelID() string {
return wc.activeThreadViewThreadChannelID.Load().(string)
}
// SetActiveThreadViewThreadChannelID sets the channel id of the active thread of the connection.
func (wc *WebConn) SetActiveThreadViewThreadChannelID(id string) {
wc.activeThreadViewThreadChannelID.Store(id)
}
// areAllInactive returns whether all of the connections

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

@@ -84,7 +84,11 @@ func (wr *WebSocketRouter) ServeWebSocket(conn *WebConn, r *model.WebSocketReque
}
if thChannelID, ok := r.Data["thread_channel_id"].(string); ok {
// Set the channelID of the active thread.
conn.SetActiveThreadChannelID(thChannelID)
if isThreadView, ok := r.Data["is_thread_view"].(bool); ok && isThreadView {
conn.SetActiveThreadViewThreadChannelID(thChannelID)
} else {
conn.SetActiveRHSThreadChannelID(thChannelID)
}
}
resp := model.NewWebSocketResponse(model.StatusOk, r.Seq, nil)