diff --git a/server/channels/app/app_iface.go b/server/channels/app/app_iface.go index 41d11ac2ca..ea5f74426f 100644 --- a/server/channels/app/app_iface.go +++ b/server/channels/app/app_iface.go @@ -921,7 +921,7 @@ type AppIface interface { Log() *mlog.Logger LoginByOAuth(c *request.Context, service string, userData io.Reader, teamID string, tokenUser *model.User) (*model.User, *model.AppError) MakePermissionError(s *model.Session, permissions []*model.Permission) *model.AppError - MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError) + MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported, isCRTEnabled bool) (map[string]int64, *model.AppError) MaxPostSize() int MessageExport() einterfaces.MessageExportInterface Metrics() einterfaces.MetricsInterface diff --git a/server/channels/app/channel.go b/server/channels/app/channel.go index f9c0879d28..059c55fc9d 100644 --- a/server/channels/app/channel.go +++ b/server/channels/app/channel.go @@ -2953,7 +2953,7 @@ func (a *App) SearchChannelsUserNotIn(c request.CTX, teamID string, userID strin return channelList, nil } -func (a *App) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError) { +func (a *App) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported, isCRTEnabled bool) (map[string]int64, *model.AppError) { // I start looking for channels with notifications before I mark it as read, to clear the push notifications if needed channelsToClearPushNotifications := []string{} if a.canSendPushNotifications() { @@ -2996,7 +2996,7 @@ func (a *App) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID st } var err error - updateThreads := *a.Config().ServiceSettings.ThreadAutoFollow && (!collapsedThreadsSupported || !a.IsCRTEnabledForUser(c, userID)) + updateThreads := *a.Config().ServiceSettings.ThreadAutoFollow && (!collapsedThreadsSupported || !isCRTEnabled) if updateThreads { err = a.Srv().Store().Thread().MarkAllAsReadByChannels(userID, channelIDs) if err != nil { @@ -3026,7 +3026,7 @@ func (a *App) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID st a.clearPushNotification(currentSessionId, userID, channelID, "") } - if updateThreads && a.IsCRTEnabledForUser(c, userID) { + if updateThreads && isCRTEnabled { timestamp := model.GetMillis() for _, channelID := range channelIDs { message := model.NewWebSocketEvent(model.WebsocketEventThreadReadChanged, "", channelID, userID, nil, "") @@ -3057,7 +3057,7 @@ func (a *App) ViewChannel(c request.CTX, view *model.ChannelView, userID string, return map[string]int64{}, nil } - return a.MarkChannelsAsViewed(c, channelIDs, userID, currentSessionId, collapsedThreadsSupported) + return a.MarkChannelsAsViewed(c, channelIDs, userID, currentSessionId, collapsedThreadsSupported, a.IsCRTEnabledForUser(c, userID)) } func (a *App) PermanentDeleteChannel(c request.CTX, channel *model.Channel) *model.AppError { diff --git a/server/channels/app/channel_test.go b/server/channels/app/channel_test.go index 4968717c4c..711476f9ea 100644 --- a/server/channels/app/channel_test.go +++ b/server/channels/app/channel_test.go @@ -1422,9 +1422,9 @@ func TestMarkChannelAsUnreadFromPost(t *testing.T) { unread, err = th.App.GetChannelUnread(th.Context, c1.Id, u2.Id) require.Nil(t, err) require.Equal(t, int64(4), unread.MsgCount) - _, err = th.App.MarkChannelsAsViewed(th.Context, []string{c1.Id, pc1.Id}, u1.Id, "", false) + _, err = th.App.MarkChannelsAsViewed(th.Context, []string{c1.Id, pc1.Id}, u1.Id, "", false, false) require.Nil(t, err) - _, err = th.App.MarkChannelsAsViewed(th.Context, []string{c1.Id, pc1.Id}, u2.Id, "", false) + _, err = th.App.MarkChannelsAsViewed(th.Context, []string{c1.Id, pc1.Id}, u2.Id, "", false, false) require.Nil(t, err) unread, err = th.App.GetChannelUnread(th.Context, c1.Id, u2.Id) require.Nil(t, err) @@ -2146,7 +2146,7 @@ func TestMarkChannelsAsViewedPanic(t *testing.T) { mockThreadStore.On("MarkAllAsReadByChannels", "userID", []string{"channelID"}).Return(nil) mockStore.On("Thread").Return(&mockThreadStore) - _, appErr := th.App.MarkChannelsAsViewed(th.Context, []string{"channelID"}, "userID", th.Context.Session().Id, false) + _, appErr := th.App.MarkChannelsAsViewed(th.Context, []string{"channelID"}, "userID", th.Context.Session().Id, false, false) require.Nil(t, appErr) } @@ -2256,7 +2256,7 @@ func TestViewChannelCollapsedThreadsTurnedOff(t *testing.T) { require.Truef(t, found, "did not find created thread in user's threads") // Mark channel as read from a client that supports CRT - _, appErr = th.App.MarkChannelsAsViewed(th.Context, []string{c1.Id}, u1.Id, th.Context.Session().Id, true) + _, appErr = th.App.MarkChannelsAsViewed(th.Context, []string{c1.Id}, u1.Id, th.Context.Session().Id, true, th.App.IsCRTEnabledForUser(th.Context, u1.Id)) require.Nil(t, appErr) // Thread should be marked as read because CRT has been turned off by user diff --git a/server/channels/app/export_test.go b/server/channels/app/export_test.go index d82c95e563..801fc423a9 100644 --- a/server/channels/app/export_test.go +++ b/server/channels/app/export_test.go @@ -93,7 +93,7 @@ func TestExportUserChannels(t *testing.T) { Value: "true", } - _, appErr := th.App.MarkChannelsAsViewed(th.Context, []string{th.BasicPost.ChannelId}, user.Id, "", true) + _, appErr := th.App.MarkChannelsAsViewed(th.Context, []string{th.BasicPost.ChannelId}, user.Id, "", true, th.App.IsCRTEnabledForUser(th.Context, user.Id)) require.Nil(t, appErr) var preferences model.Preferences diff --git a/server/channels/app/opentracing/opentracing_layer.go b/server/channels/app/opentracing/opentracing_layer.go index 2e9fdf4d1c..a9f6b929e0 100644 --- a/server/channels/app/opentracing/opentracing_layer.go +++ b/server/channels/app/opentracing/opentracing_layer.go @@ -12594,7 +12594,7 @@ func (a *OpenTracingAppLayer) MarkChannelAsUnreadFromPost(c request.CTX, postID return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError) { +func (a *OpenTracingAppLayer) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported bool, isCRTEnabled bool) (map[string]int64, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.MarkChannelsAsViewed") @@ -12606,7 +12606,7 @@ func (a *OpenTracingAppLayer) MarkChannelsAsViewed(c request.CTX, channelIDs []s }() defer span.Finish() - resultVar0, resultVar1 := a.app.MarkChannelsAsViewed(c, channelIDs, userID, currentSessionId, collapsedThreadsSupported) + resultVar0, resultVar1 := a.app.MarkChannelsAsViewed(c, channelIDs, userID, currentSessionId, collapsedThreadsSupported, isCRTEnabled) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) diff --git a/server/channels/app/post.go b/server/channels/app/post.go index 93a005842a..71cc0c3a11 100644 --- a/server/channels/app/post.go +++ b/server/channels/app/post.go @@ -100,9 +100,10 @@ func (a *App) CreatePostAsUser(c request.CTX, post *model.Post, currentSessionId // the post is NOT a reply post with CRT enabled _, fromWebhook := post.GetProps()["from_webhook"] _, fromBot := post.GetProps()["from_bot"] - isCRTReply := post.RootId != "" && a.IsCRTEnabledForUser(c, post.UserId) + isCRTEnabled := a.IsCRTEnabledForUser(c, post.UserId) + isCRTReply := post.RootId != "" && isCRTEnabled if !fromWebhook && !fromBot && !isCRTReply { - if _, err := a.MarkChannelsAsViewed(c, []string{post.ChannelId}, post.UserId, currentSessionId, true); err != nil { + if _, err := a.MarkChannelsAsViewed(c, []string{post.ChannelId}, post.UserId, currentSessionId, true, isCRTEnabled); err != nil { c.Logger().Warn( "Encountered error updating last viewed", mlog.String("channel_id", post.ChannelId),