[MM-41350] All CRT server operations should only happen if ThreadAutoFollow is true (#19411)

Summary
CRT server book-keeping should only happen if ThreadAutoFollow is true.

Ticket Link
https://mattermost.atlassian.net/browse/MM-41350
Этот коммит содержится в:
Ashish Bhate
2022-02-01 17:56:42 +05:30
коммит произвёл GitHub
родитель fdf4800994
Коммит 58879719f2

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

@@ -2655,10 +2655,11 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(postID string, userID st
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError) return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
} }
threadMembership, nErr := a.Srv().Store.Thread().GetMembershipForUser(user.Id, threadId) if *a.Config().ServiceSettings.ThreadAutoFollow {
threadMembership, sErr := a.Srv().Store.Thread().GetMembershipForUser(user.Id, threadId)
var errNotFound *store.ErrNotFound var errNotFound *store.ErrNotFound
if nErr != nil && !errors.As(nErr, &errNotFound) { if sErr != nil && !errors.As(sErr, &errNotFound) {
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError) return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, sErr.Error(), http.StatusInternalServerError)
} }
// Follow thread if we're not already following it // Follow thread if we're not already following it
if threadMembership == nil { if threadMembership == nil {
@@ -2669,9 +2670,9 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(postID string, userID st
UpdateViewedTimestamp: false, UpdateViewedTimestamp: false,
UpdateParticipants: false, UpdateParticipants: false,
} }
threadMembership, nErr = a.Srv().Store.Thread().MaintainMembership(user.Id, threadId, opts) threadMembership, sErr = a.Srv().Store.Thread().MaintainMembership(user.Id, threadId, opts)
if nErr != nil { if sErr != nil {
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError) return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, sErr.Error(), http.StatusInternalServerError)
} }
} }
// If threadmembership already exists but user had previously unfollowed the thread, then follow the thread again. // If threadmembership already exists but user had previously unfollowed the thread, then follow the thread again.
@@ -2681,13 +2682,13 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(postID string, userID st
if err != nil { if err != nil {
return nil, err return nil, err
} }
threadMembership, nErr = a.Srv().Store.Thread().UpdateMembership(threadMembership) threadMembership, sErr = a.Srv().Store.Thread().UpdateMembership(threadMembership)
if nErr != nil { if sErr != nil {
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError) return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, sErr.Error(), http.StatusInternalServerError)
} }
thread, nErr := a.Srv().Store.Thread().GetThreadForUser(channel.TeamId, threadMembership, true) thread, sErr := a.Srv().Store.Thread().GetThreadForUser(channel.TeamId, threadMembership, true)
if nErr != nil { if sErr != nil {
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError) return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, sErr.Error(), http.StatusInternalServerError)
} }
a.sanitizeProfiles(thread.Participants, false) a.sanitizeProfiles(thread.Participants, false)
thread.Post.SanitizeProps() thread.Post.SanitizeProps()
@@ -2701,6 +2702,8 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(postID string, userID st
message.Add("thread", string(payload)) message.Add("thread", string(payload))
a.Publish(message) a.Publish(message)
} }
}
channelUnread, nErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions, 0, false, false) channelUnread, nErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions, 0, false, false)
if nErr != nil { if nErr != nil {
return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError) return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
@@ -2912,7 +2915,7 @@ func (a *App) MarkChannelsAsViewed(channelIDs []string, userID string, currentSe
a.clearPushNotification(currentSessionId, userID, channelID, "") a.clearPushNotification(currentSessionId, userID, channelID, "")
} }
if !collapsedThreadsSupported || !a.IsCRTEnabledForUser(userID) { if *a.Config().ServiceSettings.ThreadAutoFollow && (!collapsedThreadsSupported || !a.IsCRTEnabledForUser(userID)) {
if err := a.Srv().Store.Thread().MarkAllAsReadInChannels(userID, channelIDs); err != nil { if err := a.Srv().Store.Thread().MarkAllAsReadInChannels(userID, channelIDs); err != nil {
return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, err.Error(), http.StatusInternalServerError)
} }