Merge commit 'f652c54c3334890176331f62150559a96eeb41ae' into glitch-soc/merge-upstream
Conflicts: - `app/services/backup_service.rb`: Upstream refactored activity serialization while glitch-soc passed an extra argument. Followed upstream's refactor, keeping our extra argument.
This commit is contained in:
commit
59e02a628d
108 files changed
+1228
-995
No files matched your search
@@ -1,20 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::ActivitySerializer < ActivityPub::Serializer
|
||||
def self.serializer_for(model, options)
|
||||
case model.class.name
|
||||
when 'Status'
|
||||
ActivityPub::NoteSerializer
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
attributes :id, :type, :actor, :published, :to, :cc
|
||||
|
||||
has_one :virtual_object, key: :object
|
||||
|
||||
def published
|
||||
object.published.iso8601
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::AddFeaturedCollectionSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :actor, :target
|
||||
has_one :object, serializer: ActivityPub::FeaturedCollectionSerializer
|
||||
|
||||
def type
|
||||
'Add'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def target
|
||||
ap_account_featured_collections_url(object.account_id)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::AddHashtagSerializer < ActivityPub::Serializer
|
||||
attributes :type, :actor, :target
|
||||
|
||||
has_one :object, serializer: ActivityPub::HashtagSerializer
|
||||
|
||||
def type
|
||||
'Add'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def target
|
||||
# Technically this is not correct, as tags have their own collection.
|
||||
# But sadly we do not store the collection URI for tags anywhere so cannot
|
||||
# handle `Add` activities to that properly (yet). The receiving code for
|
||||
# this currently looks at the type of the contained objects to do the
|
||||
# right thing.
|
||||
ActivityPub::TagManager.instance.collection_uri_for(object.account, :featured)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::AddNoteSerializer < ActivityPub::Serializer
|
||||
attributes :type, :actor, :target
|
||||
|
||||
has_one :proper_object, key: :object
|
||||
|
||||
def type
|
||||
'Add'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def proper_object
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def target
|
||||
ActivityPub::TagManager.instance.collection_uri_for(object.account, :featured)
|
||||
end
|
||||
end
|
||||
@@ -1,55 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::AddSerializer < ActivityPub::Serializer
|
||||
class UriSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
def serializable_hash(*_args)
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
end
|
||||
|
||||
def self.serializer_for(model, options)
|
||||
case model
|
||||
when Status
|
||||
UriSerializer
|
||||
when FeaturedTag
|
||||
ActivityPub::HashtagSerializer
|
||||
when Collection
|
||||
ActivityPub::FeaturedCollectionSerializer
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :actor, :target
|
||||
has_one :proper_object, key: :object
|
||||
|
||||
def type
|
||||
'Add'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def proper_object
|
||||
object
|
||||
end
|
||||
|
||||
def target
|
||||
case object
|
||||
when Status, FeaturedTag
|
||||
# Technically this is not correct, as tags have their own collection.
|
||||
# But sadly we do not store the collection URI for tags anywhere so cannot
|
||||
# handle `Add` activities to that properly (yet). The receiving code for
|
||||
# this currently looks at the type of the contained objects to do the
|
||||
# right thing.
|
||||
ActivityPub::TagManager.instance.collection_uri_for(object.account, :featured)
|
||||
when Collection
|
||||
ap_account_featured_collections_url(object.account_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,53 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::AnnounceNoteSerializer < ActivityPub::Serializer
|
||||
def self.serializer_for(model, options)
|
||||
return ActivityPub::NoteSerializer if model.is_a?(Status)
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
attributes :id, :type, :actor, :published, :to, :cc
|
||||
|
||||
has_one :virtual_object, key: :object
|
||||
|
||||
def id
|
||||
ActivityPub::TagManager.instance.activity_uri_for(object)
|
||||
end
|
||||
|
||||
def type
|
||||
'Announce'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def to
|
||||
ActivityPub::TagManager.instance.to(object)
|
||||
end
|
||||
|
||||
def cc
|
||||
ActivityPub::TagManager.instance.cc(object)
|
||||
end
|
||||
|
||||
def published
|
||||
object.created_at.iso8601
|
||||
end
|
||||
|
||||
def virtual_object
|
||||
if allow_inlining? && object.account == object.proper.account && object.proper.private_visibility? && object.local?
|
||||
object.proper
|
||||
else
|
||||
ActivityPub::TagManager.instance.uri_for(object.proper)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def allow_inlining?
|
||||
return instance_options[:allow_inlining] if instance_options.key?(:allow_inlining)
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::CreateNoteSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :published, :to, :cc
|
||||
|
||||
has_one :object, serializer: ActivityPub::NoteSerializer
|
||||
|
||||
def id
|
||||
ActivityPub::TagManager.instance.activity_uri_for(object)
|
||||
end
|
||||
|
||||
def type
|
||||
'Create'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def to
|
||||
ActivityPub::TagManager.instance.to(object)
|
||||
end
|
||||
|
||||
def cc
|
||||
ActivityPub::TagManager.instance.cc(object)
|
||||
end
|
||||
|
||||
def published
|
||||
object.created_at.iso8601
|
||||
end
|
||||
end
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::DeleteSerializer < ActivityPub::Serializer
|
||||
class ActivityPub::DeleteNoteSerializer < ActivityPub::Serializer
|
||||
class TombstoneSerializer < ActivityPub::Serializer
|
||||
context_extensions :atom_uri
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
|
||||
class ActivityPub::OutboxSerializer < ActivityPub::CollectionSerializer
|
||||
def self.serializer_for(model, options)
|
||||
if model.instance_of?(::ActivityPub::ActivityPresenter)
|
||||
ActivityPub::ActivitySerializer
|
||||
case model
|
||||
when Status
|
||||
model.reblog? ? ActivityPub::AnnounceNoteSerializer : ActivityPub::CreateNoteSerializer
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def items
|
||||
object.items.map { |status| ActivityPub::ActivityPresenter.from_status(status) }
|
||||
object.items
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::RemoveFeaturedCollectionSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :actor, :target
|
||||
has_one :object_uri, key: :object
|
||||
|
||||
def type
|
||||
'Remove'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def target
|
||||
ap_account_featured_collections_url(object.account_id)
|
||||
end
|
||||
|
||||
def object_uri
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::RemoveHashtagSerializer < ActivityPub::Serializer
|
||||
attributes :type, :actor, :target
|
||||
has_one :object, serializer: ActivityPub::HashtagSerializer
|
||||
|
||||
def type
|
||||
'Remove'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def target
|
||||
ActivityPub::TagManager.instance.collection_uri_for(object.account, :featured)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::RemoveNoteSerializer < ActivityPub::Serializer
|
||||
attributes :type, :actor, :target
|
||||
has_one :proper_object, key: :object
|
||||
|
||||
def type
|
||||
'Remove'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def proper_object
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def target
|
||||
ActivityPub::TagManager.instance.collection_uri_for(object.account, :featured)
|
||||
end
|
||||
end
|
||||
@@ -1,43 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::RemoveSerializer < ActivityPub::Serializer
|
||||
class UriSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
def serializable_hash(*_args)
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
end
|
||||
|
||||
def self.serializer_for(model, options)
|
||||
case model.class.name
|
||||
when 'Status'
|
||||
UriSerializer
|
||||
when 'FeaturedTag'
|
||||
ActivityPub::HashtagSerializer
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :actor, :target
|
||||
has_one :proper_object, key: :object
|
||||
|
||||
def type
|
||||
'Remove'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def proper_object
|
||||
object
|
||||
end
|
||||
|
||||
def target
|
||||
ActivityPub::TagManager.instance.collection_uri_for(object.account, :featured)
|
||||
end
|
||||
end
|
||||
@@ -3,7 +3,11 @@
|
||||
class ActivityPub::UndoAnnounceSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :to
|
||||
|
||||
has_one :virtual_object, key: :object, serializer: ActivityPub::ActivitySerializer
|
||||
has_one :virtual_object, key: :object, serializer: ActivityPub::AnnounceNoteSerializer do |serializer|
|
||||
serializer.send(:instance_options)[:allow_inlining] = false
|
||||
|
||||
object
|
||||
end
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object.account), '#announces/', object.id, '/undo'].join
|
||||
@@ -22,6 +26,6 @@ class ActivityPub::UndoAnnounceSerializer < ActivityPub::Serializer
|
||||
end
|
||||
|
||||
def virtual_object
|
||||
ActivityPub::ActivityPresenter.from_status(object, allow_inlining: false)
|
||||
object
|
||||
end
|
||||
end
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UpdateSerializer < ActivityPub::Serializer
|
||||
class ActivityPub::UpdateActorSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :to
|
||||
|
||||
has_one :object, serializer: ActivityPub::ActorSerializer
|
||||
@@ -0,0 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UpdateNoteSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :published, :to, :cc
|
||||
|
||||
has_one :object, serializer: ActivityPub::NoteSerializer
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object), '#updates/', edited_at.to_i].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Update'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def to
|
||||
ActivityPub::TagManager.instance.to(object)
|
||||
end
|
||||
|
||||
def cc
|
||||
ActivityPub::TagManager.instance.cc(object)
|
||||
end
|
||||
|
||||
def published
|
||||
edited_at.iso8601
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def edited_at
|
||||
instance_options[:updated_at]&.to_datetime || object.edited_at
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user