模板消息中有html标签

This commit is contained in:
cxt 2016-04-20 10:44:54 +08:00
parent 0cc5eca34b
commit ef987d6bf7
9 changed files with 45 additions and 15 deletions

View File

@ -1 +1 @@
{"access_token":"q51KZUeA6_-CCCH-Buy1mxFmRjcrCViHgk2mHHHqEDbjuA_pgCM1IyW1DASYvpzyB06xHiarujo3rz1Ucq3GRoXdgQ7hAoFCzkL_q3Z5vczLjwAjowAVwmulYE-cAij8ATUfADAWPQ","expires_in":7200,"got_token_at":1460601163}
{"access_token":"GbIQJdIaX2c0IyQSOJcNNT2TxUH5aSQCNL7N92BV9oggGePRoj886HDohtqRokwPS6OVcIYF8WZTnSn717CP-czrWupY_gIHehK4UqjqXYqGkVqODXaXEB_LV0grMIwEXQDhAAAFYL","expires_in":7200,"got_token_at":1461117548}

View File

@ -3068,3 +3068,18 @@ def host_with_protocol
return Setting.protocol + "://" + Setting.host_name
end
def strip_html(text,len=0,endss="...")
ss = ""
if text.length>0
ss=text.gsub(/<\/?.*?>/, '').strip
if len > 0 && ss.length > len
ss = ss[0, len] + endss
elsif len > 0 && ss.length <= len
ss = ss
#ss = truncate(ss, :length => len)
end
end
return ss
end

View File

@ -81,10 +81,12 @@ class BlogComment < ActiveRecord::Base
ws = WechatService.new
if self.parent_id.nil?
self.author.watcher_users.each do |watcher|
ws.message_update_template watcher.id, "#{l(:label_new_blog_template)}", self.author.try(:realname) + " 发表了博客:" + self.title.html_safe, format_time(self.created_at)
content = strip_html self.author.try(:realname) + " 发表了博客:" + self.title.html_safe, 200
ws.message_update_template watcher.id, "#{l(:label_new_blog_template)}", content, format_time(self.created_at)
end
else
ws.comment_template self.parent.author_id, "#{l(:label_blog_comment_template)}", self.author.try(:realname), format_time(self.created_at), self.content.html_safe
content = strip_html self.content.html_safe, 200
ws.comment_template self.parent.author_id, "#{l(:label_blog_comment_template)}", self.author.try(:realname), format_time(self.created_at), content
end
end
end

View File

@ -45,12 +45,14 @@ class Comment < ActiveRecord::Base
if self.commented.course
if self.author_id != self.commented.author_id
self.course_messages << CourseMessage.new(:user_id => self.commented.author_id, :course_id => self.commented.course.id, :viewed => false)
ws.comment_template self.commented.author_id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), self.comments.html_safe
content = strip_html self.comments.html_safe, 200
ws.comment_template self.commented.author_id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), content
end
else # 项目相关
if self.author_id != self.commented.author_id
self.forge_messages << ForgeMessage.new(:user_id => self.commented.author_id, :project_id => self.commented.project.id, :viewed => false)
ws.comment_template self.commented.author_id, "#{l(:label_news_comment_template)}", self.author.try(:realname), format_time(self.created_on), self.comments.html_safe
content = strip_html self.comments.html_safe, 200
ws.comment_template self.commented.author_id, "#{l(:label_news_comment_template)}", self.author.try(:realname), format_time(self.created_on), content
end
end
end

View File

@ -160,7 +160,8 @@ class Issue < ActiveRecord::Base
unless self.author_id == self.assigned_to_id
self.forge_messages << ForgeMessage.new(:user_id => self.assigned_to_id, :project_id => self.project_id, :viewed => false)
ws = WechatService.new
ws.message_update_template self.assigned_to_id, "#{l(:label_new_issue_template)}", self.author.try(:realname) + " 给您指派了缺陷:" + self.subject.html_safe, format_time(self.created_on)
content = strip_html self.author.try(:realname) + " 给您指派了缺陷:" + self.subject.html_safe, 200
ws.message_update_template self.assigned_to_id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on)
end
if self.tracker_id == 5
self.project.members.each do |m|

