From 48b93f21133f6c18c69547b42214738faa68ee8d Mon Sep 17 00:00:00 2001 From: huang Date: Mon, 21 Sep 2015 17:51:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BC=BA=E9=99=B7=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E7=82=B9=E5=AF=B9=E7=82=B9=E5=8F=91=E9=80=81=20?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96=EF=BC=88?= =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E6=88=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 3 --- app/models/journal.rb | 9 +++++++-- app/models/journal_reply.rb | 25 +++++++++++++++++++++++++ app/views/issues/_edit.html.erb | 6 ------ 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index bf854abe8..2232602aa 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -223,7 +223,6 @@ class IssuesController < ApplicationController end if saved - #修改界面增加跟踪者 watcherlist = @issue.watcher_users select_users = [] @@ -253,9 +252,7 @@ class IssuesController < ApplicationController JournalReply.add_reply(@issue.current_journal.id, reply_id, User.current.id) end flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? - respond_to do |format| - format.html { redirect_to issue_url(@issue.id) } format.api { render_api_ok } end diff --git a/app/models/journal.rb b/app/models/journal.rb index 0d86d12ff..9ffc5d405 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -171,11 +171,16 @@ class Journal < ActiveRecord::Base # 缺陷状态更改,消息提醒 def act_as_forge_message + receivers = [] + # 直接回复 if self.user_id != self.issue.author_id - self.forge_messages << ForgeMessage.new(:user_id => self.issue.author_id, :project_id => self.issue.project_id, :viewed => false) + receivers << self.issue.author_id end if self.user_id != self.issue.assigned_to_id && self.issue.assigned_to_id != self.issue.author_id # 指派人不是自己的话,则给指派人发送 - self.forge_messages << ForgeMessage.new(:user_id => self.issue.assigned_to_id, :project_id => self.issue.project_id, :viewed => false) + receivers << self.issue.assigned_to_id + end + receivers.each do |r| + self.forge_messages << ForgeMessage.new(:user_id => r, :project_id => self.issue.project_id, :viewed => false) end end diff --git a/app/models/journal_reply.rb b/app/models/journal_reply.rb index 814231776..430d506ed 100644 --- a/app/models/journal_reply.rb +++ b/app/models/journal_reply.rb @@ -5,8 +5,33 @@ class JournalReply < ActiveRecord::Base belongs_to :user belongs_to :journal + after_create :send_journal_messages def self.add_reply(journal_id, reply_id, user_id) self.create(:journal_id => journal_id, :reply_id => reply_id, :user_id => user_id) end + + def send_journal_messages + journal = self.journal + replier = User.find(self.reply_id) + receivers = [] + # 被回复的人发送消息 + if journal.user_id != self.reply_id + receivers << self.replier + end + if journal.user_id != journal.issue.author_id && self.reply_id != journal.issue.author_id + receivers << self.journal.issue.author + end + receivers.each do |r| + journal.forge_messages << ForgeMessage.new(:user_id =>r, :project_id => journal.issue.project, :viewed => false) + end + + # if self.user_id != self.journal_reply.user_id + # receivers << self.journal_reply.user_id + # end + # # 给缺陷发布者发送 + # if self.user_id != self.issue.author_id && self.journal_reply.user_id != self.issue.author_id + # receivers << self.issue.author_id + # end + end end diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb index 1f3f984b4..3a3782e47 100644 --- a/app/views/issues/_edit.html.erb +++ b/app/views/issues/_edit.html.erb @@ -6,15 +6,9 @@ - <% end %> - - <% if @journals.present? %>
<%= render :partial => 'history', :locals => {:issue => @issue, :journals => @journals} %>