FIX: no email when the category is muted and mailing list is on (#11490)

When `mute_all_categories_by_default` setting is enabled we should not send mailing list until category, tag or topic is explicitly watched.
This commit is contained in:
Krzysztof Kotlarek
2020-12-16 09:30:21 +11:00
committed by GitHub
parent 7588910ee6
commit 6dd3f986b2
4 changed files with 41 additions and 5 deletions

View File

@ -234,6 +234,13 @@ class User < ActiveRecord::Base
end
end
scope :watching_topic_when_mute_categories_by_default, ->(topic) do
joins(DB.sql_fragment("LEFT JOIN category_users ON category_users.user_id = users.id AND category_users.category_id = :category_id", category_id: topic.category_id))
.joins(DB.sql_fragment("LEFT JOIN topic_users ON topic_users.user_id = users.id AND topic_users.topic_id = :topic_id", topic_id: topic.id))
.joins("LEFT JOIN tag_users ON tag_users.user_id = users.id AND tag_users.tag_id IN (#{topic.tag_ids.join(",").presence || 'NULL'})")
.where("category_users.notification_level > 0 OR topic_users.notification_level > 0 OR tag_users.notification_level > 0")
end
module NewTopicDuration
ALWAYS = -1
LAST_VISIT = -2