minor cleanups after last merge
This commit is contained in:
parent
17d8213bc7
commit
cb5e05c461
|
@ -12,7 +12,8 @@ class Comment < ActiveRecord::Base
|
|||
:indent_level, :highlighted
|
||||
|
||||
before_create :assign_short_id_and_upvote, :assign_initial_confidence
|
||||
after_create :assign_votes, :mark_submitter, :deliver_reply_notifications, :deliver_mention_notifications
|
||||
after_create :assign_votes, :mark_submitter, :deliver_reply_notifications,
|
||||
:deliver_mention_notifications
|
||||
after_destroy :unassign_votes
|
||||
|
||||
MAX_EDIT_MINS = 45
|
||||
|
@ -99,26 +100,33 @@ class Comment < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def deliver_mention_notifications
|
||||
self[:comment].gsub(/\B\@([\w\-]+)/) do |u|
|
||||
if user = User.find_by_username(u[1..-1])
|
||||
if user.email_mentions?
|
||||
EmailReply.mention(self, user).deliver
|
||||
end
|
||||
if user.pushover_mentions? && user.pushover_user_key.present?
|
||||
Pushover.push(user.pushover_user_key, user.pushover_device, {
|
||||
:title => "Lobsters mention by #{self.user.username} on #{self.story.title}",
|
||||
:message => self.plaintext_comment,
|
||||
:url => self.url,
|
||||
:url_title => "Reply to #{self.user.username}",
|
||||
})
|
||||
self.plaintext_comment.scan(/\B\@([\w\-]+)/).flatten.uniq.each do |mention|
|
||||
if u = User.find_by_username(mention)
|
||||
begin
|
||||
if u.email_mentions?
|
||||
EmailReply.mention(self, u).deliver
|
||||
end
|
||||
|
||||
if u.pushover_mentions? && u.pushover_user_key.present?
|
||||
Pushover.push(u.pushover_user_key, u.pushover_device, {
|
||||
:title => "Lobsters mention by #{self.user.username} on " <<
|
||||
self.story.title,
|
||||
:message => self.plaintext_comment,
|
||||
:url => self.url,
|
||||
:url_title => "Reply to #{self.user.username}",
|
||||
})
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.error "failed to deliver mention notification to " <<
|
||||
"#{u.username}: #{e.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def deliver_reply_notifications
|
||||
begin
|
||||
if self.parent_comment_id && u = self.parent_comment.try(:user)
|
||||
if self.parent_comment_id && u = self.parent_comment.try(:user)
|
||||
begin
|
||||
if u.email_replies?
|
||||
EmailReply.reply(self, u).deliver
|
||||
end
|
||||
|
@ -132,8 +140,10 @@ class Comment < ActiveRecord::Base
|
|||
:url_title => "Reply to #{self.user.username}",
|
||||
})
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.error "failed to deliver reply notification to " <<
|
||||
"#{u.username}: #{e.message}"
|
||||
end
|
||||
rescue
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -78,8 +78,7 @@
|
|||
</div>
|
||||
|
||||
<div class="boxline">
|
||||
<%= f.label :pushover_replies,
|
||||
raw("Receive <a href=\"https://pushover.net/\">Pushover</a> Alert:"),
|
||||
<%= f.label :pushover_replies, "Receive Pushover Alert:",
|
||||
:class => "required" %>
|
||||
<%= f.check_box :pushover_replies %>
|
||||
<span class="hint">
|
||||
|
@ -99,8 +98,7 @@
|
|||
</div>
|
||||
|
||||
<div class="boxline">
|
||||
<%= f.label :pushover_mentions,
|
||||
raw("Receive <a href=\"https://pushover.net/\">Pushover</a> Alert:"),
|
||||
<%= f.label :pushover_mentions, "Receive Pushover Alert:",
|
||||
:class => "required" %>
|
||||
<%= f.check_box :pushover_mentions %>
|
||||
<span class="hint">
|
||||
|
@ -120,8 +118,7 @@
|
|||
</div>
|
||||
|
||||
<div class="boxline">
|
||||
<%= f.label :pushover_messages,
|
||||
raw("Receive <a href=\"https://pushover.net/\">Pushover</a> Alert:"),
|
||||
<%= f.label :pushover_messages, "Receive Pushover Alert:",
|
||||
:class => "required" %>
|
||||
<%= f.check_box :pushover_replies %>
|
||||
<span class="hint">
|
||||
|
|
|
@ -22,10 +22,10 @@ class Markdowner
|
|||
# make links have rel=nofollow
|
||||
html.gsub!(/<a href/, "<a rel=\"nofollow\" href")
|
||||
|
||||
# make @mentions into links to user profile
|
||||
# make @username link to that user's profile
|
||||
html.gsub!(/\B\@([\w\-]+)/) do |u|
|
||||
if User.find_by_username(u[1..-1])
|
||||
"<a href=\"/u/#{u[1..-1]}\">#{u}</a>"
|
||||
if User.find_by_username(u[1 .. -1])
|
||||
"<a href=\"/u/#{u[1 .. -1]}\">#{u}</a>"
|
||||
else
|
||||
u
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue