nas/app/presenters/status_relationships_presenter.rb
KMY(雪あすか) 44b739a39a
Add: Webでの引用表示 (#50)
* Add compacted component

* 引用表示の間にコンテナをはさみ、不要なコードを削除

* 引用APIを作成、ついでにブロック状況を引用APIに反映

* テスト修正など

* 引用をキャッシュに登録

* `quote_id`が`quote_of_id`になったのをSerializerに反映

* Fix test

* 引用をフィルターの対象に含める設定+エラー修正

* ストリーミングの存在しないプロパティ削除によるエラーを修正

* Fix lint

* 他のサーバーから来た引用付き投稿を処理

* Fix test

* フィルター設定時エラーの調整

* 画像つき投稿のスタイルを調整

* 画像つき投稿の最大高さを調整

* 引用禁止・非表示の設定を追加

* ブロック対応

* マイグレーションコード調整

* 引用設定の翻訳を作成

* Lint修正

* 参照1つの場合は引用に変換する設定を削除

* 不要になったテストを削除

* ブロック設定追加、バグ修正

* 他サーバーへ引用送信・受け入れ
2023-10-02 11:12:51 +09:00

66 lines
3.1 KiB
Ruby

# frozen_string_literal: true
class StatusRelationshipsPresenter
PINNABLE_VISIBILITIES = %w(public public_unlisted unlisted login private).freeze
attr_reader :reblogs_map, :favourites_map, :mutes_map, :pins_map, :blocks_map, :domain_blocks_map,
:bookmarks_map, :filters_map, :attributes_map, :emoji_reaction_allows_map
def initialize(statuses, current_account_id = nil, **options)
@current_account_id = current_account_id
if current_account_id.nil?
@reblogs_map = {}
@favourites_map = {}
@bookmarks_map = {}
@mutes_map = {}
@blocks_map = {}
@domain_blocks_map = {}
@pins_map = {}
@filters_map = {}
@emoji_reaction_allows_map = nil
else
statuses = statuses.compact
statuses += statuses.filter_map(&:quote)
status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq.compact
conversation_ids = statuses.filter_map(&:conversation_id).uniq
pinnable_status_ids = statuses.map(&:proper).filter_map { |s| s.id if s.account_id == current_account_id && PINNABLE_VISIBILITIES.include?(s.visibility) }
@filters_map = build_filters_map(statuses, current_account_id).merge(options[:filters_map] || {})
@reblogs_map = Status.reblogs_map(status_ids, current_account_id).merge(options[:reblogs_map] || {})
@favourites_map = Status.favourites_map(status_ids, current_account_id).merge(options[:favourites_map] || {})
@bookmarks_map = Status.bookmarks_map(status_ids, current_account_id).merge(options[:bookmarks_map] || {})
@mutes_map = Status.mutes_map(conversation_ids, current_account_id).merge(options[:mutes_map] || {})
@blocks_map = Status.blocks_map(statuses.map(&:account_id), current_account_id).merge(options[:blocks_map] || {})
@domain_blocks_map = Status.domain_blocks_map(statuses.filter_map { |status| status.account.domain }.uniq, current_account_id).merge(options[:domain_blocks_map] || {})
@pins_map = Status.pins_map(pinnable_status_ids, current_account_id).merge(options[:pins_map] || {})
@emoji_reaction_allows_map = Status.emoji_reaction_allows_map(status_ids, current_account_id).merge(options[:emoji_reaction_allows_map] || {})
@attributes_map = options[:attributes_map] || {}
end
end
private
def build_filters_map(statuses, current_account_id)
active_filters = CustomFilter.cached_filters_for(current_account_id)
@filters_map = statuses.each_with_object({}) do |status, h|
filter_matches = CustomFilter.apply_cached_filters(active_filters, status, following?(status.account_id))
unless filter_matches.empty?
h[status.id] = filter_matches
h[status.reblog_of_id] = filter_matches if status.reblog?
end
end
end
def following?(other_account_id)
return false if @current_account_id.nil?
@account ||= Account.find(@current_account_id)
return false unless @account
@following_map ||= @account.following.pluck(:id)
@following_map.include?(other_account_id)
end
end