diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index a8b9d33..48fabf6 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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." diff --git a/app/mailers/redstoner_mailer.rb b/app/mailers/redstoner_mailer.rb index 1e2d50f..aa0ff26 100644 --- a/app/mailers/redstoner_mailer.rb +++ b/app/mailers/redstoner_mailer.rb @@ -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") diff --git a/app/models/comment.rb b/app/models/comment.rb index 80bd530..616ed06 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 \ No newline at end of file diff --git a/app/models/threadreply.rb b/app/models/threadreply.rb index c013a10..901c957 100644 --- a/app/models/threadreply.rb +++ b/app/models/threadreply.rb @@ -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}" diff --git a/app/views/redstoner_mailer/thread_reply_mail.html.erb b/app/views/redstoner_mailer/thread_reply_mail.html.erb deleted file mode 100644 index d6bfa85..0000000 --- a/app/views/redstoner_mailer/thread_reply_mail.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -
<%= 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!
- -- <%# TODO: fix relative links + iframes %> - <%= render_md(@reply.content).html_safe %> -- -
<%= link_to "Click here", forumthread_url(@reply.thread) + "#reply-#{@reply.id}", style: "text-decoration: none; color: #4096EE;" %> to view the thread.
- -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!
-Your Redstoner team
- -You cannot (yet) unsubscribe from these mails, sorry about that. Will add this ASAP! -
-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;" %> -
-