2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
class UserNotifications < ActionMailer::Base
|
2017-01-09 12:27:27 -06:00
|
|
|
include UserNotificationsHelper
|
2017-04-10 12:15:25 -05:00
|
|
|
include ApplicationHelper
|
2017-04-24 14:26:06 -05:00
|
|
|
helper :application, :email
|
2013-04-26 01:56:28 -05:00
|
|
|
default charset: 'UTF-8'
|
2019-07-30 14:05:08 -05:00
|
|
|
layout 'email_template'
|
2013-04-26 01:56:28 -05:00
|
|
|
|
2013-06-10 15:46:08 -05:00
|
|
|
include Email::BuildEmailHelper
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2017-07-27 20:20:09 -05:00
|
|
|
def signup(user, opts = {})
|
2017-04-20 10:17:24 -05:00
|
|
|
build_user_email_token_by_template(
|
|
|
|
"user_notifications.signup",
|
|
|
|
user,
|
|
|
|
opts[:email_token]
|
|
|
|
)
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
2019-04-10 09:53:52 -05:00
|
|
|
def activation_reminder(user, opts = {})
|
|
|
|
build_user_email_token_by_template(
|
|
|
|
"user_notifications.activation_reminder",
|
|
|
|
user,
|
|
|
|
opts[:email_token]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-07-27 20:20:09 -05:00
|
|
|
def signup_after_approval(user, opts = {})
|
2018-09-05 04:44:26 -05:00
|
|
|
locale = user_locale(user)
|
|
|
|
tips = I18n.t('system_messages.usage_tips.text_body_template',
|
|
|
|
base_url: Discourse.base_url,
|
|
|
|
locale: locale)
|
|
|
|
|
2013-06-10 15:46:08 -05:00
|
|
|
build_email(user.email,
|
2013-06-12 15:35:46 -05:00
|
|
|
template: 'user_notifications.signup_after_approval',
|
2018-09-05 04:44:26 -05:00
|
|
|
locale: locale,
|
|
|
|
new_user_tips: tips)
|
2013-06-05 22:16:31 -05:00
|
|
|
end
|
|
|
|
|
2021-04-12 10:08:23 -05:00
|
|
|
def post_approved(user, opts = {})
|
|
|
|
post_url = opts.dig(:notification_data_hash, :post_url)
|
|
|
|
|
|
|
|
return if post_url.nil?
|
|
|
|
|
|
|
|
locale = user_locale(user)
|
|
|
|
build_email(user.email,
|
|
|
|
template: 'user_notifications.post_approved',
|
|
|
|
locale: locale,
|
|
|
|
base_url: Discourse.base_url,
|
|
|
|
post_url: post_url
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-01-14 16:43:26 -06:00
|
|
|
def signup_after_reject(user, opts = {})
|
|
|
|
locale = user_locale(user)
|
|
|
|
build_email(user.email,
|
|
|
|
template: 'user_notifications.signup_after_reject',
|
|
|
|
locale: locale,
|
|
|
|
reject_reason: opts[:reject_reason])
|
|
|
|
end
|
|
|
|
|
2018-10-25 04:45:31 -05:00
|
|
|
def suspicious_login(user, opts = {})
|
|
|
|
ipinfo = DiscourseIpInfo.get(opts[:client_ip])
|
2018-12-20 03:23:05 -06:00
|
|
|
location = ipinfo[:location]
|
2018-10-25 04:45:31 -05:00
|
|
|
browser = BrowserDetection.browser(opts[:user_agent])
|
|
|
|
device = BrowserDetection.device(opts[:user_agent])
|
|
|
|
os = BrowserDetection.os(opts[:user_agent])
|
|
|
|
|
|
|
|
build_email(
|
|
|
|
user.email,
|
|
|
|
template: "user_notifications.suspicious_login",
|
|
|
|
locale: user_locale(user),
|
|
|
|
client_ip: opts[:client_ip],
|
|
|
|
location: location.present? ? location : I18n.t('staff_action_logs.unknown'),
|
|
|
|
browser: I18n.t("user_auth_tokens.browser.#{browser}"),
|
|
|
|
device: I18n.t("user_auth_tokens.device.#{device}"),
|
|
|
|
os: I18n.t("user_auth_tokens.os.#{os}")
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-07-27 20:20:09 -05:00
|
|
|
def notify_old_email(user, opts = {})
|
2016-02-03 12:27:58 -06:00
|
|
|
build_email(user.email,
|
2016-03-07 13:40:11 -06:00
|
|
|
template: "user_notifications.notify_old_email",
|
|
|
|
locale: user_locale(user),
|
|
|
|
new_email: opts[:new_email])
|
|
|
|
end
|
|
|
|
|
2020-06-10 11:11:49 -05:00
|
|
|
def notify_old_email_add(user, opts = {})
|
|
|
|
build_email(user.email,
|
|
|
|
template: "user_notifications.notify_old_email_add",
|
|
|
|
locale: user_locale(user),
|
|
|
|
new_email: opts[:new_email])
|
|
|
|
end
|
|
|
|
|
2017-07-27 20:20:09 -05:00
|
|
|
def confirm_old_email(user, opts = {})
|
2017-04-20 10:17:24 -05:00
|
|
|
build_user_email_token_by_template(
|
|
|
|
"user_notifications.confirm_old_email",
|
|
|
|
user,
|
|
|
|
opts[:email_token]
|
|
|
|
)
|
2016-03-07 13:40:11 -06:00
|
|
|
end
|
|
|
|
|
2020-06-10 11:11:49 -05:00
|
|
|
def confirm_old_email_add(user, opts = {})
|
|
|
|
build_user_email_token_by_template(
|
|
|
|
"user_notifications.confirm_old_email_add",
|
|
|
|
user,
|
|
|
|
opts[:email_token]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-07-27 20:20:09 -05:00
|
|
|
def confirm_new_email(user, opts = {})
|
2017-04-20 10:17:24 -05:00
|
|
|
build_user_email_token_by_template(
|
2020-10-06 22:02:24 -05:00
|
|
|
opts[:requested_by_admin] ? "user_notifications.confirm_new_email_via_admin" : "user_notifications.confirm_new_email",
|
2017-04-20 10:17:24 -05:00
|
|
|
user,
|
|
|
|
opts[:email_token]
|
|
|
|
)
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
2017-07-27 20:20:09 -05:00
|
|
|
def forgot_password(user, opts = {})
|
2017-04-20 10:17:24 -05:00
|
|
|
build_user_email_token_by_template(
|
|
|
|
user.has_password? ? "user_notifications.forgot_password" : "user_notifications.set_password",
|
|
|
|
user,
|
|
|
|
opts[:email_token]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def email_login(user, opts = {})
|
|
|
|
build_user_email_token_by_template(
|
|
|
|
"user_notifications.email_login",
|
|
|
|
user,
|
|
|
|
opts[:email_token]
|
|
|
|
)
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
2015-04-27 05:59:48 -05:00
|
|
|
|
2017-07-27 20:20:09 -05:00
|
|
|
def admin_login(user, opts = {})
|
2017-04-20 10:17:24 -05:00
|
|
|
build_user_email_token_by_template(
|
|
|
|
"user_notifications.admin_login",
|
|
|
|
user,
|
|
|
|
opts[:email_token]
|
|
|
|
)
|
2015-04-27 05:59:48 -05:00
|
|
|
end
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2017-07-27 20:20:09 -05:00
|
|
|
def account_created(user, opts = {})
|
2017-04-20 10:17:24 -05:00
|
|
|
build_user_email_token_by_template(
|
|
|
|
"user_notifications.account_created",
|
|
|
|
user,
|
|
|
|
opts[:email_token]
|
|
|
|
)
|
2014-09-11 11:47:17 -05:00
|
|
|
end
|
|
|
|
|
2017-11-13 12:41:36 -06:00
|
|
|
def account_silenced(user, opts = nil)
|
|
|
|
opts ||= {}
|
|
|
|
|
|
|
|
return unless user_history = opts[:user_history]
|
|
|
|
|
2021-07-20 05:42:08 -05:00
|
|
|
if user.silenced_forever?
|
|
|
|
build_email(
|
|
|
|
user.email,
|
|
|
|
template: "user_notifications.account_silenced_forever",
|
|
|
|
locale: user_locale(user),
|
|
|
|
reason: user_history.details
|
|
|
|
)
|
|
|
|
else
|
2022-05-27 04:58:54 -05:00
|
|
|
silenced_till = user.silenced_till.in_time_zone(user.user_option.timezone)
|
2021-07-20 05:42:08 -05:00
|
|
|
build_email(
|
|
|
|
user.email,
|
|
|
|
template: "user_notifications.account_silenced",
|
|
|
|
locale: user_locale(user),
|
|
|
|
reason: user_history.details,
|
2022-05-27 04:58:54 -05:00
|
|
|
silenced_till: I18n.l(silenced_till, format: :long)
|
2021-07-20 05:42:08 -05:00
|
|
|
)
|
|
|
|
end
|
2017-11-13 12:41:36 -06:00
|
|
|
end
|
|
|
|
|
2017-09-13 13:43:36 -05:00
|
|
|
def account_suspended(user, opts = nil)
|
|
|
|
opts ||= {}
|
|
|
|
|
|
|
|
return unless user_history = opts[:user_history]
|
|
|
|
|
2021-07-20 05:42:08 -05:00
|
|
|
if user.suspended_forever?
|
|
|
|
build_email(
|
|
|
|
user.email,
|
|
|
|
template: "user_notifications.account_suspended_forever",
|
|
|
|
locale: user_locale(user),
|
|
|
|
reason: user_history.details
|
|
|
|
)
|
|
|
|
else
|
2022-05-27 04:58:54 -05:00
|
|
|
suspended_till = user.suspended_till.in_time_zone(user.user_option.timezone)
|
2021-07-20 05:42:08 -05:00
|
|
|
build_email(
|
|
|
|
user.email,
|
|
|
|
template: "user_notifications.account_suspended",
|
|
|
|
locale: user_locale(user),
|
|
|
|
reason: user_history.details,
|
2022-05-27 04:58:54 -05:00
|
|
|
suspended_till: I18n.l(suspended_till, format: :long)
|
2021-07-20 05:42:08 -05:00
|
|
|
)
|
|
|
|
end
|
2017-09-13 13:43:36 -05:00
|
|
|
end
|
|
|
|
|
2017-10-03 13:08:37 -05:00
|
|
|
def account_exists(user, opts = {})
|
|
|
|
build_email(
|
|
|
|
user.email,
|
|
|
|
template: 'user_notifications.account_exists',
|
|
|
|
locale: user_locale(user),
|
|
|
|
email: user.email
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-12-21 19:18:12 -06:00
|
|
|
def account_second_factor_disabled(user, opts = {})
|
|
|
|
build_email(
|
|
|
|
user.email,
|
|
|
|
template: 'user_notifications.account_second_factor_disabled',
|
|
|
|
locale: user_locale(user),
|
|
|
|
email: user.email
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-07-27 20:20:09 -05:00
|
|
|
def digest(user, opts = {})
|
2016-05-21 08:17:54 -05:00
|
|
|
build_summary_for(user)
|
2016-07-15 04:39:29 -05:00
|
|
|
min_date = opts[:since] || user.last_emailed_at || user.last_seen_at || 1.month.ago
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2016-12-30 14:18:05 -06:00
|
|
|
# Fetch some topics and posts to show
|
2017-07-27 20:20:09 -05:00
|
|
|
digest_opts = { limit: SiteSetting.digest_topics + SiteSetting.digest_other_topics, top_order: true }
|
2016-12-19 13:53:53 -06:00
|
|
|
topics_for_digest = Topic.for_digest(user, min_date, digest_opts).to_a
|
|
|
|
if topics_for_digest.empty? && !user.user_option.try(:include_tl0_in_digests)
|
2016-12-30 14:18:05 -06:00
|
|
|
# Find some topics from new users that are at least 24 hours old
|
2016-12-19 13:53:53 -06:00
|
|
|
topics_for_digest = Topic.for_digest(user, min_date, digest_opts.merge(include_tl0: true)).where('topics.created_at < ?', 24.hours.ago).to_a
|
|
|
|
end
|
2014-04-17 15:04:26 -05:00
|
|
|
|
2017-07-27 20:20:09 -05:00
|
|
|
@popular_topics = topics_for_digest[0, SiteSetting.digest_topics]
|
2016-11-22 12:23:21 -06:00
|
|
|
|
2016-11-10 17:16:24 -06:00
|
|
|
if @popular_topics.present?
|
2017-01-09 12:27:27 -06:00
|
|
|
@other_new_for_you = topics_for_digest.size > SiteSetting.digest_topics ? topics_for_digest[SiteSetting.digest_topics..-1] : []
|
|
|
|
|
|
|
|
@popular_posts = if SiteSetting.digest_posts > 0
|
|
|
|
Post.order("posts.score DESC")
|
2017-07-27 20:20:09 -05:00
|
|
|
.for_mailing_list(user, min_date)
|
|
|
|
.where('posts.post_type = ?', Post.types[:regular])
|
|
|
|
.where('posts.deleted_at IS NULL AND posts.hidden = false AND posts.user_deleted = false')
|
|
|
|
.where("posts.post_number > ? AND posts.score > ?", 1, ScoreCalculator.default_score_weights[:like_score] * 5.0)
|
2017-08-14 11:47:33 -05:00
|
|
|
.where('posts.created_at < ?', (SiteSetting.editing_grace_period || 0).seconds.ago)
|
2017-07-27 20:20:09 -05:00
|
|
|
.limit(SiteSetting.digest_posts)
|
2017-01-09 12:27:27 -06:00
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
@excerpts = {}
|
|
|
|
|
|
|
|
@popular_topics.map do |t|
|
2019-05-20 03:04:23 -05:00
|
|
|
@excerpts[t.first_post.id] = email_excerpt(t.first_post.cooked, t.first_post) if t.first_post.present?
|
2017-01-09 12:27:27 -06:00
|
|
|
end
|
|
|
|
|
2016-12-30 14:18:05 -06:00
|
|
|
# Try to find 3 interesting stats for the top of the digest
|
2019-04-04 01:19:39 -05:00
|
|
|
new_topics_count = Topic.for_digest(user, min_date).count
|
2016-12-30 14:18:05 -06:00
|
|
|
|
|
|
|
if new_topics_count == 0
|
|
|
|
# We used topics from new users instead, so count should match
|
|
|
|
new_topics_count = topics_for_digest.size
|
|
|
|
end
|
2017-07-27 20:20:09 -05:00
|
|
|
@counts = [{ label_key: 'user_notifications.digest.new_topics',
|
|
|
|
value: new_topics_count,
|
|
|
|
href: "#{Discourse.base_url}/new" }]
|
2016-12-30 14:18:05 -06:00
|
|
|
|
2020-05-05 23:23:13 -05:00
|
|
|
# totalling unread notifications (which are low-priority only) and unread
|
|
|
|
# PMs and bookmark reminder notifications, so the total is both unread low
|
|
|
|
# and high priority PMs
|
|
|
|
value = user.unread_notifications + user.unread_high_priority_notifications
|
2017-07-27 20:20:09 -05:00
|
|
|
@counts << { label_key: 'user_notifications.digest.unread_notifications', value: value, href: "#{Discourse.base_url}/my/notifications" } if value > 0
|
2016-12-30 14:18:05 -06:00
|
|
|
|
|
|
|
if @counts.size < 3
|
|
|
|
value = user.unread_notifications_of_type(Notification.types[:liked])
|
2017-07-27 20:20:09 -05:00
|
|
|
@counts << { label_key: 'user_notifications.digest.liked_received', value: value, href: "#{Discourse.base_url}/my/notifications" } if value > 0
|
2016-12-30 14:18:05 -06:00
|
|
|
end
|
|
|
|
|
2020-06-01 16:39:16 -05:00
|
|
|
if @counts.size < 3 && user.user_option.digest_after_minutes.to_i >= 1440
|
2019-10-25 15:33:05 -05:00
|
|
|
value = summary_new_users_count(min_date)
|
2016-12-30 14:18:05 -06:00
|
|
|
@counts << { label_key: 'user_notifications.digest.new_users', value: value, href: "#{Discourse.base_url}/about" } if value > 0
|
|
|
|
end
|
|
|
|
|
|
|
|
@last_seen_at = short_date(user.last_seen_at || user.created_at)
|
|
|
|
|
|
|
|
@preheader_text = I18n.t('user_notifications.digest.preheader', last_seen_at: @last_seen_at)
|
|
|
|
|
2016-07-15 04:39:29 -05:00
|
|
|
opts = {
|
2019-01-04 09:08:06 -06:00
|
|
|
from_alias: I18n.t('user_notifications.digest.from', site_name: Email.site_title),
|
2017-03-21 08:11:15 -05:00
|
|
|
subject: I18n.t('user_notifications.digest.subject_template', email_prefix: @email_prefix, date: short_date(Time.now)),
|
2016-07-15 04:39:29 -05:00
|
|
|
add_unsubscribe_link: true,
|
|
|
|
unsubscribe_url: "#{Discourse.base_url}/email/unsubscribe/#{@unsubscribe_key}",
|
|
|
|
}
|
|
|
|
|
|
|
|
build_email(user.email, opts)
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
end
|
2013-02-07 09:45:24 -06:00
|
|
|
|
2013-06-12 15:35:46 -05:00
|
|
|
def user_replied(user, opts)
|
|
|
|
opts[:allow_reply_by_email] = true
|
2014-09-29 00:16:55 -05:00
|
|
|
opts[:use_site_subject] = true
|
2014-10-03 06:44:08 -05:00
|
|
|
opts[:show_category_in_subject] = true
|
2018-07-10 21:24:07 -05:00
|
|
|
opts[:show_tags_in_subject] = true
|
2013-06-12 15:35:46 -05:00
|
|
|
notification_email(user, opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_quoted(user, opts)
|
|
|
|
opts[:allow_reply_by_email] = true
|
2014-09-29 00:16:55 -05:00
|
|
|
opts[:use_site_subject] = true
|
2014-10-03 06:44:08 -05:00
|
|
|
opts[:show_category_in_subject] = true
|
2018-07-10 21:24:07 -05:00
|
|
|
opts[:show_tags_in_subject] = true
|
2013-06-12 15:35:46 -05:00
|
|
|
notification_email(user, opts)
|
|
|
|
end
|
|
|
|
|
2016-02-16 11:29:23 -06:00
|
|
|
def user_linked(user, opts)
|
|
|
|
opts[:allow_reply_by_email] = true
|
|
|
|
opts[:use_site_subject] = true
|
|
|
|
opts[:show_category_in_subject] = true
|
2018-07-10 21:24:07 -05:00
|
|
|
opts[:show_tags_in_subject] = true
|
2016-02-16 11:29:23 -06:00
|
|
|
notification_email(user, opts)
|
|
|
|
end
|
|
|
|
|
2013-06-12 15:35:46 -05:00
|
|
|
def user_mentioned(user, opts)
|
|
|
|
opts[:allow_reply_by_email] = true
|
2014-09-29 00:16:55 -05:00
|
|
|
opts[:use_site_subject] = true
|
2014-10-03 06:44:08 -05:00
|
|
|
opts[:show_category_in_subject] = true
|
2018-07-10 21:24:07 -05:00
|
|
|
opts[:show_tags_in_subject] = true
|
2013-06-12 15:35:46 -05:00
|
|
|
notification_email(user, opts)
|
|
|
|
end
|
|
|
|
|
2015-11-30 19:12:55 -06:00
|
|
|
def group_mentioned(user, opts)
|
|
|
|
opts[:allow_reply_by_email] = true
|
|
|
|
opts[:use_site_subject] = true
|
|
|
|
opts[:show_category_in_subject] = true
|
2018-07-10 21:24:07 -05:00
|
|
|
opts[:show_tags_in_subject] = true
|
2015-11-30 19:12:55 -06:00
|
|
|
notification_email(user, opts)
|
|
|
|
end
|
|
|
|
|
2013-06-12 15:35:46 -05:00
|
|
|
def user_posted(user, opts)
|
|
|
|
opts[:allow_reply_by_email] = true
|
2014-09-29 00:16:55 -05:00
|
|
|
opts[:use_site_subject] = true
|
|
|
|
opts[:add_re_to_subject] = true
|
2014-10-03 06:44:08 -05:00
|
|
|
opts[:show_category_in_subject] = true
|
2018-07-10 21:24:07 -05:00
|
|
|
opts[:show_tags_in_subject] = true
|
2013-06-12 15:35:46 -05:00
|
|
|
notification_email(user, opts)
|
|
|
|
end
|
|
|
|
|
2013-08-07 12:02:49 -05:00
|
|
|
def user_private_message(user, opts)
|
|
|
|
opts[:allow_reply_by_email] = true
|
2014-09-29 00:16:55 -05:00
|
|
|
opts[:use_site_subject] = true
|
|
|
|
opts[:add_re_to_subject] = true
|
2014-10-03 06:44:08 -05:00
|
|
|
opts[:show_category_in_subject] = false
|
2018-07-10 21:24:07 -05:00
|
|
|
opts[:show_tags_in_subject] = false
|
2018-02-19 03:20:17 -06:00
|
|
|
opts[:show_group_in_subject] = true if SiteSetting.group_in_subject
|
2013-08-07 12:02:49 -05:00
|
|
|
|
|
|
|
# We use the 'user_posted' event when you are emailed a post in a PM.
|
2014-06-16 01:36:02 -05:00
|
|
|
opts[:notification_type] = 'posted'
|
2013-08-07 12:02:49 -05:00
|
|
|
|
|
|
|
notification_email(user, opts)
|
|
|
|
end
|
|
|
|
|
2015-04-07 01:21:38 -05:00
|
|
|
def user_invited_to_private_message(user, opts)
|
2016-03-25 07:26:52 -05:00
|
|
|
opts[:allow_reply_by_email] = false
|
|
|
|
opts[:use_invite_template] = true
|
2015-04-07 01:21:38 -05:00
|
|
|
notification_email(user, opts)
|
|
|
|
end
|
|
|
|
|
2015-03-30 13:36:47 -05:00
|
|
|
def user_invited_to_topic(user, opts)
|
2016-03-25 07:26:52 -05:00
|
|
|
opts[:allow_reply_by_email] = false
|
|
|
|
opts[:use_invite_template] = true
|
2015-03-30 13:36:47 -05:00
|
|
|
opts[:show_category_in_subject] = true
|
2018-07-10 21:24:07 -05:00
|
|
|
opts[:show_tags_in_subject] = true
|
2015-03-30 13:36:47 -05:00
|
|
|
notification_email(user, opts)
|
|
|
|
end
|
|
|
|
|
2016-07-07 11:23:19 -05:00
|
|
|
def user_watching_first_post(user, opts)
|
|
|
|
user_posted(user, opts)
|
|
|
|
end
|
|
|
|
|
2014-02-06 18:06:35 -06:00
|
|
|
def mailing_list_notify(user, post)
|
2016-02-03 12:27:58 -06:00
|
|
|
opts = {
|
2014-02-06 18:06:35 -06:00
|
|
|
post: post,
|
|
|
|
allow_reply_by_email: true,
|
2014-09-29 00:16:55 -05:00
|
|
|
use_site_subject: true,
|
|
|
|
add_re_to_subject: true,
|
2014-10-03 06:44:08 -05:00
|
|
|
show_category_in_subject: true,
|
2018-07-10 21:24:07 -05:00
|
|
|
show_tags_in_subject: true,
|
2014-02-06 18:06:35 -06:00
|
|
|
notification_type: "posted",
|
2016-02-03 12:27:58 -06:00
|
|
|
notification_data_hash: {
|
|
|
|
original_username: post.user.username,
|
|
|
|
topic_title: post.topic.title,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
notification_email(user, opts)
|
2014-02-06 18:06:35 -06:00
|
|
|
end
|
|
|
|
|
2013-06-12 15:35:46 -05:00
|
|
|
protected
|
|
|
|
|
2016-02-09 17:54:13 -06:00
|
|
|
def user_locale(user)
|
2018-09-05 04:44:26 -05:00
|
|
|
user.effective_locale
|
2016-02-09 17:54:13 -06:00
|
|
|
end
|
|
|
|
|
2017-07-27 20:20:09 -05:00
|
|
|
def email_post_markdown(post, add_posted_by = false)
|
2020-09-09 18:50:16 -05:00
|
|
|
result = +"#{post.raw}\n\n"
|
2016-04-11 12:06:10 -05:00
|
|
|
if add_posted_by
|
|
|
|
result << "#{I18n.t('user_notifications.posted_by', username: post.username, post_date: post.created_at.strftime("%m/%d/%Y"))}\n\n"
|
|
|
|
end
|
2013-07-22 14:06:37 -05:00
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2016-02-25 07:05:40 -06:00
|
|
|
def self.get_context_posts(post, topic_user, user)
|
2017-04-24 14:26:06 -05:00
|
|
|
if (user.user_option.email_previous_replies == UserOption.previous_replies_type[:never]) ||
|
|
|
|
SiteSetting.private_email?
|
2016-02-18 20:56:52 -06:00
|
|
|
return []
|
|
|
|
end
|
|
|
|
|
2016-02-12 05:10:30 -06:00
|
|
|
allowed_post_types = [Post.types[:regular]]
|
|
|
|
allowed_post_types << Post.types[:whisper] if topic_user.try(:user).try(:staff?)
|
|
|
|
|
2014-01-30 23:37:40 -06:00
|
|
|
context_posts = Post.where(topic_id: post.topic_id)
|
2017-07-27 20:20:09 -05:00
|
|
|
.where("post_number < ?", post.post_number)
|
|
|
|
.where(user_deleted: false)
|
|
|
|
.where(hidden: false)
|
|
|
|
.where(post_type: allowed_post_types)
|
|
|
|
.order('created_at desc')
|
|
|
|
.limit(SiteSetting.email_posts_context)
|
2014-01-30 23:37:40 -06:00
|
|
|
|
2016-02-25 07:05:40 -06:00
|
|
|
if topic_user && topic_user.last_emailed_post_number && user.user_option.email_previous_replies == UserOption.previous_replies_type[:unless_emailed]
|
2014-01-30 23:37:40 -06:00
|
|
|
context_posts = context_posts.where("post_number > ?", topic_user.last_emailed_post_number)
|
|
|
|
end
|
|
|
|
|
|
|
|
context_posts
|
|
|
|
end
|
|
|
|
|
2013-06-12 15:35:46 -05:00
|
|
|
def notification_email(user, opts)
|
2016-02-03 12:27:58 -06:00
|
|
|
notification_type = opts[:notification_type]
|
|
|
|
notification_data = opts[:notification_data_hash]
|
|
|
|
post = opts[:post]
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2016-01-26 19:19:49 -06:00
|
|
|
unless String === notification_type
|
|
|
|
if Numeric === notification_type
|
|
|
|
notification_type = Notification.types[notification_type]
|
|
|
|
end
|
|
|
|
notification_type = notification_type.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
user_name = notification_data[:original_username]
|
|
|
|
|
|
|
|
if post && SiteSetting.enable_names && SiteSetting.display_name_on_email_from
|
2021-05-25 21:55:07 -05:00
|
|
|
name = User.where(id: notification_data[:original_user_id] || post.user_id).pluck_first(:name)
|
2015-05-05 21:55:33 -05:00
|
|
|
user_name = name unless name.blank?
|
2014-10-21 09:06:55 -05:00
|
|
|
end
|
|
|
|
|
2014-05-06 14:01:19 -05:00
|
|
|
allow_reply_by_email = opts[:allow_reply_by_email] unless user.suspended?
|
2016-01-26 19:19:49 -06:00
|
|
|
original_username = notification_data[:original_username] || notification_data[:display_username]
|
2014-02-06 18:06:35 -06:00
|
|
|
|
2019-01-18 03:52:48 -06:00
|
|
|
if user.staged && post
|
|
|
|
original_subject = IncomingEmail.joins(:post)
|
|
|
|
.where("posts.topic_id = ? AND posts.post_number = 1", post.topic_id)
|
|
|
|
.pluck(:subject)
|
|
|
|
.first
|
|
|
|
end
|
|
|
|
|
|
|
|
if original_subject
|
|
|
|
topic_title = original_subject
|
|
|
|
opts[:use_site_subject] = false
|
|
|
|
opts[:add_re_to_subject] = true
|
|
|
|
use_topic_title_subject = true
|
|
|
|
else
|
|
|
|
topic_title = notification_data[:topic_title]
|
|
|
|
use_topic_title_subject = false
|
|
|
|
end
|
|
|
|
|
2017-07-26 01:51:44 -05:00
|
|
|
email_options = {
|
2019-01-18 03:52:48 -06:00
|
|
|
title: topic_title,
|
2016-01-26 19:19:49 -06:00
|
|
|
post: post,
|
2015-03-30 13:36:47 -05:00
|
|
|
username: original_username,
|
2019-01-04 09:06:21 -06:00
|
|
|
from_alias: I18n.t('email_from', user_name: user_name, site_name: Email.site_title),
|
2014-02-06 18:06:35 -06:00
|
|
|
allow_reply_by_email: allow_reply_by_email,
|
2016-02-22 18:34:16 -06:00
|
|
|
use_site_subject: opts[:use_site_subject],
|
|
|
|
add_re_to_subject: opts[:add_re_to_subject],
|
|
|
|
show_category_in_subject: opts[:show_category_in_subject],
|
2018-07-10 21:24:07 -05:00
|
|
|
show_tags_in_subject: opts[:show_tags_in_subject],
|
2018-02-19 03:20:17 -06:00
|
|
|
show_group_in_subject: opts[:show_group_in_subject],
|
2014-02-06 18:06:35 -06:00
|
|
|
notification_type: notification_type,
|
2016-03-25 07:26:52 -05:00
|
|
|
use_invite_template: opts[:use_invite_template],
|
2019-01-18 03:52:48 -06:00
|
|
|
use_topic_title_subject: use_topic_title_subject,
|
2014-02-06 18:06:35 -06:00
|
|
|
user: user
|
2017-07-26 01:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if group_id = notification_data[:group_id]
|
|
|
|
email_options[:group_name] = Group.find_by(id: group_id)&.name
|
|
|
|
end
|
|
|
|
|
|
|
|
send_notification_email(email_options)
|
2014-02-06 18:06:35 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def send_notification_email(opts)
|
|
|
|
post = opts[:post]
|
|
|
|
title = opts[:title]
|
2017-04-24 14:26:06 -05:00
|
|
|
|
2014-02-06 18:06:35 -06:00
|
|
|
allow_reply_by_email = opts[:allow_reply_by_email]
|
2014-09-29 00:16:55 -05:00
|
|
|
use_site_subject = opts[:use_site_subject]
|
|
|
|
add_re_to_subject = opts[:add_re_to_subject] && post.post_number > 1
|
2019-01-18 03:52:48 -06:00
|
|
|
use_topic_title_subject = opts[:use_topic_title_subject]
|
2014-10-21 09:06:55 -05:00
|
|
|
username = opts[:username]
|
2014-02-06 18:06:35 -06:00
|
|
|
from_alias = opts[:from_alias]
|
|
|
|
notification_type = opts[:notification_type]
|
|
|
|
user = opts[:user]
|
2017-07-26 01:51:44 -05:00
|
|
|
group_name = opts[:group_name]
|
2016-02-09 17:54:13 -06:00
|
|
|
locale = user_locale(user)
|
2014-02-06 18:06:35 -06:00
|
|
|
|
2019-05-02 17:17:27 -05:00
|
|
|
template = +"user_notifications.user_#{notification_type}"
|
2017-03-10 13:07:41 -06:00
|
|
|
if post.topic.private_message?
|
|
|
|
template << "_pm"
|
2017-07-26 01:51:44 -05:00
|
|
|
|
|
|
|
if group_name
|
|
|
|
template << "_group"
|
|
|
|
elsif user.staged
|
|
|
|
template << "_staged"
|
|
|
|
end
|
2017-03-10 13:07:41 -06:00
|
|
|
end
|
|
|
|
|
2014-10-03 06:44:08 -05:00
|
|
|
# category name
|
2018-05-17 00:19:01 -05:00
|
|
|
category = Topic.find_by(id: post.topic_id)&.category
|
2015-06-01 00:43:16 -05:00
|
|
|
if opts[:show_category_in_subject] && post.topic_id && category && !category.uncategorized?
|
2014-10-03 06:44:08 -05:00
|
|
|
show_category_in_subject = category.name
|
|
|
|
|
|
|
|
# subcategory case
|
|
|
|
if !category.parent_category_id.nil?
|
2019-10-21 05:32:27 -05:00
|
|
|
show_category_in_subject = "#{Category.where(id: category.parent_category_id).pluck_first(:name)}/#{show_category_in_subject}"
|
2014-10-03 06:44:08 -05:00
|
|
|
end
|
|
|
|
else
|
|
|
|
show_category_in_subject = nil
|
|
|
|
end
|
|
|
|
|
2018-07-10 21:24:07 -05:00
|
|
|
# tag names
|
|
|
|
if opts[:show_tags_in_subject] && post.topic_id
|
2018-07-10 21:38:11 -05:00
|
|
|
|
|
|
|
tags = Tag.joins(:topic_tags)
|
|
|
|
.where("topic_tags.topic_id = ?", post.topic_id)
|
|
|
|
.limit(3)
|
|
|
|
.pluck(:name)
|
|
|
|
|
|
|
|
show_tags_in_subject = tags.any? ? tags.join(" ") : nil
|
2018-07-10 21:24:07 -05:00
|
|
|
end
|
|
|
|
|
2021-06-02 23:47:32 -05:00
|
|
|
group = post.topic.allowed_groups&.first
|
|
|
|
|
2018-02-19 03:20:17 -06:00
|
|
|
if post.topic.private_message?
|
|
|
|
subject_pm =
|
2021-06-02 23:47:32 -05:00
|
|
|
if opts[:show_group_in_subject] && group.present?
|
2018-03-11 07:22:11 -05:00
|
|
|
if group.full_name
|
|
|
|
"[#{group.full_name}] "
|
|
|
|
else
|
|
|
|
"[#{group.name}] "
|
2018-02-19 03:20:17 -06:00
|
|
|
end
|
|
|
|
else
|
|
|
|
I18n.t('subject_pm')
|
|
|
|
end
|
2018-05-03 17:50:06 -05:00
|
|
|
|
2022-04-20 11:05:17 -05:00
|
|
|
participants = self.class.participants(post, user)
|
2018-02-19 03:20:17 -06:00
|
|
|
end
|
|
|
|
|
2017-04-24 14:26:06 -05:00
|
|
|
if SiteSetting.private_email?
|
|
|
|
title = I18n.t("system_messages.private_topic_title", id: post.topic_id)
|
|
|
|
end
|
|
|
|
|
2019-05-13 01:31:20 -05:00
|
|
|
context = +""
|
2014-02-06 18:06:35 -06:00
|
|
|
tu = TopicUser.get(post.topic_id, user)
|
2016-02-25 07:05:40 -06:00
|
|
|
context_posts = self.class.get_context_posts(post, tu, user)
|
2013-12-29 20:02:12 -06:00
|
|
|
|
|
|
|
# make .present? cheaper
|
|
|
|
context_posts = context_posts.to_a
|
|
|
|
|
2013-07-22 14:06:37 -05:00
|
|
|
if context_posts.present?
|
2019-05-13 03:23:05 -05:00
|
|
|
context << +"-- \n*#{I18n.t('user_notifications.previous_discussion')}*\n"
|
2013-07-22 14:06:37 -05:00
|
|
|
context_posts.each do |cp|
|
2019-05-08 10:27:03 -05:00
|
|
|
context << email_post_markdown(cp, true)
|
2013-07-22 14:06:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-26 01:51:44 -05:00
|
|
|
translation_override_exists = TranslationOverride.where(
|
|
|
|
locale: SiteSetting.default_locale,
|
|
|
|
translation_key: "#{template}.text_body_template"
|
|
|
|
).exists?
|
2016-03-22 23:08:34 -05:00
|
|
|
|
2016-03-25 07:26:52 -05:00
|
|
|
if opts[:use_invite_template]
|
2019-05-02 17:17:27 -05:00
|
|
|
invite_template = +"user_notifications.invited"
|
2019-05-08 10:27:03 -05:00
|
|
|
invite_template << "_group" if group_name
|
2017-07-26 01:51:44 -05:00
|
|
|
|
2019-05-08 10:27:03 -05:00
|
|
|
invite_template <<
|
2017-07-26 01:51:44 -05:00
|
|
|
if post.topic.private_message?
|
|
|
|
"_to_private_message_body"
|
|
|
|
else
|
|
|
|
"_to_topic_body"
|
|
|
|
end
|
|
|
|
|
2016-06-10 21:37:33 -05:00
|
|
|
topic_excerpt = post.excerpt.tr("\n", " ") if post.is_first_post? && post.excerpt
|
2019-10-16 02:20:30 -05:00
|
|
|
topic_url = post.topic&.url
|
|
|
|
|
|
|
|
if SiteSetting.private_email?
|
|
|
|
topic_excerpt = ""
|
|
|
|
topic_url = ""
|
|
|
|
end
|
2017-07-26 01:51:44 -05:00
|
|
|
|
|
|
|
message = I18n.t(invite_template,
|
|
|
|
username: username,
|
|
|
|
group_name: group_name,
|
|
|
|
topic_title: gsub_emoji_to_unicode(title),
|
|
|
|
topic_excerpt: topic_excerpt,
|
|
|
|
site_title: SiteSetting.title,
|
2019-10-16 01:56:36 -05:00
|
|
|
site_description: SiteSetting.site_description,
|
2019-10-16 02:20:30 -05:00
|
|
|
topic_url: topic_url
|
2017-07-26 01:51:44 -05:00
|
|
|
)
|
2017-03-10 13:07:41 -06:00
|
|
|
|
2019-07-30 14:05:08 -05:00
|
|
|
html = PrettyText.cook(message, sanitize: false).html_safe
|
2015-04-07 01:21:38 -05:00
|
|
|
else
|
2017-03-10 13:07:41 -06:00
|
|
|
reached_limit = SiteSetting.max_emails_per_day_per_user > 0
|
2018-07-26 23:32:07 -05:00
|
|
|
reached_limit &&= (EmailLog.where(user_id: user.id)
|
2017-03-10 13:07:41 -06:00
|
|
|
.where('created_at > ?', 1.day.ago)
|
2017-07-27 20:20:09 -05:00
|
|
|
.count) >= (SiteSetting.max_emails_per_day_per_user - 1)
|
2017-03-10 13:07:41 -06:00
|
|
|
|
2016-02-25 07:05:40 -06:00
|
|
|
in_reply_to_post = post.reply_to_post if user.user_option.email_in_reply_to
|
2017-04-24 14:26:06 -05:00
|
|
|
if SiteSetting.private_email?
|
|
|
|
message = I18n.t('system_messages.contents_hidden')
|
|
|
|
else
|
2018-12-03 21:48:13 -06:00
|
|
|
message = email_post_markdown(post) + (reached_limit ? "\n\n#{I18n.t "user_notifications.reached_limit", count: SiteSetting.max_emails_per_day_per_user}" : "")
|
2017-04-24 14:26:06 -05:00
|
|
|
end
|
|
|
|
|
2021-06-25 11:05:50 -05:00
|
|
|
first_footer_classes = "highlight"
|
2018-06-11 17:54:39 -05:00
|
|
|
if (allow_reply_by_email && user.staged) || (user.suspended? || user.staged?)
|
|
|
|
first_footer_classes = ""
|
|
|
|
end
|
|
|
|
|
2017-03-10 13:07:41 -06:00
|
|
|
unless translation_override_exists
|
2019-10-09 16:50:48 -05:00
|
|
|
html = UserNotificationRenderer.render(
|
2017-03-10 13:07:41 -06:00
|
|
|
template: 'email/notification',
|
|
|
|
format: :html,
|
|
|
|
locals: { context_posts: context_posts,
|
|
|
|
reached_limit: reached_limit,
|
|
|
|
post: post,
|
|
|
|
in_reply_to_post: in_reply_to_post,
|
2018-06-11 17:54:39 -05:00
|
|
|
classes: Rtl.new(user).css_class,
|
2021-06-27 19:42:06 -05:00
|
|
|
first_footer_classes: first_footer_classes,
|
|
|
|
reply_above_line: false
|
2017-03-10 13:07:41 -06:00
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
2015-12-09 12:45:46 -06:00
|
|
|
end
|
2013-07-24 02:13:15 -05:00
|
|
|
|
2013-02-27 17:30:14 -06:00
|
|
|
email_opts = {
|
2017-07-21 13:24:28 -05:00
|
|
|
topic_title: Emoji.gsub_emoji_to_unicode(title),
|
2019-12-11 20:49:21 -06:00
|
|
|
topic_title_url_encoded: title ? UrlHelper.encode_component(title) : title,
|
2016-03-25 07:26:52 -05:00
|
|
|
message: message,
|
2017-04-24 14:26:06 -05:00
|
|
|
url: post.url(without_slug: SiteSetting.private_email?),
|
2014-02-06 18:06:35 -06:00
|
|
|
post_id: post.id,
|
|
|
|
topic_id: post.topic_id,
|
2013-07-22 14:06:37 -05:00
|
|
|
context: context,
|
2014-10-21 09:06:55 -05:00
|
|
|
username: username,
|
2017-07-26 01:51:44 -05:00
|
|
|
group_name: group_name,
|
2021-06-27 17:55:13 -05:00
|
|
|
add_unsubscribe_link: !user.staged,
|
2016-06-03 08:48:54 -05:00
|
|
|
mailing_list_mode: user.user_option.mailing_list_mode,
|
2016-06-16 20:27:52 -05:00
|
|
|
unsubscribe_url: post.unsubscribe_url(user),
|
2014-02-06 18:06:35 -06:00
|
|
|
allow_reply_by_email: allow_reply_by_email,
|
2016-02-26 16:56:56 -06:00
|
|
|
only_reply_by_email: allow_reply_by_email && user.staged,
|
2014-09-29 00:16:55 -05:00
|
|
|
use_site_subject: use_site_subject,
|
|
|
|
add_re_to_subject: add_re_to_subject,
|
2014-10-03 06:44:08 -05:00
|
|
|
show_category_in_subject: show_category_in_subject,
|
2018-07-10 21:24:07 -05:00
|
|
|
show_tags_in_subject: show_tags_in_subject,
|
2014-06-06 08:09:00 -05:00
|
|
|
private_reply: post.topic.private_message?,
|
2018-02-19 03:20:17 -06:00
|
|
|
subject_pm: subject_pm,
|
2018-05-03 17:50:06 -05:00
|
|
|
participants: participants,
|
2016-04-11 12:06:10 -05:00
|
|
|
include_respond_instructions: !(user.suspended? || user.staged?),
|
2014-01-21 00:24:05 -06:00
|
|
|
template: template,
|
2019-01-18 03:52:48 -06:00
|
|
|
use_topic_title_subject: use_topic_title_subject,
|
2015-04-07 01:21:38 -05:00
|
|
|
site_description: SiteSetting.site_description,
|
|
|
|
site_title: SiteSetting.title,
|
2019-12-11 20:49:21 -06:00
|
|
|
site_title_url_encoded: UrlHelper.encode_component(SiteSetting.title),
|
2021-06-27 17:55:13 -05:00
|
|
|
locale: locale
|
2013-02-27 17:30:14 -06:00
|
|
|
}
|
|
|
|
|
2017-03-10 13:07:41 -06:00
|
|
|
unless translation_override_exists
|
|
|
|
email_opts[:html_override] = html
|
|
|
|
end
|
|
|
|
|
2013-02-27 17:30:14 -06:00
|
|
|
# If we have a display name, change the from address
|
2015-08-12 16:00:16 -05:00
|
|
|
email_opts[:from_alias] = from_alias if from_alias.present?
|
2013-02-27 17:30:14 -06:00
|
|
|
|
2014-02-06 18:06:35 -06:00
|
|
|
TopicUser.change(user.id, post.topic_id, last_emailed_post_number: post.post_number)
|
2013-12-29 20:02:12 -06:00
|
|
|
|
2013-06-10 15:46:08 -05:00
|
|
|
build_email(user.email, email_opts)
|
2013-02-07 09:45:24 -06:00
|
|
|
end
|
2016-05-21 08:17:54 -05:00
|
|
|
|
2022-04-20 11:05:17 -05:00
|
|
|
def self.participants(post, recipient_user, reveal_staged_email: false)
|
|
|
|
list = []
|
|
|
|
|
|
|
|
allowed_groups = post.topic.allowed_groups.order("user_count DESC")
|
|
|
|
|
|
|
|
allowed_groups.each do |g|
|
|
|
|
list.push("[#{g.name_full_preferred} (#{g.user_count})](#{g.full_url})")
|
|
|
|
break if list.size >= SiteSetting.max_participant_names
|
|
|
|
end
|
|
|
|
|
|
|
|
recent_posts_query = post.topic.posts
|
|
|
|
.select("user_id, MAX(post_number) AS post_number")
|
|
|
|
.where(post_type: Post.types[:regular], post_number: ..post.post_number)
|
|
|
|
.where.not(user_id: recipient_user.id)
|
|
|
|
.group(:user_id)
|
|
|
|
.order("post_number DESC")
|
|
|
|
.limit(SiteSetting.max_participant_names)
|
|
|
|
.to_sql
|
|
|
|
|
|
|
|
allowed_users = post.topic.allowed_users
|
|
|
|
.joins("LEFT JOIN (#{recent_posts_query}) pu ON topic_allowed_users.user_id = pu.user_id")
|
|
|
|
.order("post_number DESC NULLS LAST", :id)
|
|
|
|
.where.not(id: recipient_user.id)
|
|
|
|
.human_users
|
|
|
|
|
|
|
|
allowed_users.each do |u|
|
|
|
|
break if list.size >= SiteSetting.max_participant_names
|
|
|
|
|
|
|
|
if reveal_staged_email && u.staged?
|
|
|
|
list.push("#{u.email}")
|
|
|
|
else
|
|
|
|
list.push("[#{u.display_name}](#{u.full_url})")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
participants = list.join(I18n.t("word_connector.comma"))
|
|
|
|
others_count = allowed_groups.size + allowed_users.size - list.size
|
|
|
|
|
|
|
|
if others_count > 0
|
|
|
|
I18n.t("user_notifications.more_pm_participants", participants: participants, count: others_count)
|
|
|
|
else
|
|
|
|
participants
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-21 08:17:54 -05:00
|
|
|
private
|
|
|
|
|
2017-04-20 10:17:24 -05:00
|
|
|
def build_user_email_token_by_template(template, user, email_token)
|
|
|
|
build_email(
|
|
|
|
user.email,
|
|
|
|
template: template,
|
|
|
|
locale: user_locale(user),
|
|
|
|
email_token: email_token
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2016-05-21 08:17:54 -05:00
|
|
|
def build_summary_for(user)
|
2017-04-28 09:37:52 -05:00
|
|
|
@site_name = SiteSetting.email_prefix.presence || SiteSetting.title # used by I18n
|
2016-05-21 08:17:54 -05:00
|
|
|
@user = user
|
|
|
|
@date = short_date(Time.now)
|
|
|
|
@base_url = Discourse.base_url
|
2017-03-21 08:11:15 -05:00
|
|
|
@email_prefix = SiteSetting.email_prefix.presence || SiteSetting.title
|
2016-11-10 17:16:24 -06:00
|
|
|
@header_color = ColorScheme.hex_for_name('header_primary')
|
|
|
|
@header_bgcolor = ColorScheme.hex_for_name('header_background')
|
2016-05-21 08:17:54 -05:00
|
|
|
@anchor_color = ColorScheme.hex_for_name('tertiary')
|
|
|
|
@markdown_linker = MarkdownLinker.new(@base_url)
|
2016-06-16 20:27:52 -05:00
|
|
|
@unsubscribe_key = UnsubscribeKey.create_key_for(@user, "digest")
|
2019-07-30 14:05:08 -05:00
|
|
|
@disable_email_custom_styles = !SiteSetting.apply_custom_styles_to_digest
|
2016-06-21 10:12:30 -05:00
|
|
|
end
|
2019-10-25 15:33:05 -05:00
|
|
|
|
|
|
|
def self.summary_new_users_count_key(min_date_str)
|
|
|
|
"summary-new-users:#{min_date_str}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def summary_new_users_count(min_date)
|
|
|
|
min_date_str = min_date.is_a?(String) ? min_date : min_date.strftime('%Y-%m-%d')
|
|
|
|
key = self.class.summary_new_users_count_key(min_date_str)
|
2019-12-03 03:05:53 -06:00
|
|
|
((count = Discourse.redis.get(key)) && count.to_i) || begin
|
2019-10-25 15:33:05 -05:00
|
|
|
count = User.real.where(active: true, staged: false).not_suspended.where("created_at > ?", min_date_str).count
|
2019-12-03 03:05:53 -06:00
|
|
|
Discourse.redis.setex(key, 1.day, count)
|
2019-10-25 15:33:05 -05:00
|
|
|
count
|
|
|
|
end
|
|
|
|
end
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|