FIX: Dismissing unread posts did not publish changes to other clients (#22584)

Why this change?

Prior to this change, dismissing unreads posts did not publish the
changes across clients for the same user. As a result, users can end up
seeing an unread count being present but saw no topics being loaded when
visiting the `/unread` route.
This commit is contained in:
Alan Guo Xiang Tan
2023-07-13 18:05:56 +08:00
committed by GitHub
parent ab6c638da2
commit 48c8ed49d6
9 changed files with 208 additions and 40 deletions

View File

@ -86,6 +86,7 @@ class TopicsBulkAction
def dismiss_posts
highest_number_source_column =
@user.whisperer? ? "highest_staff_post_number" : "highest_post_number"
sql = <<~SQL
UPDATE topic_users tu
SET last_read_post_number = t.#{highest_number_source_column}
@ -94,6 +95,8 @@ class TopicsBulkAction
SQL
DB.exec(sql, user_id: @user.id, topic_ids: @topic_ids)
TopicTrackingState.publish_dismiss_new_posts(@user.id, topic_ids: @topic_ids.sort)
@changed_ids.concat @topic_ids
end
@ -115,7 +118,9 @@ class TopicsBulkAction
now = Time.zone.now
rows = ids.map { |id| { topic_id: id, user_id: @user.id, created_at: now } }
DismissedTopicUser.insert_all(rows)
TopicTrackingState.publish_dismiss_new(@user.id, topic_ids: ids.sort)
end
@changed_ids = ids
end