add info mail for new blog comments
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
class CommentsController < ApplicationController
|
||||
|
||||
include MailerHelper
|
||||
|
||||
def edit
|
||||
@comment = Comment.find(params[:id])
|
||||
if mod? || @comment.author.is?(current_user)
|
||||
@@ -15,6 +17,7 @@ class CommentsController < ApplicationController
|
||||
@comment.user_author = current_user
|
||||
@comment.blogpost = Blogpost.find(params[:blogpost_id])
|
||||
if @comment.save
|
||||
@comment.send_new_comment_mail
|
||||
redirect_to blogpost_path(@comment.blogpost) + "#comment-#{@comment.id}", notice: 'Comment created!'
|
||||
else
|
||||
flash[:alert] = "Could not create comment."
|
||||
|
||||
@@ -16,12 +16,18 @@ class RedstonerMailer < ActionMailer::Base
|
||||
mail(to: "redstonerserver@gmail.com", subject: "#{@user.name} registered on Redstoner")
|
||||
end
|
||||
|
||||
def thread_reply_mail(user, reply)
|
||||
def new_thread_reply_mail(user, reply)
|
||||
@user = user
|
||||
@reply = reply
|
||||
mail(to: @user.email, subject: "#{reply.author.name} replied to '#{reply.thread.title}' on Redstoner")
|
||||
end
|
||||
|
||||
def new_post_comment_mail(user, comment)
|
||||
@user = user
|
||||
@comment = comment
|
||||
mail(to: @user.email, subject: "#{comment.author.name} replied to '#{comment.blogpost.title}' on Redstoner")
|
||||
end
|
||||
|
||||
def email_change_confirm_mail(user)
|
||||
@user = user
|
||||
mail(to: @user.email, subject: "Email change on Redstoner.com")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
class Comment < ActiveRecord::Base
|
||||
|
||||
include MailerHelper
|
||||
|
||||
belongs_to :user_author, class_name: "User", foreign_key: "user_author_id"
|
||||
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
|
||||
|
||||
@@ -25,4 +27,33 @@ class Comment < ActiveRecord::Base
|
||||
def edited?
|
||||
!!user_editor_id
|
||||
end
|
||||
|
||||
def send_new_comment_mail
|
||||
userids = []
|
||||
|
||||
# thread + replies
|
||||
posts = blogpost.comments.to_a
|
||||
posts << blogpost # if thread.author.send_own_post_comment_mail (TODO)
|
||||
posts.each do |post|
|
||||
# don't send mail to the author, don't send to banned/disabled users
|
||||
if post.author != author && post.author.normal? && post.author.confirmed? # &&
|
||||
userids << post.author.id # && post.author.send_commented_comment_mail (TODO)
|
||||
end
|
||||
end
|
||||
# making sure we don't send multiple mails to the same user
|
||||
userids.uniq!
|
||||
|
||||
mails = []
|
||||
userids.each do |uid|
|
||||
begin
|
||||
mails << RedstonerMailer.new_post_comment_mail(User.find(uid), self)
|
||||
rescue => e
|
||||
Rails.logger.error "---"
|
||||
Rails.logger.error "WARNING: Failed to create thread_reply mail (view) for reply#: #{@self.id}, user: #{@user.name}, #{@user.email}"
|
||||
Rails.logger.error e.message
|
||||
Rails.logger.error "---"
|
||||
end
|
||||
end
|
||||
background_mailer(mails)
|
||||
end
|
||||
end
|
||||
@@ -50,7 +50,7 @@ class Threadreply < ActiveRecord::Base
|
||||
mails = []
|
||||
userids.each do |uid|
|
||||
begin
|
||||
mails << RedstonerMailer.thread_reply_mail(User.find(uid), self)
|
||||
mails << RedstonerMailer.new_thread_reply_mail(User.find(uid), self)
|
||||
rescue => e
|
||||
Rails.logger.error "---"
|
||||
Rails.logger.error "WARNING: Failed to create thread_reply mail (view) for reply#: #{@self.id}, user: #{@user.name}, #{@user.email}"
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<div style="font-family: 'Oswald','Calibri','Arial','DejaVu Sans','Open Sans','Lucida Sans','Lucida Grande','Lucida Sans Unicode',sans-serif; background: #F2F2F2">
|
||||
<div style="color: #3f3f3f; width: 600px; max-width: 100%; padding: 2em; margin: auto;">
|
||||
Hi <%= @user.name %>!
|
||||
|
||||
<p><%= link_to @reply.author.name, user_url(@reply.author), style: "text-decoration: none; color: #4096EE;" %> has replied to '<%= @reply.thread.title %>' on the Redstoner forums!</p>
|
||||
|
||||
<blockquote>
|
||||
<%# TODO: fix relative links + iframes %>
|
||||
<%= render_md(@reply.content).html_safe %>
|
||||
</blockquote>
|
||||
|
||||
<p><%= link_to "Click here", forumthread_url(@reply.thread) + "#reply-#{@reply.id}", style: "text-decoration: none; color: #4096EE;" %> to view the thread.</p>
|
||||
|
||||
<p>If you have any questions or problems, just ask one of our <%= link_to "Staff", users_url(role: "staff"), style: "text-decoration: none; color: #4096EE;" %> in-game or on the forums!</p>
|
||||
<p>Your Redstoner team</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div style="background: #444; width: 100%; padding: 2em; color: #fff; margin: auto; text-align: center;">
|
||||
<p><i>You cannot (yet) unsubscribe from these mails, sorry about that. Will add this ASAP!</i>
|
||||
</p>
|
||||
<p>You can contact us via:
|
||||
<%= link_to "Website", root_url, style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Twitter", "https://twitter.com/RedstonerServer", style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Google+", "https://google.com/+Redstoner", style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Email", "mailto:redstonerserver+website@gmail.com", style: "text-decoration: none; color: #4096EE;" %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -17,11 +17,18 @@ class RegistrationPreview < ActionMailer::Preview
|
||||
RedstonerMailer.register_info_mail(@@user, true)
|
||||
end
|
||||
|
||||
def thread_reply_mail
|
||||
def new_thread_reply_mail
|
||||
op = User.new(id: 32, name: "TheOP", email: "theopuser@example.com")
|
||||
thread = Forumthread.new(id: 123, user_author: op, title: "Wow, test thread!", content: "You should not see this...")
|
||||
reply = Threadreply.new(id: 312, user_author: @@user, content: "# Markdown!\n\n`incline code`\n\n<b>html?</b>\n\n[yt:abcd1234]\n\n[link](/forums)", forumthread: thread)
|
||||
RedstonerMailer.thread_reply_mail(@@user, reply)
|
||||
RedstonerMailer.new_thread_reply_mail(@@user, reply)
|
||||
end
|
||||
|
||||
def new_post_comment_mail
|
||||
op = User.new(id: 32, name: "TheOP", email: "theopuser@example.com")
|
||||
post = Blogpost.new(id: 123, user_author: op, title: "Wow, test post!", content: "You should not see this...")
|
||||
comment = Comment.new(id: 312, user_author: @@user, content: "Wow, that is **cool**!", blogpost: post)
|
||||
RedstonerMailer.new_post_comment_mail(@@user, comment)
|
||||
end
|
||||
|
||||
def email_change_confirm_mail
|
||||
|
||||
Reference in New Issue
Block a user