mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 11:11:13 +08:00
FEATURE: Dismiss new and unread for PM inboxes.
This commit is contained in:
@ -925,26 +925,7 @@ class TopicsController < ApplicationController
|
||||
end
|
||||
topic_ids = params[:topic_ids].map { |t| t.to_i }
|
||||
elsif params[:filter] == 'unread'
|
||||
tq = TopicQuery.new(current_user)
|
||||
topics = TopicQuery.unread_filter(tq.joined_topic_user, staff: guardian.is_staff?).listable_topics
|
||||
topics = TopicQuery.tracked_filter(topics, current_user.id) if params[:tracked].to_s == "true"
|
||||
|
||||
if params[:category_id]
|
||||
if params[:include_subcategories]
|
||||
topics = topics.where(<<~SQL, category_id: params[:category_id])
|
||||
category_id in (select id FROM categories WHERE parent_category_id = :category_id) OR
|
||||
category_id = :category_id
|
||||
SQL
|
||||
else
|
||||
topics = topics.where('category_id = ?', params[:category_id])
|
||||
end
|
||||
end
|
||||
|
||||
if params[:tag_name].present?
|
||||
topics = topics.joins(:tags).where("tags.name": params[:tag_name])
|
||||
end
|
||||
|
||||
topic_ids = topics.pluck(:id)
|
||||
topic_ids = bulk_unread_topic_ids
|
||||
else
|
||||
raise ActionController::ParameterMissing.new(:topic_ids)
|
||||
end
|
||||
@ -960,6 +941,35 @@ class TopicsController < ApplicationController
|
||||
render_json_dump topic_ids: changed_topic_ids
|
||||
end
|
||||
|
||||
def private_message_reset_new
|
||||
topic_query = TopicQuery.new(current_user)
|
||||
|
||||
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_scope = topic_query
|
||||
.private_messages_for(current_user, :all)
|
||||
.where("topics.id IN (?)", params[:topic_ids].map(&:to_i))
|
||||
else
|
||||
params.require(:inbox)
|
||||
inbox = params[:inbox].to_s
|
||||
filter = private_message_filter(topic_query, inbox)
|
||||
topic_scope = topic_query.filter_private_message_new(current_user, filter)
|
||||
end
|
||||
|
||||
TopicsBulkAction.new(
|
||||
current_user,
|
||||
topic_scope.pluck(:id),
|
||||
type: "dismiss_topics"
|
||||
).perform!
|
||||
|
||||
render json: success_json
|
||||
end
|
||||
|
||||
def reset_new
|
||||
topic_scope =
|
||||
if params[:category_id].present?
|
||||
@ -993,7 +1003,7 @@ class TopicsController < ApplicationController
|
||||
topic_scope = topic_scope.where(id: topic_ids)
|
||||
end
|
||||
|
||||
dismissed_topic_ids = TopicsBulkAction.new(current_user, [topic_scope.pluck(:id)], type: "dismiss_topics").perform!
|
||||
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
|
||||
@ -1217,4 +1227,49 @@ class TopicsController < ApplicationController
|
||||
def pm_has_slots?(pm)
|
||||
guardian.is_staff? || !pm.reached_recipients_limit?
|
||||
end
|
||||
|
||||
def bulk_unread_topic_ids
|
||||
topic_query = TopicQuery.new(current_user)
|
||||
|
||||
if inbox = params[:private_message_inbox]
|
||||
filter = private_message_filter(topic_query, inbox)
|
||||
topics = topic_query.filter_private_messages_unread(current_user, filter)
|
||||
else
|
||||
topics = TopicQuery.unread_filter(topic_query.joined_topic_user, staff: guardian.is_staff?).listable_topics
|
||||
topics = TopicQuery.tracked_filter(topics, current_user.id) if params[:tracked].to_s == "true"
|
||||
|
||||
if params[:category_id]
|
||||
if params[:include_subcategories]
|
||||
topics = topics.where(<<~SQL, category_id: params[:category_id])
|
||||
category_id in (select id FROM categories WHERE parent_category_id = :category_id) OR
|
||||
category_id = :category_id
|
||||
SQL
|
||||
else
|
||||
topics = topics.where('category_id = ?', params[:category_id])
|
||||
end
|
||||
end
|
||||
|
||||
if params[:tag_name].present?
|
||||
topics = topics.joins(:tags).where("tags.name": params[:tag_name])
|
||||
end
|
||||
end
|
||||
|
||||
topics.pluck(:id)
|
||||
end
|
||||
|
||||
def private_message_filter(topic_query, inbox)
|
||||
case inbox
|
||||
when "group"
|
||||
group_name = params[:group_name]
|
||||
group = Group.find_by("lower(name) = ?", group_name)
|
||||
raise Discourse::NotFound if !group
|
||||
raise Discourse::NotFound if !guardian.can_see_group_messages?(group)
|
||||
topic_query.options[:group_name] = group_name
|
||||
:group
|
||||
when "user"
|
||||
:user
|
||||
else
|
||||
:all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user