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 c34a31a3c..15a0d64d9 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -22,11 +22,12 @@
  • <%= link_to "问卷调查",{:controller=> 'users', :action => 'user_messages', id: User.current.id, host: Setting.host_user, :type => 'poll'} %>
  • <% end %> <% if @user_course_messages_count > 0 %> -
  • <%= link_to "作品评阅",{:controller=> 'users', :action => 'user_messages', id: User.current.id, host: Setting.host_user, :type => 'works_reviewers'} %>
  • +
  • <%= link_to "作品评阅",{:controller=> 'users', :action => 'user_messages', id: User.current.id, host: Setting.host_user, :type => 'works_reviewers'} %>
  • <% end %> <% if @user_course_messages_count > 0 %> -
  • <%= link_to "作品讨论",{:controller=> 'users', :action => 'user_messages', id: User.current.id, host: Setting.host_user, :type => 'works_reply'} %>
  • - <% end %> +
  • <%= link_to "作品讨论",{:controller=> 'users', :action => 'user_messages', id: User.current.id, host: Setting.host_user, :type => 'works_reply'} %>
  • + + <% end %> <% end %> <%# 项目相关消息 %> <% unless @user_forge_messages.nil? %> @@ -50,6 +51,11 @@ <% 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 %> @@ -216,6 +222,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 %>