Skip to content

Commit

Permalink
#40 checking which mentions failed [buggy]
Browse files Browse the repository at this point in the history
* flash message does not work
  • Loading branch information
amenk committed Feb 11, 2016
1 parent e37629c commit d8820b4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/redmine_mentions/journal_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module JournalPatch
def self.included(base)
base.class_eval do
after_create :send_mail

def send_mail
if self.journalized.is_a?(Issue) && self.notes.present?
issue = self.journalized
Expand All @@ -12,13 +12,22 @@ def send_mail
users_regex=users.collect{|u| "#{Setting.plugin_redmine_mentions['trigger']}#{u.login}"}.join('|')
regex_for_email = '\B('+users_regex+')\b'
regex = Regexp.new(regex_for_email)

mentioned_users = self.notes.scan(regex)
mentioned_users.each do |mentioned_user|
username = mentioned_user.first[1..-1]
if user = User.find_by_login(username)
MentionMailer.notify_mentioning(issue, self, user).deliver
end
end

all_mentions = self.notes.scan(Regexp.new("(#{Setting.plugin_redmine_mentions['trigger']}\\w+)"))
not_notified = all_mentions - mentioned_users

if !flash[:notice].blank? && not_notified.any?
flash[:notice] += content_tag(:p, l(:label_issue_notice_recipients) + not_notified.join('; '), :class => 'email-was-not-sent')
flash[:notice] = flash[:notice].html_safe
end
end
end
end
Expand Down

0 comments on commit d8820b4

Please sign in to comment.