通知、消息创建的时候异步发送消息
This commit is contained in:
parent
9e17db376a
commit
649b3918c4
|
@ -83,7 +83,7 @@ class Message < ActiveRecord::Base
|
|||
# after_create :add_author_as_watcher, :reset_counters!, :add_boards_count
|
||||
after_update :update_messages_board, :update_activity
|
||||
after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score
|
||||
after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count, :act_as_system_message
|
||||
after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count, :act_as_system_message, :delay_message_send
|
||||
#before_save :be_user_score
|
||||
|
||||
scope :visible, lambda {|*args|
|
||||
|
@ -308,6 +308,22 @@ class Message < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def delay_message_send
|
||||
if self.course
|
||||
if self.parent_id.nil? # 发帖
|
||||
self.delay.contain_messages_message
|
||||
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
|
||||
end
|
||||
|
||||
#更新用户分数 -by zjc
|
||||
def be_user_score
|
||||
#新建message且无parent的为发帖
|
||||
|
|
|
@ -62,7 +62,7 @@ class News < ActiveRecord::Base
|
|||
:author_key => :author_id
|
||||
acts_as_watchable
|
||||
|
||||
after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score, :act_as_system_message
|
||||
after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score, :act_as_system_message, :delay_news_send
|
||||
after_update :update_activity
|
||||
after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score
|
||||
|
||||
|
@ -167,7 +167,17 @@ class News < ActiveRecord::Base
|
|||
# 消息发送原则:除了消息的发布者,课程的其它成员都能收到消息提醒
|
||||
def act_as_system_message
|
||||
if self.course
|
||||
self.delay.send_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)
|
||||
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count
|
||||
if count == 0
|
||||
ws = WechatService.new
|
||||
content = strip_html self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, 200
|
||||
ws.message_update_template m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", content, format_time(self.created_on)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if !self.project.nil?
|
||||
self.project.members.each do |m|
|
||||
|
@ -179,17 +189,16 @@ class News < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def send_message
|
||||
def delay_news_send
|
||||
if self.course
|
||||
self.delay.contain_news_message
|
||||
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 => user_id, :course_id => container_id, :viewed => false)
|
||||
# 微信相关
|
||||
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count
|
||||
if count == 0
|
||||
ws = WechatService.new
|
||||
content = strip_html self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, 200
|
||||
ws.message_update_template m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", content, format_time(self.created_on)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue