remove comment mention mail, use reply mail instead

This commit is contained in:
jomo
2015-02-08 01:18:09 +01:00
parent f82af96759
commit 05760b845c
6 changed files with 18 additions and 73 deletions

View File

@@ -18,7 +18,6 @@ class CommentsController < ApplicationController
@comment.blogpost = Blogpost.find(params[:blogpost_id])
if @comment.save
@comment.send_new_comment_mail
@comment.send_new_mention_mail
position = @comment.blogpost.comments.count - 1
page = position / Kaminari.config.default_per_page + 1
redirect_to blogpost_path(@comment.blogpost, page: page) + "#comment-#{@comment.id}", notice: 'Comment created!'
@@ -39,7 +38,7 @@ class CommentsController < ApplicationController
@comment.attributes = comment_params
old_content = @comment.content_was
if @comment.save
@comment.send_new_mention_mail(old_content)
@comment.send_new_comment_mail(old_content)
flash[:notice] = "Comment updated!"
position = @comment.blogpost.comments.index(@comment)
page = position / Kaminari.config.default_per_page + 1

View File

@@ -2,12 +2,14 @@ module UsersHelper
require "open-uri"
def mentions(content)
users = []
words = content.scan(/@[a-zA-Z0-9_]{1,16}/)
words.map! do |w|
w[0] = ""
w
words.each do |w|
puts w.inspect
user = User.find_by_ign(w[1..-1])
users << user if user && user.normal? && user.confirmed? && user.mail_mention?
end
User.where(ign: words).uniq!
users
end
def get_youtube(yt_name)

View File

@@ -46,12 +46,6 @@ class RedstonerMailer < ActionMailer::Base
mail(to: @user.email, subject: "#{comment.author.name} replied to '#{comment.blogpost.title}' on Redstoner")
end
def new_post_comment_mention_mail(user, comment)
@user = user
@comment = comment
mail(to: @user.email, subject: "#{comment.author.name} mentioned you in '#{comment.blogpost.title}' on Redstoner")
end
def email_change_confirm_mail(user)
@user = user
mail(to: @user.email, subject: "Email change on Redstoner.com")

View File

@@ -29,16 +29,21 @@ class Comment < ActiveRecord::Base
!!user_editor_id
end
def send_new_comment_mail
userids = []
def send_new_comment_mail(old_content = "")
userids = mentions(content) - mentions(old_content)
puts "userids: #{userids}"
# post + comments
comments = blogpost.comments.to_a
comments << blogpost if blogpost.author.mail_own_blogpost_comment?
comments.each do |comment|
# don't send mail to the author of this comment, don't send to banned/disabled users
if comment.author != author && comment.author.normal? && comment.author.confirmed? # &&
userids << comment.author.id if comment.author.mail_other_blogpost_comment?
# only send "reply" mails when the comment is new
unless old_content.present?
comments.each do |comment|
# don't send mail to the author of this comment, don't send to banned/disabled users
if comment.author != author && comment.author.normal? && comment.author.confirmed? # &&
userids << comment.author.id if comment.author.mail_other_blogpost_comment?
end
end
end
# making sure we don't send multiple mails to the same user
@@ -58,19 +63,4 @@ class Comment < ActiveRecord::Base
background_mailer(mails)
end
def send_new_mention_mail(old_content = "")
new_mentions = mentions(content) - mentions(old_content)
mails = []
new_mentions.each do |user|
begin
mails << RedstonerMailer.new_post_comment_mention_mail(user, self) if user.normal? && user.confirmed? && user.mail_mention?
rescue => e
Rails.logger.error "---"
Rails.logger.error "WARNING: Failed to create new_post_comment_mention_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

View File

@@ -1,33 +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 0; margin: auto;">
Hi <%= @user.name %>!
<p><%= link_to @comment.author.name, user_url(@comment.author), style: "text-decoration: none; color: #4096EE;" %> has mentioned you in '<%= @comment.blogpost.title %>' on the Redstoner blog!</p>
<blockquote>
<%= render_md(@comment.content).html_safe %>
</blockquote>
<%
position = @comment.blogpost.comments.count - 1
page = position / Kaminari.config.default_per_page + 1
%>
<p><%= link_to "Click here", blogpost_url(@comment.blogpost, page: page) + "#comment-#{@comment.id}", style: "text-decoration: none; color: #4096EE;" %> to view the blog post.</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%; color: #fff; margin: auto; text-align: center; display: inline-block;">
<div style="margin: 2em;">
<p><i>Too much spam? Change <%= link_to "your notification settings", edit_notifications_user_url(@user), style: "text-decoration: none; color: #4096EE;" %>!</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>
</div>

View File

@@ -50,13 +50,6 @@ class AllPreview < ActionMailer::Preview
RedstonerMailer.new_post_comment_mail(@@user, comment)
end
def new_post_comment_mention_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: "@mention Wow, that is **cool**!", blogpost: post)
RedstonerMailer.new_post_comment_mail(@@user, comment)
end
def email_change_confirm_mail
RedstonerMailer.email_change_confirm_mail(@@user)
end