From e3ee99b486d1222841aa3e58833071902b6cad51 Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 16 Jun 2016 15:46:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E4=B8=AD?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E6=8E=89=E5=B7=B2=E5=88=A0=E9=99=A4=E7=9A=84?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=B6=88=E6=81=AF=E3=80=81=20at=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E4=B8=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 2 +- app/controllers/users_controller.rb | 31 +++++++++++++++------- app/helpers/users_helper.rb | 4 ++- app/views/users/_user_at_message.html.erb | 2 +- app/views/users/user_messages.html.erb | 5 ++-- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 22047efee..d478b4d63 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -1096,7 +1096,7 @@ class StudentWorkController < ApplicationController all_student_ids = "(" + pro.members.map{|member| member.user_id}.join(",") + ")" end all_students = User.where("id in #{all_student_ids}") - student_work_id = @homework.student_work_projects.where("user_id=?",User.current.id).first.student_work_id + student_work_id = @homework.student_work_projects.where("user_id=?",User.current.id).empty? ? -1 : @homework.student_work_projects.where("user_id=?",User.current.id).first.student_work_id @commit_student_ids = @homework.student_work_projects.where("student_work_id != #{student_work_id}").map{|student| student.user_id} @users = searchstudent_by_name all_students,name respond_to do |format| diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cad57b49f..ca63f496c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -130,8 +130,11 @@ class UsersController < ApplicationController onclick_time = User.current.onclick_time.onclick_time messages.each do |message_all| # 未读的消息存放在数组 - if (message_all.message_type != "SystemMessage"&& !message_all.message.nil? && message_all.message.viewed == 0) || (message_all.message_type == "SystemMessage"&& !message_all.message.nil? && message_all.message.created_at > onclick_time) - @message_alls << message_all.message + mess = message_all.message + if (message_all.message_type != "SystemMessage"&& !mess.nil? && (mess.viewed == 0 || !mess.viewed)) || (message_all.message_type == "SystemMessage"&& !mess.nil? && mess.created_at > onclick_time) + unless (message_all.message_type == 'CourseMessage' && mess && mess.course.is_delete == 1) + @message_alls << mess + end break if @message_alls.length == 5 end end @@ -154,33 +157,41 @@ class UsersController < ApplicationController update_message_viewed(@user) end # @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count + courses = @user.courses.where("is_delete = 1") + course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" case params[:type] when nil # 系统消息为管理员发送,我的消息中包含有系统消息 @message_alls = [] messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc") messages.each do |message_all| - @message_alls << message_all.message + mess = message_all.message + unless (message_all.message_type == 'CourseMessage' && mess && mess.course.is_delete == 1) + @message_alls << mess + end end when 'unviewed' @message_alls = [] - messages = MessageAll.where("user_id =?", @user.id).includes(:message).order("created_at desc") + messages = MessageAll.where("message_alls.user_id =?", @user.id).includes(:message).order("created_at desc") messages.each do |message_all| # 在点击或者刷新消息列表后未读的消息存放在数组 - if message_all.message_type != "SystemMessage"&& !message_all.message.nil? && message_all.message.viewed == 0 - @message_alls << message_all.message + mess = message_all.message + if message_all.message_type != "SystemMessage"&& !mess.nil? && (mess.viewed == 0 || !mess.viewed) + unless (message_all.message_type == 'CourseMessage' && mess && mess.course.is_delete == 1) + @message_alls << mess + end end end #课程相关消息 when 'homework' - @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =?", @user.id).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =? and course_id NOT IN #{course_ids}", @user.id).order("created_at desc") when 'course_message' - @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user.id).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type =? and user_id =? and course_id NOT IN #{course_ids}", "Message", @user.id).order("created_at desc") when 'course_news' # 课程通知包含发布的通知和回复的通知 - @message_alls = CourseMessage.where("course_message_type in ('News', 'Comment') and user_id =?", @user.id).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type in ('News', 'Comment') and user_id =? and course_id NOT IN #{course_ids}", @user.id).order("created_at desc") when 'poll' - @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user.id).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type =? and user_id =? and course_id NOT IN #{course_ids}", "Poll", @user.id).order("created_at desc") #项目相关消息 when 'issue' @message_alls = ForgeMessage.where("forge_message_type in ('Issue', 'Journal') and user_id =?" , @user.id).order("created_at desc") diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 44b919121..4a6dbc6b6 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -147,7 +147,9 @@ module UsersHelper # 统计未读消息数 def unviewed_message(user) - course_count = CourseMessage.where("user_id =? and viewed =?", user, 0).count + courses = user.courses.where("is_delete = 1") + course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" + course_count = CourseMessage.where("user_id =? and viewed =? and course_id not in #{course_ids}", user, 0).count forge_count = ForgeMessage.where("user_id =? and viewed =?", user, 0).count org_count = OrgMessage.where("user_id =? and viewed =?", user, 0).count user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0).count diff --git a/app/views/users/_user_at_message.html.erb b/app/views/users/_user_at_message.html.erb index 8f0c6acaf..81139ab8e 100644 --- a/app/views/users/_user_at_message.html.erb +++ b/app/views/users/_user_at_message.html.erb @@ -1,4 +1,4 @@ -<% if AtMessage === ma && ma.at_valid? %> +<% if ma.class == AtMessage && ma.at_valid? %>