Archived
remove comment mention mail, use reply mail instead
This commit is contained in:
@@ -18,7 +18,6 @@ class CommentsController < ApplicationController
|
|||||||
@comment.blogpost = Blogpost.find(params[:blogpost_id])
|
@comment.blogpost = Blogpost.find(params[:blogpost_id])
|
||||||
if @comment.save
|
if @comment.save
|
||||||
@comment.send_new_comment_mail
|
@comment.send_new_comment_mail
|
||||||
@comment.send_new_mention_mail
|
|
||||||
position = @comment.blogpost.comments.count - 1
|
position = @comment.blogpost.comments.count - 1
|
||||||
page = position / Kaminari.config.default_per_page + 1
|
page = position / Kaminari.config.default_per_page + 1
|
||||||
redirect_to blogpost_path(@comment.blogpost, page: page) + "#comment-#{@comment.id}", notice: 'Comment created!'
|
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
|
@comment.attributes = comment_params
|
||||||
old_content = @comment.content_was
|
old_content = @comment.content_was
|
||||||
if @comment.save
|
if @comment.save
|
||||||
@comment.send_new_mention_mail(old_content)
|
@comment.send_new_comment_mail(old_content)
|
||||||
flash[:notice] = "Comment updated!"
|
flash[:notice] = "Comment updated!"
|
||||||
position = @comment.blogpost.comments.index(@comment)
|
position = @comment.blogpost.comments.index(@comment)
|
||||||
page = position / Kaminari.config.default_per_page + 1
|
page = position / Kaminari.config.default_per_page + 1
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ module UsersHelper
|
|||||||
require "open-uri"
|
require "open-uri"
|
||||||
|
|
||||||
def mentions(content)
|
def mentions(content)
|
||||||
|
users = []
|
||||||
words = content.scan(/@[a-zA-Z0-9_]{1,16}/)
|
words = content.scan(/@[a-zA-Z0-9_]{1,16}/)
|
||||||
words.map! do |w|
|
words.each do |w|
|
||||||
w[0] = ""
|
puts w.inspect
|
||||||
w
|
user = User.find_by_ign(w[1..-1])
|
||||||
|
users << user if user && user.normal? && user.confirmed? && user.mail_mention?
|
||||||
end
|
end
|
||||||
User.where(ign: words).uniq!
|
users
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_youtube(yt_name)
|
def get_youtube(yt_name)
|
||||||
|
|||||||
@@ -46,12 +46,6 @@ class RedstonerMailer < ActionMailer::Base
|
|||||||
mail(to: @user.email, subject: "#{comment.author.name} replied to '#{comment.blogpost.title}' on Redstoner")
|
mail(to: @user.email, subject: "#{comment.author.name} replied to '#{comment.blogpost.title}' on Redstoner")
|
||||||
end
|
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)
|
def email_change_confirm_mail(user)
|
||||||
@user = user
|
@user = user
|
||||||
mail(to: @user.email, subject: "Email change on Redstoner.com")
|
mail(to: @user.email, subject: "Email change on Redstoner.com")
|
||||||
|
|||||||
+7
-17
@@ -29,18 +29,23 @@ class Comment < ActiveRecord::Base
|
|||||||
!!user_editor_id
|
!!user_editor_id
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_new_comment_mail
|
def send_new_comment_mail(old_content = "")
|
||||||
userids = []
|
userids = mentions(content) - mentions(old_content)
|
||||||
|
|
||||||
|
puts "userids: #{userids}"
|
||||||
|
|
||||||
# post + comments
|
# post + comments
|
||||||
comments = blogpost.comments.to_a
|
comments = blogpost.comments.to_a
|
||||||
comments << blogpost if blogpost.author.mail_own_blogpost_comment?
|
comments << blogpost if blogpost.author.mail_own_blogpost_comment?
|
||||||
|
# only send "reply" mails when the comment is new
|
||||||
|
unless old_content.present?
|
||||||
comments.each do |comment|
|
comments.each do |comment|
|
||||||
# don't send mail to the author of this comment, don't send to banned/disabled users
|
# 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? # &&
|
if comment.author != author && comment.author.normal? && comment.author.confirmed? # &&
|
||||||
userids << comment.author.id if comment.author.mail_other_blogpost_comment?
|
userids << comment.author.id if comment.author.mail_other_blogpost_comment?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
# making sure we don't send multiple mails to the same user
|
# making sure we don't send multiple mails to the same user
|
||||||
userids.uniq!
|
userids.uniq!
|
||||||
|
|
||||||
@@ -58,19 +63,4 @@ class Comment < ActiveRecord::Base
|
|||||||
background_mailer(mails)
|
background_mailer(mails)
|
||||||
end
|
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
|
end
|
||||||
@@ -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>
|
|
||||||
@@ -50,13 +50,6 @@ class AllPreview < ActionMailer::Preview
|
|||||||
RedstonerMailer.new_post_comment_mail(@@user, comment)
|
RedstonerMailer.new_post_comment_mail(@@user, comment)
|
||||||
end
|
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
|
def email_change_confirm_mail
|
||||||
RedstonerMailer.email_change_confirm_mail(@@user)
|
RedstonerMailer.email_change_confirm_mail(@@user)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user