MM-32655 - Collapsed threads websocket handling (#16909)

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Eli Yukelzon
2021-03-02 16:49:00 +02:00
коммит произвёл GitHub
родитель 78355ae2a7
Коммит 23d51ed1f2
11 изменённых файлов: 102 добавлений и 63 удалений

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

@@ -2945,13 +2945,13 @@ func updateReadStateThreadByUser(c *Context, w http.ResponseWriter, r *http.Requ
return
}
err := c.App.UpdateThreadReadForUser(c.Params.UserId, c.Params.TeamId, c.Params.ThreadId, c.Params.Timestamp)
thread, err := c.App.UpdateThreadReadForUser(c.Params.UserId, c.Params.TeamId, c.Params.ThreadId, c.Params.Timestamp)
if err != nil {
c.Err = err
return
}
ReturnStatusOK(w)
w.Write([]byte(thread.ToJson()))
auditRec.Success()
}
@@ -2973,7 +2973,7 @@ func unfollowThreadByUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
err := c.App.UpdateThreadFollowForUser(c.Params.UserId, c.Params.ThreadId, false)
err := c.App.UpdateThreadFollowForUser(c.Params.UserId, c.Params.TeamId, c.Params.ThreadId, false)
if err != nil {
c.Err = err
return
@@ -3001,7 +3001,7 @@ func followThreadByUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
err := c.App.UpdateThreadFollowForUser(c.Params.UserId, c.Params.ThreadId, true)
err := c.App.UpdateThreadFollowForUser(c.Params.UserId, c.Params.TeamId, c.Params.ThreadId, true)
if err != nil {
c.Err = err
return

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

@@ -5475,10 +5475,13 @@ func TestThreadSocketEvents(t *testing.T) {
case ev := <-userWSClient.EventChannel:
if ev.EventType() == model.WEBSOCKET_EVENT_THREAD_UPDATED {
caught = true
thread, err := model.ThreadFromJson(ev.GetData()["thread"].(string))
thread, err := model.ThreadResponseFromJson(ev.GetData()["thread"].(string))
require.NoError(t, err)
require.Contains(t, thread.Participants, th.BasicUser.Id)
require.Contains(t, thread.Participants, th.BasicUser2.Id)
for _, p := range thread.Participants {
if p.Id != th.BasicUser.Id && p.Id != th.BasicUser2.Id {
require.Fail(t, "invalid participants")
}
}
}
case <-time.After(1 * time.Second):
return
@@ -5510,7 +5513,7 @@ func TestThreadSocketEvents(t *testing.T) {
require.Truef(t, caught, "User should have received %s event", model.WEBSOCKET_EVENT_THREAD_FOLLOW_CHANGED)
})
resp = th.Client.UpdateThreadReadForUser(th.BasicUser.Id, th.BasicTeam.Id, rpost.Id, 123)
_, resp = th.Client.UpdateThreadReadForUser(th.BasicUser.Id, th.BasicTeam.Id, rpost.Id, 123)
CheckNoError(t, resp)
CheckOKStatus(t, resp)
@@ -5650,7 +5653,7 @@ func TestMaintainUnreadRepliesInThread(t *testing.T) {
checkThreadListReplies(t, th, th.Client, th.BasicUser.Id, 0, 1, nil)
// mark other user's read state
resp = th.SystemAdminClient.UpdateThreadReadForUser(th.SystemAdminUser.Id, th.BasicTeam.Id, rpost.Id, model.GetMillis())
_, resp = th.SystemAdminClient.UpdateThreadReadForUser(th.SystemAdminUser.Id, th.BasicTeam.Id, rpost.Id, model.GetMillis())
CheckNoError(t, resp)
CheckOKStatus(t, resp)
@@ -5658,7 +5661,7 @@ func TestMaintainUnreadRepliesInThread(t *testing.T) {
checkThreadListReplies(t, th, th.SystemAdminClient, th.SystemAdminUser.Id, 0, 0, &model.GetUserThreadsOpts{Unread: true})
// restore unread to an old date
resp = th.SystemAdminClient.UpdateThreadReadForUser(th.SystemAdminUser.Id, th.BasicTeam.Id, rpost.Id, 123)
_, resp = th.SystemAdminClient.UpdateThreadReadForUser(th.SystemAdminUser.Id, th.BasicTeam.Id, rpost.Id, 123)
CheckNoError(t, resp)
CheckOKStatus(t, resp)
@@ -5876,7 +5879,7 @@ func TestReadThreads(t *testing.T) {
uss, _ := checkThreadListReplies(t, th, th.Client, th.BasicUser.Id, 2, 2, nil)
resp := th.Client.UpdateThreadReadForUser(th.BasicUser.Id, th.BasicTeam.Id, rrpost.Id, model.GetMillis()+10)
_, resp := th.Client.UpdateThreadReadForUser(th.BasicUser.Id, th.BasicTeam.Id, rrpost.Id, model.GetMillis()+10)
CheckNoError(t, resp)
CheckOKStatus(t, resp)
@@ -5884,7 +5887,7 @@ func TestReadThreads(t *testing.T) {
require.Greater(t, uss2.Threads[0].LastViewedAt, uss.Threads[0].LastViewedAt)
timestamp := model.GetMillis()
resp = th.Client.UpdateThreadReadForUser(th.BasicUser.Id, th.BasicTeam.Id, rrpost.Id, timestamp)
_, resp = th.Client.UpdateThreadReadForUser(th.BasicUser.Id, th.BasicTeam.Id, rrpost.Id, timestamp)
CheckNoError(t, resp)
CheckOKStatus(t, resp)