View File

@ -240,6 +240,7 @@ class Journal < ActiveRecord::Base
#缺陷回复微信模板消息
def issue_wechat_message
ws = WechatService.new
ws.comment_template self.issue.author_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), self.notes.html_safe
content = strip_html self.notes.html_safe, 200
ws.comment_template self.issue.author_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), content
end
end

View File

@ -257,7 +257,9 @@ class JournalsForMessage < ActiveRecord::Base
end
if self.jour_type == 'HomeworkCommon'
ws = WechatService.new
ws.comment_template self.jour.user_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), self.notes.html_safe
#content = truncate(strip_tags(self.notes.to_s), length: 200)
content = strip_html self.notes.html_safe, 200
ws.comment_template self.jour.user_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content
end
end
@ -271,7 +273,8 @@ class JournalsForMessage < ActiveRecord::Base
if self.reply_id == 0
if self.user_id != self.jour_id # 过滤自己给自己的留言消息
receivers << self.jour
ws.message_update_template self.jour_id, "#{l(:label_new_journals_template)}", self.notes.html_safe, format_time(self.created_on)
content = strip_html self.notes, 200
ws.message_update_template self.jour_id, "#{l(:label_new_journals_template)}", content, format_time(self.created_on)
end
else # 留言回复
reply_to = User.find(self.reply_id)
@ -281,7 +284,8 @@ class JournalsForMessage < ActiveRecord::Base
if self.user_id != self.parent.jour_id && self.reply_id != self.parent.jour_id # 给东家发信息,如果回复的对象是东家则不发
receivers << self.parent.jour
end
ws.comment_template self.reply_id, "#{l(:label_journals_comment_template)}", self.user.try(:realname), format_time(self.created_on), self.notes.html_safe
content = strip_html self.notes, 200
ws.comment_template self.reply_id, "#{l(:label_journals_comment_template)}", self.user.try(:realname), format_time(self.created_on), content
end
receivers.each do |r|
self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false)

View File

@ -266,14 +266,16 @@ class Message < ActiveRecord::Base
self.course.members.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)
ws.topic_publish_template m.user_id, "#{l(:label_course_topic_template)}", self.subject, self.author.try(:realname), format_time(self.created_on)
content = strip_html self.subject, 200
ws.topic_publish_template m.user_id, "#{l(:label_course_topic_template)}", content, self.author.try(:realname), format_time(self.created_on)
end
end
else # 回帖
self.course.members.each do |m|
if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false)
ws.comment_template m.user_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), self.content.html_safe
content = strip_html self.content.html_safe, 200
ws.comment_template m.user_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content
end
end
end
@ -282,14 +284,16 @@ class Message < ActiveRecord::Base
self.project.members.each do |m|
if m.user_id != self.author_id
self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false)
ws.topic_publish_template m.user_id, "#{l(:label_project_topic_template)}", self.subject, self.author.try(:realname), format_time(self.created_on)
content = strip_html self.subject, 200
ws.topic_publish_template m.user_id, "#{l(:label_project_topic_template)}", content, self.author.try(:realname), format_time(self.created_on)
end
end
else # 回帖
self.project.members.each do |m|
if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息
self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false)
ws.comment_template m.user_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), self.content.html_safe
content = strip_html self.content.html_safe, 200
ws.comment_template m.user_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content
end
end
end

View File

@ -171,7 +171,8 @@ class News < ActiveRecord::Base
if m.user_id != self.author_id
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false)
ws = WechatService.new
ws.message_update_template m.user_id, "#{l(:label_new_notice_template)}", self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, format_time(self.created_on)
content = strip_html self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, 200
ws.message_update_template m.user_id, "#{l(:label_new_notice_template)}", self.author.try(:realname) + " 发布了通知:" + content, format_time(self.created_on)
end
end
else