diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index b7e4b9efd..5e2e7c48a 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -33,12 +33,18 @@ class HomeworkCommonController < ApplicationController @homeworks = paginateHelper @homework_commons,10 #设置at已读 - @homeworks.each do |homework| - # homework.journals_for_messages.each do |j| - # User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!} - # end - homework.delay.set_jour_viewed + ids = @homeworks.inject([]) do |ids, homework| + jids = homework.journals_for_messages.map(&:id) + jids ? ids + jids : ids + + # homework.delay.set_jour_viewed end + unless ids.empty? + User.current.at_messages.where(viewed: false, + at_message_type: 'JournalsForMessage', + at_message_id: ids).update_all(viewed: true) + end + @left_nav_type = 3 respond_to do |format| format.js diff --git a/app/models/message.rb b/app/models/message.rb index 309291183..5366724eb 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -328,17 +328,28 @@ class Message < ActiveRecord::Base def delay_message_send if self.course if self.parent_id.nil? # 发帖 - self.delay.contain_messages_message + dm = [] + self.course.members.includes(:user).each do |m| + if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息 + dm << {course_message_type:'Message',course_message_id:self.id, :user_id => m.user_id, + :course_id => self.board.course_id, :viewed => false} + if dm.size >= 30 + self.delay.contain_messages_message(dm) + dm.clear + end + end + end + + unless dm.empty? + self.delay.contain_messages_message(dm) + end + end end end - def contain_messages_message - self.course.members.includes(:user).each do |m| - if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息 - self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) - end - end + def contain_messages_message vs + CourseMessage.create(vs) end #更新用户分数 -by zjc diff --git a/app/models/news.rb b/app/models/news.rb index f39352c94..c436724fd 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -208,16 +208,29 @@ class News < ActiveRecord::Base def delay_news_send if self.course - self.delay.contain_news_message + + vs = [] + self.course.members.each do | m| + if m.user_id != self.author_id + vs << {course_message_type:'News',course_message_id:self.id, :user_id => m.user_id, + :course_id => self.course_id, :viewed => false} + + if vs.size >= 30 + self.delay.contain_news_message(vs) + vs.clear + end + end + end + + unless vs.empty? + self.delay.contain_news_message(vs) + end + end end - def contain_news_message - self.course.members.each do |m| - if m.user_id != self.author_id - self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) - end - end + def contain_news_message(vs) + CourseMessage.create(vs) end # Time 2015-03-31 13:50:54 diff --git a/app/views/layouts/new_base_user.html.erb b/app/views/layouts/new_base_user.html.erb index 1e31674f4..24cad0bf8 100644 --- a/app/views/layouts/new_base_user.html.erb +++ b/app/views/layouts/new_base_user.html.erb @@ -167,7 +167,7 @@