diff --git a/app/api/mobile/apis/activities.rb b/app/api/mobile/apis/activities.rb index 41069b4bf..9329ea860 100644 --- a/app/api/mobile/apis/activities.rb +++ b/app/api/mobile/apis/activities.rb @@ -6,12 +6,16 @@ module Mobile resources :activities do desc "get user activities" + + params do + requires :page, type: Integer + end get ':id' do #uw = UserWechat.find params[:openid] user = User.find params[:id] 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 + page = params[:page] ? params[:page] : 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')" @@ -22,8 +26,14 @@ module Mobile 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(50).offset(page * 10) + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc') + all_count = activities.count + activities = activities.limit(10).offset(page * 10) + count = activities.count present :data, activities, with: Mobile::Entities::Activity + present :all_count, all_count + present :count, count + present :page, page present :status, 0 end end diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 63775c12d..753299956 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -12,7 +12,7 @@ module Mobile requires :type, type: String requires :content, type: String end - get ':id' do + post ':id' do type = params[:type] result = 1 current_user = User.find 8686 diff --git a/app/api/mobile/entities/message.rb b/app/api/mobile/entities/message.rb index 3d7fb7bbe..d182e5965 100644 --- a/app/api/mobile/entities/message.rb +++ b/app/api/mobile/entities/message.rb @@ -24,6 +24,8 @@ module Mobile end when :lasted_comment time_from_now u.created_on + when :message_praise_count + get_activity_praise_num(u) end end end @@ -41,6 +43,7 @@ module Mobile message_expose :subject message_expose :content message_expose :replies_count + message_expose :message_praise_count message_expose :created_on message_expose :id message_expose :lasted_comment diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index bf084c2f4..d1ec9c5c3 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -2,6 +2,7 @@ module Mobile module Entities class News < Grape::Entity include Redmine::I18n + include ApiHelper def self.news_expose(field) expose field do |f,opt| if f.is_a?(Hash) && f.key?(field) @@ -16,7 +17,9 @@ module Mobile else case field when :course_name - Course.find(f.course_id).name unless f.course_id == nil + get_course(f.course_id).name unless f.course_id == nil + when :news_praise_count + get_activity_praise_num(f) end end elsif f.is_a?(Hash) && !f.key?(field) @@ -59,6 +62,7 @@ module Mobile news_expose :created_on #评论数量 news_expose :comments_count + news_expose :news_praise_count #课程名字 news_expose :course_name #评论 diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index c1467bc52..066a28f25 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -211,13 +211,65 @@ -