From 364ea5ed63e3ccb8c953a849b4c52773bc9ffa08 Mon Sep 17 00:00:00 2001 From: Caleb Roseland Date: Wed, 9 Jun 2021 12:37:25 -0500 Subject: [PATCH] MM-36054: send reply_count with following ws event (#17683) * send reply_count with following ws event * add test * code suggestion --- api4/user_test.go | 1 + app/user.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/api4/user_test.go b/api4/user_test.go index ee480bf48b..cdd6a733c2 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -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 diff --git a/app/user.go b/app/user.go index 131343e8ad..02d5c1407c 100644 --- a/app/user.go +++ b/app/user.go @@ -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 }