|
|
|
|
@@ -11,14 +11,14 @@ class UserNotifications < ActionMailer::Base
|
|
|
|
|
|
|
|
|
|
include Email::BuildEmailHelper
|
|
|
|
|
|
|
|
|
|
def signup(user, opts={})
|
|
|
|
|
def signup(user, opts = {})
|
|
|
|
|
build_email(user.email,
|
|
|
|
|
template: "user_notifications.signup",
|
|
|
|
|
locale: user_locale(user),
|
|
|
|
|
email_token: opts[:email_token])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def signup_after_approval(user, opts={})
|
|
|
|
|
def signup_after_approval(user, opts = {})
|
|
|
|
|
build_email(user.email,
|
|
|
|
|
template: 'user_notifications.signup_after_approval',
|
|
|
|
|
locale: user_locale(user),
|
|
|
|
|
@@ -26,42 +26,42 @@ class UserNotifications < ActionMailer::Base
|
|
|
|
|
new_user_tips: I18n.t('system_messages.usage_tips.text_body_template', base_url: Discourse.base_url, locale: locale))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def notify_old_email(user, opts={})
|
|
|
|
|
def notify_old_email(user, opts = {})
|
|
|
|
|
build_email(user.email,
|
|
|
|
|
template: "user_notifications.notify_old_email",
|
|
|
|
|
locale: user_locale(user),
|
|
|
|
|
new_email: opts[:new_email])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def confirm_old_email(user, opts={})
|
|
|
|
|
def confirm_old_email(user, opts = {})
|
|
|
|
|
build_email(user.email,
|
|
|
|
|
template: "user_notifications.confirm_old_email",
|
|
|
|
|
locale: user_locale(user),
|
|
|
|
|
email_token: opts[:email_token])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def confirm_new_email(user, opts={})
|
|
|
|
|
def confirm_new_email(user, opts = {})
|
|
|
|
|
build_email(user.email,
|
|
|
|
|
template: "user_notifications.confirm_new_email",
|
|
|
|
|
locale: user_locale(user),
|
|
|
|
|
email_token: opts[:email_token])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def forgot_password(user, opts={})
|
|
|
|
|
def forgot_password(user, opts = {})
|
|
|
|
|
build_email(user.email,
|
|
|
|
|
template: user.has_password? ? "user_notifications.forgot_password" : "user_notifications.set_password",
|
|
|
|
|
locale: user_locale(user),
|
|
|
|
|
email_token: opts[:email_token])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def admin_login(user, opts={})
|
|
|
|
|
def admin_login(user, opts = {})
|
|
|
|
|
build_email(user.email,
|
|
|
|
|
template: "user_notifications.admin_login",
|
|
|
|
|
locale: user_locale(user),
|
|
|
|
|
email_token: opts[:email_token])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def account_created(user, opts={})
|
|
|
|
|
def account_created(user, opts = {})
|
|
|
|
|
build_email(user.email,
|
|
|
|
|
template: "user_notifications.account_created",
|
|
|
|
|
locale: user_locale(user),
|
|
|
|
|
@@ -76,30 +76,30 @@ class UserNotifications < ActionMailer::Base
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def digest(user, opts={})
|
|
|
|
|
def digest(user, opts = {})
|
|
|
|
|
build_summary_for(user)
|
|
|
|
|
min_date = opts[:since] || user.last_emailed_at || user.last_seen_at || 1.month.ago
|
|
|
|
|
|
|
|
|
|
# Fetch some topics and posts to show
|
|
|
|
|
digest_opts = {limit: SiteSetting.digest_topics + SiteSetting.digest_other_topics, top_order: true}
|
|
|
|
|
digest_opts = { limit: SiteSetting.digest_topics + SiteSetting.digest_other_topics, top_order: true }
|
|
|
|
|
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)
|
|
|
|
|
# Find some topics from new users that are at least 24 hours old
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
@popular_topics = topics_for_digest[0,SiteSetting.digest_topics]
|
|
|
|
|
@popular_topics = topics_for_digest[0, SiteSetting.digest_topics]
|
|
|
|
|
|
|
|
|
|
if @popular_topics.present?
|
|
|
|
|
@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")
|
|
|
|
|
.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)
|
|
|
|
|
.limit(SiteSetting.digest_posts)
|
|
|
|
|
.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)
|
|
|
|
|
.limit(SiteSetting.digest_posts)
|
|
|
|
|
else
|
|
|
|
|
[]
|
|
|
|
|
end
|
|
|
|
|
@@ -117,19 +117,19 @@ class UserNotifications < ActionMailer::Base
|
|
|
|
|
# We used topics from new users instead, so count should match
|
|
|
|
|
new_topics_count = topics_for_digest.size
|
|
|
|
|
end
|
|
|
|
|
@counts = [{label_key: 'user_notifications.digest.new_topics',
|
|
|
|
|
value: new_topics_count,
|
|
|
|
|
href: "#{Discourse.base_url}/new"}]
|
|
|
|
|
@counts = [{ label_key: 'user_notifications.digest.new_topics',
|
|
|
|
|
value: new_topics_count,
|
|
|
|
|
href: "#{Discourse.base_url}/new" }]
|
|
|
|
|
|
|
|
|
|
value = user.unread_notifications
|
|
|
|
|
@counts << {label_key: 'user_notifications.digest.unread_notifications', value: value, href: "#{Discourse.base_url}/my/notifications"} if value > 0
|
|
|
|
|
@counts << { label_key: 'user_notifications.digest.unread_notifications', value: value, href: "#{Discourse.base_url}/my/notifications" } if value > 0
|
|
|
|
|
|
|
|
|
|
value = user.unread_private_messages
|
|
|
|
|
@counts << {label_key: 'user_notifications.digest.unread_messages', value: value, href: "#{Discourse.base_url}/my/messages"} if value > 0
|
|
|
|
|
@counts << { label_key: 'user_notifications.digest.unread_messages', value: value, href: "#{Discourse.base_url}/my/messages" } if value > 0
|
|
|
|
|
|
|
|
|
|
if @counts.size < 3
|
|
|
|
|
value = user.unread_notifications_of_type(Notification.types[:liked])
|
|
|
|
|
@counts << {label_key: 'user_notifications.digest.liked_received', value: value, href: "#{Discourse.base_url}/my/notifications"} if value > 0
|
|
|
|
|
@counts << { label_key: 'user_notifications.digest.liked_received', value: value, href: "#{Discourse.base_url}/my/notifications" } if value > 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if @counts.size < 3
|
|
|
|
|
@@ -157,7 +157,6 @@ class UserNotifications < ActionMailer::Base
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def user_replied(user, opts)
|
|
|
|
|
opts[:allow_reply_by_email] = true
|
|
|
|
|
opts[:use_site_subject] = true
|
|
|
|
|
@@ -252,7 +251,7 @@ class UserNotifications < ActionMailer::Base
|
|
|
|
|
(user.locale.present? && I18n.available_locales.include?(user.locale.to_sym)) ? user.locale : nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def email_post_markdown(post, add_posted_by=false)
|
|
|
|
|
def email_post_markdown(post, add_posted_by = false)
|
|
|
|
|
result = "#{post.raw}\n\n"
|
|
|
|
|
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"
|
|
|
|
|
@@ -275,12 +274,12 @@ class UserNotifications < ActionMailer::Base
|
|
|
|
|
allowed_post_types << Post.types[:whisper] if topic_user.try(:user).try(:staff?)
|
|
|
|
|
|
|
|
|
|
context_posts = Post.where(topic_id: post.topic_id)
|
|
|
|
|
.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)
|
|
|
|
|
.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)
|
|
|
|
|
|
|
|
|
|
if topic_user && topic_user.last_emailed_post_number && user.user_option.email_previous_replies == UserOption.previous_replies_type[:unless_emailed]
|
|
|
|
|
context_posts = context_posts.where("post_number > ?", topic_user.last_emailed_post_number)
|
|
|
|
|
@@ -429,7 +428,7 @@ class UserNotifications < ActionMailer::Base
|
|
|
|
|
reached_limit = SiteSetting.max_emails_per_day_per_user > 0
|
|
|
|
|
reached_limit &&= (EmailLog.where(user_id: user.id, skipped: false)
|
|
|
|
|
.where('created_at > ?', 1.day.ago)
|
|
|
|
|
.count) >= (SiteSetting.max_emails_per_day_per_user-1)
|
|
|
|
|
.count) >= (SiteSetting.max_emails_per_day_per_user - 1)
|
|
|
|
|
|
|
|
|
|
in_reply_to_post = post.reply_to_post if user.user_option.email_in_reply_to
|
|
|
|
|
if SiteSetting.private_email?
|
|
|
|
|
@@ -438,7 +437,6 @@ class UserNotifications < ActionMailer::Base
|
|
|
|
|
message = email_post_markdown(post) + (reached_limit ? "\n\n#{I18n.t "user_notifications.reached_limit", count: SiteSetting.max_emails_per_day_per_user}" : "");
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unless translation_override_exists
|
|
|
|
|
html = UserNotificationRenderer.new(Rails.configuration.paths["app/views"]).render(
|
|
|
|
|
template: 'email/notification',
|
|
|
|
|
|