动态内容调整
This commit is contained in:
parent
f644aa1144
commit
fce8d85380
|
@ -120,14 +120,23 @@ class WechatsController < ActionController::Base
|
||||||
on :click, with: 'MY_NEWS' do |request, key|
|
on :click, with: 'MY_NEWS' do |request, key|
|
||||||
uw = user_binded?(request[:FromUserName])
|
uw = user_binded?(request[:FromUserName])
|
||||||
if uw && uw.user
|
if uw && uw.user
|
||||||
ua = UserActivity.where(user_id: uw.user.id).order("id desc").limit(5)
|
|
||||||
|
ua = user_activity(uw.user)
|
||||||
|
|
||||||
logo = "trustie_logo2.png"
|
logo = "trustie_logo2.png"
|
||||||
i = 0
|
i = 0
|
||||||
news = ua.map do |ua|
|
news =[]
|
||||||
|
ua.each do |ua|
|
||||||
i += 1
|
i += 1
|
||||||
{title: "act_type: #{ua.act_type}, act_id: #{ua.act_id}",
|
activity = process_activity(ua)
|
||||||
content: "container_id: #{ua.container_id}, container_type: #{ua.container_type}",
|
if activity
|
||||||
picurl: "http://wechat.trustie.net/images/#{i == 1 ? logo : 'trustie_logo1.png'}" }
|
news << {title: activity[0],
|
||||||
|
content: activity[1],
|
||||||
|
picurl: "http://wechat.trustie.net/images/#{i == 1 ? logo : activity[2]}",
|
||||||
|
url: activity[3]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
request.reply.news(news) do |article, n, index| # article is return object
|
request.reply.news(news) do |article, n, index| # article is return object
|
||||||
|
@ -175,4 +184,36 @@ class WechatsController < ActionController::Base
|
||||||
def user_binded?(openid)
|
def user_binded?(openid)
|
||||||
uw = UserWechat.where(openid: openid).first
|
uw = UserWechat.where(openid: openid).first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user_activity(user)
|
||||||
|
@user = user
|
||||||
|
shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id)
|
||||||
|
shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id)
|
||||||
|
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||||
|
user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
|
||||||
|
user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")"
|
||||||
|
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
|
||||||
|
project_types = "('Message','Issue','ProjectCreateInfo')"
|
||||||
|
principal_types = "JournalsForMessage"
|
||||||
|
|
||||||
|
blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"
|
||||||
|
@user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
|
||||||
|
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
|
||||||
|
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " +
|
||||||
|
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10)
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def process_activity(user_activity)
|
||||||
|
act= user_activity.act
|
||||||
|
case user_activity.container_type.to_s
|
||||||
|
when 'Course'
|
||||||
|
when 'Project'
|
||||||
|
case user_activity.act_type.to_s
|
||||||
|
when 'Issue'
|
||||||
|
[activity.project.name.to_s+" | 项目问题", activity.subject.to_s, project_issues_path(activity.project), url_to_avatar(activity.author)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue