|
|
|
@ -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
|
|
|
|
|