MM-36054: send reply_count with following ws event (#17683)

* send reply_count with following ws event

* add test

* code suggestion
This commit is contained in:
Caleb Roseland
2021-06-09 12:37:25 -05:00
committed by GitHub
parent fe94a20ce7
commit 364ea5ed63
2 changed files with 7 additions and 0 deletions

View File

@@ -5671,6 +5671,7 @@ func TestThreadSocketEvents(t *testing.T) {
if ev.EventType() == model.WEBSOCKET_EVENT_THREAD_FOLLOW_CHANGED {
caught = true
require.Equal(t, ev.GetData()["state"], false)
require.Equal(t, ev.GetData()["reply_count"], float64(1))
}
case <-time.After(1 * time.Second):
return

View File

@@ -2351,12 +2351,18 @@ func (a *App) UpdateThreadsReadForUser(userID, teamID string) *model.AppError {
func (a *App) UpdateThreadFollowForUser(userID, teamID, threadID string, state bool) *model.AppError {
_, err := a.Srv().Store.Thread().MaintainMembership(userID, threadID, state, false, true, state, false)
if err != nil {
return model.NewAppError("UpdateThreadFollowForUser", "app.user.update_thread_follow_for_user.app_error", nil, err.Error(), http.StatusInternalServerError)
}
thread, err := a.Srv().Store.Thread().Get(threadID)
if err != nil {
return model.NewAppError("UpdateThreadFollowForUser", "app.user.update_thread_follow_for_user.app_error", nil, err.Error(), http.StatusInternalServerError)
}
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_THREAD_FOLLOW_CHANGED, teamID, "", userID, nil)
message.Add("thread_id", threadID)
message.Add("state", state)
message.Add("reply_count", thread.ReplyCount)
a.Publish(message)
return nil
}