FEATURE: proper mailing list mode

once enable_mailing_list_mode is enabled any user can elect
to get every post via email unless they opt out of category or topic
This commit is contained in:
Sam
2014-02-07 11:07:52 +11:00
parent 3a1c5ed39d
commit 227873df78
23 changed files with 134 additions and 68 deletions
-17
View File
@@ -72,23 +72,6 @@ class TopicUser < ActiveRecord::Base
TopicUser.where('topic_id = ? and user_id = ?', topic, user).first
end
def auto_watch_new_topic(topic_id)
# Can not afford to slow down creation of topics when a pile of users are watching new topics, reverting to SQL for max perf here
sql = <<SQL
INSERT INTO topic_users(user_id, topic_id, notification_level, notifications_reason_id)
SELECT id, :topic_id, :level, :reason
FROM users
WHERE watch_new_topics AND
NOT EXISTS(SELECT 1 FROM topic_users WHERE topic_id = :topic_id AND user_id = users.id)
SQL
exec_sql(
sql,
topic_id: topic_id,
level: notification_levels[:watching],
reason: notification_reasons[:auto_watch]
)
end
# Change attributes for a user (creates a record when none is present). First it tries an update
# since there's more likely to be an existing record than not. If the update returns 0 rows affected
+1
View File
@@ -83,6 +83,7 @@ class User < ActiveRecord::Base
attr_accessor :notification_channel_position
scope :blocked, -> { where(blocked: true) } # no index
scope :not_blocked, -> { where(blocked: false) } # no index
scope :suspended, -> { where('suspended_till IS NOT NULL AND suspended_till > ?', Time.zone.now) } # no index
scope :not_suspended, -> { where('suspended_till IS NULL') }
# excluding fake users like the community user