From e4dda89c075b51f98cb855697bb4af04893962d5 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 20 Aug 2015 12:44:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF---=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=95=99=E8=A8=80=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 8 ++++++- app/models/journals_for_message.rb | 29 ++++++++++++++------------ app/views/users/user_messages.html.erb | 28 ++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6c91fd805..686ffbb89 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -98,7 +98,7 @@ class UsersController < ApplicationController # 用户消息 # 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复 - # issue:问题;journal:缺陷状态更新; forum:公共贴吧 + # issue:问题;journal:缺陷状态更新; forum:公共贴吧: user_feedback: 用户留言 def user_messages unless User.current.logged? render_403 @@ -115,9 +115,11 @@ class UsersController < ApplicationController @user_course_messages = @user.course_messages.reverse @user_forge_messages = @user.forge_messages.reverse @user_memo_messages = @user.memo_messages.reverse + @user_feedback_messages = @user.user_feedback_messages.reverse @user_course_messages_count = @user_course_messages.count @user_forge_messages_count = @user_forge_messages.count @user_memo_messages_count = @user_memo_messages.count + @user_feedback_messages_count = @user_feedback_messages.count when 'homework' @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc") @user_course_messages_count = @user_course_messages.count @@ -126,6 +128,7 @@ class UsersController < ApplicationController @user_course_messages_count = @user_course_messages.count when 'forge_message' @user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Message", @user).order("created_at desc") + @user_forge_messages_count = @user_forge_messages.count when 'course_news' @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "News", @user).order("created_at desc") @user_course_messages_count = @user_course_messages.count @@ -150,6 +153,9 @@ class UsersController < ApplicationController when 'forum' @user_memo_messages = MemoMessage.where("memo_type =? and user_id =?", "Memo", @user).order("created_at desc") @user_memo_messages_count = @user_memo_messages.count + when 'user_feedback' + @user_feedback_messages = UserFeedbackMessage.where("journals_for_message_type =? and user_id =?", "Principal", @user).order("created_at desc") + @user_feedback_messages_count = @user_feedback_messages.count else render_404 return diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index ce58fdc69..2c397ffcf 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -209,21 +209,24 @@ class JournalsForMessage < ActiveRecord::Base end else # 留言回复 # 添加留言回复人 - # reply_to = User.find(self.reply_id) - if self.user_id != self.parent.user_id && self.user_id != self.reply_id && self.user_id != self.jour_id# 如果回帖人不是用户自己 - receivers << User.find(self.reply_id) - receivers << self.parent.jour - end - # if self.user_id != self.parent.jour_id - # receivers << self.parent.jour - # end - end - if self.jour_type == 'Principal' - if self.user_id != self.jour_id - receivers.each do |r| - self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false) + reply_to = User.find(self.reply_id) + if self.user_id != self.parent.user_id # 如果回帖人不是用户自己 + receivers << self.parent.jour + if self.reply_id != self.parent.user_id + receivers << reply_to + end + else # 用户自己回复别人的,别人收到消息通知 + if self.user_id != self.reply_id # 过滤掉自己回复自己的 + receivers << reply_to end end end + if self.jour_type == 'Principal' + + receivers.each do |r| + self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false) + end + + end end end diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb index a40a54e95..cb7fb0e60 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -25,6 +25,7 @@
  • <%= link_to "作品评阅",{:controller=> 'users', :action => 'user_messages', id: User.current.id, host: Setting.host_user, :type => 'works_reviewers'} %>
  • <% end %>
  • <%= link_to "作品讨论",{:controller=> 'users', :action => 'user_messages', id: User.current.id, host: Setting.host_user, :type => 'works_reply'} %>
  • + <% end %> <%# 项目相关消息 %> <% unless @user_forge_messages.nil? %> @@ -44,10 +45,15 @@ <%# 公共贴吧 %> <% unless @user_forum_messages.nil? %> <% unless @user_memo_messages_count > 0 %> -
  • <%= link_to "发布了帖子",{:controller=> 'users', :action => 'user_messages', id: User.current.id, host: Setting.host_user, :type => 'forum'} %>
  • +
  • <%= link_to "发布了帖子",{:controller=> 'users', :action => 'user_messages', id: User.current.id, host: Setting.host_user, :type => 'forum'} %>
  • <% end %> <% end %> <%# 用户留言 %> + <% unless @user_forge_messages.nil? %> + <% unless @user_forge_messages_count > 0 %> +
  • <%= link_to "用户留言",{:controller=> 'users', :action => 'user_messages', id: User.current.id, host: Setting.host_user, :type => 'user_feedback'} %>
  • + <% end %> + <% end %> @@ -214,6 +220,26 @@ <% end %> <% end %> <% end %> + <%# 用户留言消息 %> + <% unless @user_feedback_messages.nil? %> + <% @user_forge_messages.each do |urm| %> + <% if urm.memo_type == "Memo" %> + + <% end %> + <% end %> + <% end %> <% else %>
    暂无消息!
    <% end %>