MM-34872 CRT: thread last_viewed_at updated when channel is viewed (#17448)

Этот коммит содержится в:
Eli Yukelzon
2021-04-21 09:48:59 +03:00
коммит произвёл GitHub
родитель 56198a99c6
Коммит dd9a1918e1
3 изменённых файлов: 37 добавлений и 2 удалений

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

@@ -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 {

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

@@ -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)

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

@@ -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()