[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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fdf4800994
Коммит
58879719f2
@@ -2655,52 +2655,55 @@ 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 {
|
||||||
var errNotFound *store.ErrNotFound
|
threadMembership, sErr := a.Srv().Store.Thread().GetMembershipForUser(user.Id, threadId)
|
||||||
if nErr != nil && !errors.As(nErr, &errNotFound) {
|
var errNotFound *store.ErrNotFound
|
||||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
if sErr != nil && !errors.As(sErr, &errNotFound) {
|
||||||
}
|
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
|
|
||||||
if threadMembership == nil {
|
|
||||||
opts := store.ThreadMembershipOpts{
|
|
||||||
Following: true,
|
|
||||||
IncrementMentions: false,
|
|
||||||
UpdateFollowing: true,
|
|
||||||
UpdateViewedTimestamp: false,
|
|
||||||
UpdateParticipants: false,
|
|
||||||
}
|
}
|
||||||
threadMembership, nErr = a.Srv().Store.Thread().MaintainMembership(user.Id, threadId, opts)
|
// Follow thread if we're not already following it
|
||||||
if nErr != nil {
|
if threadMembership == nil {
|
||||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
opts := store.ThreadMembershipOpts{
|
||||||
|
Following: true,
|
||||||
|
IncrementMentions: false,
|
||||||
|
UpdateFollowing: true,
|
||||||
|
UpdateViewedTimestamp: false,
|
||||||
|
UpdateParticipants: false,
|
||||||
|
}
|
||||||
|
threadMembership, sErr = a.Srv().Store.Thread().MaintainMembership(user.Id, threadId, opts)
|
||||||
|
if sErr != nil {
|
||||||
|
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.
|
threadMembership.Following = true
|
||||||
threadMembership.Following = true
|
threadMembership.LastViewed = post.UpdateAt - 1
|
||||||
threadMembership.LastViewed = post.UpdateAt - 1
|
threadMembership.UnreadMentions, err = a.countThreadMentions(user, rootPost, channel.TeamId, post.UpdateAt-1)
|
||||||
threadMembership.UnreadMentions, err = a.countThreadMentions(user, rootPost, channel.TeamId, post.UpdateAt-1)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
return nil, err
|
}
|
||||||
}
|
threadMembership, sErr = a.Srv().Store.Thread().UpdateMembership(threadMembership)
|
||||||
threadMembership, nErr = a.Srv().Store.Thread().UpdateMembership(threadMembership)
|
if sErr != nil {
|
||||||
if nErr != nil {
|
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, sErr.Error(), http.StatusInternalServerError)
|
||||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
}
|
||||||
}
|
thread, sErr := a.Srv().Store.Thread().GetThreadForUser(channel.TeamId, threadMembership, true)
|
||||||
thread, nErr := a.Srv().Store.Thread().GetThreadForUser(channel.TeamId, threadMembership, true)
|
if sErr != nil {
|
||||||
if nErr != nil {
|
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, sErr.Error(), http.StatusInternalServerError)
|
||||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
}
|
||||||
}
|
a.sanitizeProfiles(thread.Participants, false)
|
||||||
a.sanitizeProfiles(thread.Participants, false)
|
thread.Post.SanitizeProps()
|
||||||
thread.Post.SanitizeProps()
|
|
||||||
|
|
||||||
if a.IsCRTEnabledForUser(userID) {
|
if a.IsCRTEnabledForUser(userID) {
|
||||||
payload, jsonErr := json.Marshal(thread)
|
payload, jsonErr := json.Marshal(thread)
|
||||||
if jsonErr != nil {
|
if jsonErr != nil {
|
||||||
mlog.Warn("Failed to encode thread to JSON")
|
mlog.Warn("Failed to encode thread to JSON")
|
||||||
|
}
|
||||||
|
message := model.NewWebSocketEvent(model.WebsocketEventThreadUpdated, channel.TeamId, "", userID, nil)
|
||||||
|
message.Add("thread", string(payload))
|
||||||
|
a.Publish(message)
|
||||||
}
|
}
|
||||||
message := model.NewWebSocketEvent(model.WebsocketEventThreadUpdated, channel.TeamId, "", userID, nil)
|
|
||||||
message.Add("thread", string(payload))
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user