FEATURE: Dismiss new and unread for PM inboxes.

This commit is contained in:
Alan Guo Xiang Tan
2021-07-30 17:00:48 +08:00
parent d3779d4cf7
commit 2c046cc670
29 changed files with 769 additions and 152 deletions

View File

@@ -806,7 +806,6 @@ class TopicQuery
list = list
.references("cu")
.joins("LEFT JOIN category_users ON category_users.category_id = topics.category_id AND category_users.user_id = #{user.id}")
.joins("LEFT JOIN dismissed_topic_users ON dismissed_topic_users.topic_id = topics.id AND dismissed_topic_users.user_id = #{user.id}")
.where("topics.category_id = :category_id
OR COALESCE(category_users.notification_level, :default) <> :muted
OR tu.notification_level > :regular",
@@ -877,10 +876,16 @@ class TopicQuery
def remove_dismissed(list, user)
if user
list = list.where("dismissed_topic_users.id IS NULL")
list
.joins(<<~SQL)
LEFT JOIN dismissed_topic_users
ON dismissed_topic_users.topic_id = topics.id
AND dismissed_topic_users.user_id = #{user.id.to_i}
SQL
.where("dismissed_topic_users.id IS NULL")
else
list
end
list
end
def new_messages(params)

View File

@@ -63,30 +63,15 @@ class TopicQuery
end
def list_private_messages_new(user, type = :user)
list = TopicQuery.new_filter(
private_messages_for(user, type),
treat_as_new_topic_start_date: user.user_option.treat_as_new_topic_start_date
)
list = filter_private_message_new(user, type)
list = remove_muted_tags(list, user)
list = remove_dismissed(list, user)
create_list(:private_messages, {}, list)
end
def list_private_messages_unread(user, type = :user)
list = TopicQuery.unread_filter(
private_messages_for(user, type),
staff: user.staff?
)
first_unread_pm_at = UserStat
.where(user_id: user.id)
.pluck_first(:first_unread_pm_at)
if first_unread_pm_at
list = list.where("topics.updated_at >= ?", first_unread_pm_at)
end
list = filter_private_messages_unread(user, type)
create_list(:private_messages, {}, list)
end
@@ -118,30 +103,14 @@ class TopicQuery
end
def list_private_messages_group_new(user)
list = TopicQuery.new_filter(
private_messages_for(user, :group),
treat_as_new_topic_start_date: user.user_option.treat_as_new_topic_start_date
)
list = filter_private_message_new(user, :group)
publish_read_state = !!group.publish_read_state
list = append_read_state(list, group) if publish_read_state
create_list(:private_messages, { publish_read_state: publish_read_state }, list)
end
def list_private_messages_group_unread(user)
list = TopicQuery.unread_filter(
private_messages_for(user, :group),
staff: user.staff?
)
first_unread_pm_at = UserStat
.where(user_id: user.id)
.pluck_first(:first_unread_pm_at)
if first_unread_pm_at
list = list.where("topics.updated_at >= ?", first_unread_pm_at)
end
list = filter_private_messages_unread(user, :group)
publish_read_state = !!group.publish_read_state
list = append_read_state(list, group) if publish_read_state
create_list(:private_messages, { publish_read_state: publish_read_state }, list)
@@ -206,6 +175,30 @@ class TopicQuery
create_list(:private_messages, {}, list)
end
def filter_private_messages_unread(user, type)
list = TopicQuery.unread_filter(
private_messages_for(user, type),
staff: user.staff?
)
first_unread_pm_at = UserStat
.where(user_id: user.id)
.pluck_first(:first_unread_pm_at)
if first_unread_pm_at
list = list.where("topics.updated_at >= ?", first_unread_pm_at)
end
list
end
def filter_private_message_new(user, type)
TopicQuery.new_filter(
private_messages_for(user, type),
treat_as_new_topic_start_date: user.user_option.treat_as_new_topic_start_date
)
end
private
def append_read_state(list, group)

View File

@@ -86,7 +86,6 @@ class TopicsBulkAction
.joins("LEFT JOIN topic_users ON topic_users.topic_id = topics.id AND topic_users.user_id = #{@user.id}")
.where("topics.created_at >= ?", dismiss_topics_since_date)
.where("topic_users.last_read_post_number IS NULL")
.where("topics.archetype <> ?", Archetype.private_message)
.order("topics.created_at DESC")
.limit(SiteSetting.max_new_topics).map do |topic|
{