diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index be0783e..49975cd 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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 diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 1747586..e3fca56 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -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) diff --git a/app/mailers/redstoner_mailer.rb b/app/mailers/redstoner_mailer.rb index 401ad96..553dd6a 100644 --- a/app/mailers/redstoner_mailer.rb +++ b/app/mailers/redstoner_mailer.rb @@ -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") diff --git a/app/models/comment.rb b/app/models/comment.rb index 1ae3b8b..6f6439b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 \ No newline at end of file diff --git a/app/views/redstoner_mailer/new_post_comment_mention_mail.html.erb b/app/views/redstoner_mailer/new_post_comment_mention_mail.html.erb deleted file mode 100644 index f33b2fd..0000000 --- a/app/views/redstoner_mailer/new_post_comment_mention_mail.html.erb +++ /dev/null @@ -1,33 +0,0 @@ -
<%= 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!
- -- <%= render_md(@comment.content).html_safe %> -- - <% - position = @comment.blogpost.comments.count - 1 - page = position / Kaminari.config.default_per_page + 1 - %> -
<%= link_to "Click here", blogpost_url(@comment.blogpost, page: page) + "#comment-#{@comment.id}", style: "text-decoration: none; color: #4096EE;" %> to view the blog post.
- -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
- -Too much spam? Change <%= link_to "your notification settings", edit_notifications_user_url(@user), style: "text-decoration: none; color: #4096EE;" %>!
-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;" %> -
-