From 103d61056d7d7ea0c8799a77581c52ce0b724e13 Mon Sep 17 00:00:00 2001 From: huang Date: Mon, 7 Sep 2015 16:08:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8A=9F=E8=83=BD=EF=BC=9A?= =?UTF-8?q?=201=E3=80=81=E6=B7=BB=E5=8A=A0=E2=80=9C=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E2=80=9D=E5=88=86=E7=B1=BB=202=E3=80=81?= =?UTF-8?q?=E6=96=B0=E6=B3=A8=E5=86=8C=E7=94=A8=E6=88=B7=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 12 +++++++++++- app/helpers/users_helper.rb | 9 +++++++++ app/models/user.rb | 5 ++++- app/views/users/user_messages.html.erb | 6 +++--- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4bbb9848a..f05fa891a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -106,6 +106,7 @@ class UsersController < ApplicationController return end # 记录当前点击按钮的时间 + # 考虑到用户未退出刷新消息页面 if OnclickTime.where("user_id =?", User.current).first.nil? message_new_time = OnclickTime.new message_new_time.user_id = User.current.id @@ -132,10 +133,19 @@ class UsersController < ApplicationController case params[:type] when nil @message_alls = [] - messages = MessageAll.where("user_id =?",@user).order("created_at desc") + messages = MessageAll.where("user_id =?" ,@user).order("created_at desc") messages.each do |message_all| @message_alls << message_all.message end + when 'unviewed' + @message_alls = [] + messages = MessageAll.where("user_id =?", @user).order("created_at desc") + messages.each do |message_all| + # 在点击或者刷新消息列表后未读的消息存放在数组 + if message_all.message.viewed == 0 + @message_alls << message_all.message + end + end when 'homework' @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc") when 'course_message' diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 269630ec3..c806f3493 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -52,6 +52,15 @@ module UsersHelper end end + # 统计未读消息数 + def unviewed_message(user) + course_count = CourseMessage.where("user_id =? and viewed =?", user, 0).count + forge_count = ForgeMessage.where("user_id =? and viewed =?", user, 0).count + user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0).count + user_memo_count = MemoMessage.where("user_id =? and viewed =?", user, 0).count + messages_count = course_count + forge_count + user_feedback_count + user_memo_count + end + def user_mail_notification_options(user) user.valid_notification_options.collect {|o| [l(o.last), o.first]} end diff --git a/app/models/user.rb b/app/models/user.rb index e7f4a8c50..2ccc41783 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1001,8 +1001,11 @@ class User < Principal self.acts << Activity.new(:user_id => self.id) end + # 注册用户的时候消息默认点击时间为用户创建时间 def add_onclick_time - self.onclick_time << OnclickTime.new(:user_id => self.id, :onclick_time => self.created_on) + if OnclickTime.where("user_id =?" , self.id).first.nil? + OnclickTime.create(:user_id => self.id, :onclick_time => self.created_on) + end end # Removes references that are not handled by associations diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb index c3c1a447b..6a6597af9 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -4,6 +4,7 @@
  • -<% if params[:type].nil? %> +<% if params[:type].nil? || params[:type] == "unviewed" %> <% end %> <% if @message_alls.count >0 %>