FEATURE: Allow selective dismissal of new and unread topics (#12976)

This PR improves the UI of bulk select so that its context is applied to the Dismiss Unread and Dismiss New buttons. Regular users (not just staff) are now able to use topic bulk selection on the /new and /unread routes to perform these dismiss actions more selectively.

For Dismiss Unread, there is a new count in the text of the button and in the modal when one or more topic is selected with the bulk select checkboxes.

For Dismiss New, there is a count in the button text, and we have added functionality to the server side to accept an array of topic ids to dismiss new for, instead of always having to dismiss all new, the same as the bulk dismiss unread functionality. To clean things up, the `DismissTopics` service has been rolled into the `TopicsBulkAction` service.

We now also show the top Dismiss/Dismiss New button based on whether the bottom one is in the viewport, not just based on the topic count.
This commit is contained in:
Martin Brennan
2021-05-26 09:38:46 +10:00
committed by GitHub
parent de0f2b9546
commit 7a79bd7da3
22 changed files with 399 additions and 292 deletions

View File

@@ -245,11 +245,11 @@ class TopicsController < ApplicationController
params.require(:topic_id)
params.require(:post_ids)
post_ids = params[:post_ids].map(&:to_i)
unless Array === post_ids
unless Array === params[:post_ids]
render_json_error("Expecting post_ids to contain a list of posts ids")
return
end
post_ids = params[:post_ids].map(&:to_i)
if post_ids.length > 100
render_json_error("Requested a chunk that is too big")
@@ -911,6 +911,11 @@ class TopicsController < ApplicationController
def bulk
if params[:topic_ids].present?
unless Array === params[:topic_ids]
raise Discourse::InvalidParameters.new(
"Expecting topic_ids to contain a list of topic ids"
)
end
topic_ids = params[:topic_ids].map { |t| t.to_i }
elsif params[:filter] == 'unread'
tq = TopicQuery.new(current_user)
@@ -970,7 +975,18 @@ class TopicsController < ApplicationController
end
end
dismissed_topic_ids = DismissTopics.new(current_user, topic_scope).perform!
if params[:topic_ids].present?
unless Array === params[:topic_ids]
raise Discourse::InvalidParameters.new(
"Expecting topic_ids to contain a list of topic ids"
)
end
topic_ids = params[:topic_ids].map { |t| t.to_i }
topic_scope = topic_scope.where(id: topic_ids)
end
dismissed_topic_ids = TopicsBulkAction.new(current_user, [topic_scope.pluck(:id)], type: "dismiss_topics").perform!
TopicTrackingState.publish_dismiss_new(current_user.id, topic_ids: dismissed_topic_ids)
render body: nil