From 9239e4ce4d4e958e62552d4a01183d0295c020f5 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 14 Sep 2017 00:04:30 +0200 Subject: Uploads for admin site settings (#4913) * Improve OpenGraph tags for about pages * Add thumbnail admin setting * Fix error * Fix up --- app/presenters/instance_presenter.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/presenters') diff --git a/app/presenters/instance_presenter.rb b/app/presenters/instance_presenter.rb index 8104b7531..c9e3c31a1 100644 --- a/app/presenters/instance_presenter.rb +++ b/app/presenters/instance_presenter.rb @@ -35,4 +35,8 @@ class InstancePresenter def source_url Mastodon::Version.source_url end + + def thumbnail + @thumbnail ||= Rails.cache.fetch('site_uploads/thumbnail') { SiteUpload.find_by(var: 'thumbnail') } + end end -- cgit From 9619b7f7278ed63ba2caaf6eaa1ef711d72c1918 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Mon, 18 Sep 2017 21:59:57 +0900 Subject: Use Account.local.sum(statuses_count) instead of Status.local.count (#4996) It is faster. --- app/presenters/instance_presenter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/presenters') diff --git a/app/presenters/instance_presenter.rb b/app/presenters/instance_presenter.rb index c9e3c31a1..4c1124d59 100644 --- a/app/presenters/instance_presenter.rb +++ b/app/presenters/instance_presenter.rb @@ -21,7 +21,7 @@ class InstancePresenter end def status_count - Rails.cache.fetch('local_status_count') { Status.local.count } + Rails.cache.fetch('local_status_count') { Account.local.sum(:statuses_count) } end def domain_count -- cgit From 7d16bb379d1463471faf264bb89e24d5b8a505ca Mon Sep 17 00:00:00 2001 From: nullkal Date: Tue, 19 Sep 2017 23:37:06 +0900 Subject: Use OrderedCollectionPage to return followers/following list (#4949) --- app/controllers/follower_accounts_controller.rb | 23 +++++++++++++++++--- app/controllers/following_accounts_controller.rb | 23 +++++++++++++++++--- app/presenters/activitypub/collection_presenter.rb | 2 +- .../activitypub/collection_serializer.rb | 25 +++++++++++++++++----- 4 files changed, 61 insertions(+), 12 deletions(-) (limited to 'app/presenters') diff --git a/app/controllers/follower_accounts_controller.rb b/app/controllers/follower_accounts_controller.rb index 0e1949897..8eb4d2822 100644 --- a/app/controllers/follower_accounts_controller.rb +++ b/app/controllers/follower_accounts_controller.rb @@ -17,12 +17,29 @@ class FollowerAccountsController < ApplicationController private + def page_url(page) + account_followers_url(@account, page: page) unless page.nil? + end + def collection_presenter - ActivityPub::CollectionPresenter.new( - id: account_followers_url(@account), + page = ActivityPub::CollectionPresenter.new( + id: account_followers_url(@account, page: params.fetch(:page, 1)), type: :ordered, size: @account.followers_count, - items: @follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.account) } + items: @follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.account) }, + part_of: account_followers_url(@account), + next: page_url(@follows.next_page), + prev: page_url(@follows.prev_page) ) + if params[:page].present? + page + else + ActivityPub::CollectionPresenter.new( + id: account_followers_url(@account), + type: :ordered, + size: @account.followers_count, + first: page + ) + end end end diff --git a/app/controllers/following_accounts_controller.rb b/app/controllers/following_accounts_controller.rb index d4593093f..1ca6f0fe7 100644 --- a/app/controllers/following_accounts_controller.rb +++ b/app/controllers/following_accounts_controller.rb @@ -17,12 +17,29 @@ class FollowingAccountsController < ApplicationController private + def page_url(page) + account_following_index_url(@account, page: page) unless page.nil? + end + def collection_presenter - ActivityPub::CollectionPresenter.new( - id: account_following_index_url(@account), + page = ActivityPub::CollectionPresenter.new( + id: account_following_index_url(@account, page: params.fetch(:page, 1)), type: :ordered, size: @account.following_count, - items: @follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.target_account) } + items: @follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.target_account) }, + part_of: account_following_index_url(@account), + next: page_url(@follows.next_page), + prev: page_url(@follows.prev_page) ) + if params[:page].present? + page + else + ActivityPub::CollectionPresenter.new( + id: account_following_index_url(@account), + type: :ordered, + size: @account.following_count, + first: page + ) + end end end diff --git a/app/presenters/activitypub/collection_presenter.rb b/app/presenters/activitypub/collection_presenter.rb index 631d87cd0..39657276f 100644 --- a/app/presenters/activitypub/collection_presenter.rb +++ b/app/presenters/activitypub/collection_presenter.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class ActivityPub::CollectionPresenter < ActiveModelSerializers::Model - attributes :id, :type, :size, :items + attributes :id, :type, :size, :items, :part_of, :first, :next, :prev end diff --git a/app/serializers/activitypub/collection_serializer.rb b/app/serializers/activitypub/collection_serializer.rb index d01dead28..9832133fc 100644 --- a/app/serializers/activitypub/collection_serializer.rb +++ b/app/serializers/activitypub/collection_serializer.rb @@ -3,23 +3,38 @@ class ActivityPub::CollectionSerializer < ActiveModel::Serializer def self.serializer_for(model, options) return ActivityPub::ActivitySerializer if model.class.name == 'Status' + return ActivityPub::CollectionSerializer if model.class.name == 'ActivityPub::CollectionPresenter' super end attributes :id, :type, :total_items + attribute :next, if: -> { object.next.present? } + attribute :prev, if: -> { object.prev.present? } + attribute :part_of, if: -> { object.part_of.present? } - has_many :items, key: :ordered_items + has_one :first, if: -> { object.first.present? } + has_many :items, key: :items, if: -> { (object.items.present? || page?) && !ordered? } + has_many :items, key: :ordered_items, if: -> { (object.items.present? || page?) && ordered? } def type - case object.type - when :ordered - 'OrderedCollection' + if page? + ordered? ? 'OrderedCollectionPage' : 'CollectionPage' else - 'Collection' + ordered? ? 'OrderedCollection' : 'Collection' end end def total_items object.size end + + private + + def ordered? + object.type == :ordered + end + + def page? + object.part_of.present? + end end -- cgit From ab625c57cebb1f45645b9fb0638548e1079378b1 Mon Sep 17 00:00:00 2001 From: Daigo 3 Dango Date: Sat, 23 Sep 2017 23:18:32 -1000 Subject: Compact status_ids in StatusRelationshipsPresenter (#5073) --- app/presenters/status_relationships_presenter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/presenters') diff --git a/app/presenters/status_relationships_presenter.rb b/app/presenters/status_relationships_presenter.rb index 10b449504..bc3887a44 100644 --- a/app/presenters/status_relationships_presenter.rb +++ b/app/presenters/status_relationships_presenter.rb @@ -11,7 +11,7 @@ class StatusRelationshipsPresenter @pins_map = {} else statuses = statuses.compact - status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq + status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq.compact conversation_ids = statuses.map(&:conversation_id).compact.uniq pinnable_status_ids = statuses.map(&:proper).select { |s| s.account_id == current_account_id && %w(public unlisted).include?(s.visibility) }.map(&:id) -- cgit