Allow private posts with references

This commit is contained in:
KMY 2023-09-19 18:50:16 +09:00
parent 818bcc0277
commit 11300d7550
2 changed files with 41 additions and 8 deletions

View file

@ -11,8 +11,6 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
:atom_uri, :in_reply_to_atom_uri,
:conversation, :searchable_by, :limited_scope
attribute :references, if: :not_private_post?
attribute :content
attribute :content_map, if: :language?
attribute :updated, if: :edited?
@ -25,6 +23,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
has_many :virtual_tags, key: :tag
has_one :replies, serializer: ActivityPub::CollectionSerializer, if: :local?
has_one :references, serializer: ActivityPub::CollectionSerializer
has_many :poll_options, key: :one_of, if: :poll_and_not_multiple?
has_many :poll_options, key: :any_of, if: :poll_and_multiple?
@ -71,7 +70,19 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
end
def references
ActivityPub::TagManager.instance.references_uri_for(object)
refs = object.references.reorder(id: :asc).take(5).pluck(:id, :uri)
last_id = refs.last&.first
ActivityPub::CollectionPresenter.new(
type: :unordered,
id: ActivityPub::TagManager.instance.references_uri_for(object),
first: ActivityPub::CollectionPresenter.new(
type: :unordered,
part_of: ActivityPub::TagManager.instance.references_uri_for(object),
items: refs.map(&:second),
next: last_id ? ActivityPub::TagManager.instance.references_uri_for(object, page: true, min_id: last_id) : ActivityPub::TagManager.instance.references_uri_for(object, page: true, only_other_accounts: true)
)
)
end
def language?
@ -160,10 +171,6 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
object.account.local?
end
def not_private_post?
!object.private_visibility? && !object.direct_visibility? && !object.limited_visibility?
end
def quote?
object.references.count == 1 && object.account.user&.settings&.[]('single_ref_to_quote')
end