diff --git a/app/channel.go b/app/channel.go index 221299eb12..483305c6b0 100644 --- a/app/channel.go +++ b/app/channel.go @@ -2596,7 +2596,7 @@ func (a *App) MarkChannelsAsViewed(channelIDs []string, userID string, currentSe } } } - times, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIDs, userID, *a.Config().ServiceSettings.ThreadAutoFollow) + times, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIDs, userID, false) if err != nil { var invErr *store.ErrInvalidInput switch { diff --git a/app/channel_test.go b/app/channel_test.go index 2b791437b9..fd3f55e30b 100644 --- a/app/channel_test.go +++ b/app/channel_test.go @@ -1965,7 +1965,7 @@ func TestMarkChannelsAsViewedPanic(t *testing.T) { times := map[string]int64{ "userID": 1, } - mockChannelStore.On("UpdateLastViewedAt", []string{"channelID"}, "userID", true).Return(times, nil) + mockChannelStore.On("UpdateLastViewedAt", []string{"channelID"}, "userID", false).Return(times, nil) mockStore.On("User").Return(&mockUserStore) mockStore.On("Channel").Return(&mockChannelStore) diff --git a/app/post_test.go b/app/post_test.go index f838d1deb6..1e01825dcd 100644 --- a/app/post_test.go +++ b/app/post_test.go @@ -2006,6 +2006,41 @@ func TestAutofollowBasedOnRootPost(t *testing.T) { require.Len(t, m, 1) } +func TestViewChannelShouldNotUpdateThreads(t *testing.T) { + th := Setup(t).InitBasic() + 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 + }) + + channel := th.BasicChannel + user := th.BasicUser + user2 := th.BasicUser2 + appErr := th.App.JoinChannel(channel, user.Id) + require.Nil(t, appErr) + appErr = th.App.JoinChannel(channel, user2.Id) + require.Nil(t, appErr) + p1, err := th.App.CreatePost(&model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, false, false) + require.Nil(t, err) + _, err2 := th.App.CreatePost(&model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, false, false) + require.Nil(t, err2) + m, e := th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id) + require.NoError(t, e) + + th.App.ViewChannel(&model.ChannelView{ + ChannelId: channel.Id, + PrevChannelId: "", + }, user2.Id, "") + + m1, e1 := th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id) + require.NoError(t, e1) + require.Equal(t, m[0].LastViewed, m1[0].LastViewed) // opening the channel shouldn't update threads +} + func TestCollapsedThreadFetch(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown()