MM-32027 - Marking a thread as unread not possible or marks all threads as unread. (#16757)
* mark thread as read query fix * test fix * lint
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
28c3809036
Коммит
c2316c15f3
@@ -5735,9 +5735,14 @@ func TestMaintainUnreadMentionsInThread(t *testing.T) {
|
|||||||
func TestReadThreads(t *testing.T) {
|
func TestReadThreads(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
os.Setenv("MM_FEATUREFLAGS_COLLAPSEDTHREADS", "true")
|
||||||
|
defer os.Unsetenv("MM_FEATUREFLAGS_COLLAPSEDTHREADS")
|
||||||
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.ServiceSettings.ThreadAutoFollow = true
|
||||||
|
*cfg.ServiceSettings.CollapsedThreads = model.COLLAPSED_THREADS_DEFAULT_ON
|
||||||
|
})
|
||||||
|
Client := th.Client
|
||||||
t.Run("all threads", func(t *testing.T) {
|
t.Run("all threads", func(t *testing.T) {
|
||||||
Client := th.Client
|
|
||||||
|
|
||||||
rpost, resp := Client.CreatePost(&model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
|
rpost, resp := Client.CreatePost(&model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
@@ -5772,58 +5777,31 @@ func TestReadThreads(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("1 thread", func(t *testing.T) {
|
t.Run("1 thread", func(t *testing.T) {
|
||||||
Client := th.Client
|
|
||||||
|
|
||||||
rpost, resp := Client.CreatePost(&model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
|
|
||||||
CheckNoError(t, resp)
|
|
||||||
CheckCreatedStatus(t, resp)
|
|
||||||
_, resp2 := Client.CreatePost(&model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply", RootId: rpost.Id})
|
|
||||||
CheckNoError(t, resp2)
|
|
||||||
CheckCreatedStatus(t, resp2)
|
|
||||||
|
|
||||||
rrpost, rresp := Client.CreatePost(&model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
|
|
||||||
CheckNoError(t, rresp)
|
|
||||||
CheckCreatedStatus(t, rresp)
|
|
||||||
_, rresp2 := Client.CreatePost(&model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply", RootId: rrpost.Id})
|
|
||||||
CheckNoError(t, rresp2)
|
|
||||||
CheckCreatedStatus(t, rresp2)
|
|
||||||
|
|
||||||
defer th.App.Srv().Store.Post().PermanentDeleteByUser(th.BasicUser.Id)
|
defer th.App.Srv().Store.Post().PermanentDeleteByUser(th.BasicUser.Id)
|
||||||
|
defer th.App.Srv().Store.Post().PermanentDeleteByUser(th.SystemAdminUser.Id)
|
||||||
|
|
||||||
var uss, uss2, uss3 *model.Threads
|
rpost, _ := postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
|
||||||
uss, resp = th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply", RootId: rpost.Id})
|
||||||
Page: 0,
|
|
||||||
PageSize: 30,
|
|
||||||
Deleted: false,
|
|
||||||
})
|
|
||||||
CheckNoError(t, resp)
|
|
||||||
require.Len(t, uss.Threads, 2)
|
|
||||||
|
|
||||||
resp = th.Client.UpdateThreadReadForUser(th.BasicUser.Id, th.BasicTeam.Id, rrpost.Id, model.GetMillis())
|
rrpost, _ := postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel2.Id, Message: "testMsg"})
|
||||||
|
postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: th.BasicChannel2.Id, Message: "testReply", RootId: rrpost.Id})
|
||||||
|
|
||||||
|
uss, _ := checkThreadListReplies(t, th, th.Client, th.BasicUser.Id, 2, 2, nil)
|
||||||
|
|
||||||
|
time.Sleep(1)
|
||||||
|
resp := th.Client.UpdateThreadReadForUser(th.BasicUser.Id, th.BasicTeam.Id, rrpost.Id, model.GetMillis())
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
CheckOKStatus(t, resp)
|
CheckOKStatus(t, resp)
|
||||||
|
|
||||||
uss2, resp = th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
uss2, _ := checkThreadListReplies(t, th, th.Client, th.BasicUser.Id, 1, 2, nil)
|
||||||
Page: 0,
|
require.Greater(t, uss2.Threads[0].LastViewedAt, uss.Threads[0].LastViewedAt)
|
||||||
PageSize: 30,
|
|
||||||
Deleted: false,
|
|
||||||
})
|
|
||||||
CheckNoError(t, resp)
|
|
||||||
require.Len(t, uss2.Threads, 2)
|
|
||||||
require.Greater(t, uss2.Threads[1].LastViewedAt, uss.Threads[1].LastViewedAt)
|
|
||||||
|
|
||||||
timestamp := model.GetMillis()
|
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)
|
CheckNoError(t, resp)
|
||||||
CheckOKStatus(t, resp)
|
CheckOKStatus(t, resp)
|
||||||
|
|
||||||
uss3, resp = th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
uss3, _ := checkThreadListReplies(t, th, th.Client, th.BasicUser.Id, 1, 2, nil)
|
||||||
Page: 0,
|
require.Equal(t, uss3.Threads[0].LastViewedAt, timestamp)
|
||||||
PageSize: 30,
|
|
||||||
Deleted: false,
|
|
||||||
})
|
|
||||||
CheckNoError(t, resp)
|
|
||||||
require.Len(t, uss3.Threads, 2)
|
|
||||||
require.Equal(t, uss3.Threads[1].LastViewedAt, timestamp)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -310,7 +310,8 @@ func (s *SqlThreadStore) MarkAllAsRead(userId, teamId string) error {
|
|||||||
func (s *SqlThreadStore) MarkAsRead(userId, threadId string, timestamp int64) error {
|
func (s *SqlThreadStore) MarkAsRead(userId, threadId string, timestamp int64) error {
|
||||||
query, args, _ := s.getQueryBuilder().
|
query, args, _ := s.getQueryBuilder().
|
||||||
Update("ThreadMemberships").
|
Update("ThreadMemberships").
|
||||||
Where(sq.Eq{"UserId": userId}, sq.Eq{"PostId": threadId}).
|
Where(sq.Eq{"UserId": userId}).
|
||||||
|
Where(sq.Eq{"PostId": threadId}).
|
||||||
Set("LastViewed", timestamp).
|
Set("LastViewed", timestamp).
|
||||||
ToSql()
|
ToSql()
|
||||||
if _, err := s.GetMaster().Exec(query, args...); err != nil {
|
if _, err := s.GetMaster().Exec(query, args...); err != nil {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user