mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user