FEATURE: New way to dismiss new topics (#11927)

This is a try to simplify logic around dismiss new topics to have one solution to work in all places - dismiss all-new, dismiss new in a specific category or even in a specific tag.
This commit is contained in:
Krzysztof Kotlarek
2021-02-04 11:27:34 +11:00
committed by GitHub
parent 151193bb11
commit f39e7fe81d
17 changed files with 317 additions and 33 deletions

View File

@ -551,7 +551,7 @@ class TopicQuery
result = remove_muted_topics(result, @user)
result = remove_muted_categories(result, @user, exclude: options[:category])
result = remove_muted_tags(result, @user, options)
result = remove_already_seen_for_category(result, @user)
result = remove_dismissed(result, @user)
self.class.results_filter_callbacks.each do |filter_callback|
result = filter_callback.call(:new, result, @user, options)
@ -900,6 +900,7 @@ 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",
@ -968,10 +969,9 @@ class TopicQuery
end
end
def remove_already_seen_for_category(list, user)
def remove_dismissed(list, user)
if user
list = list
.where("category_users.last_seen_at IS NULL OR topics.created_at > category_users.last_seen_at")
list = list.where("dismissed_topic_users.id IS NULL")
end
list