Browse Source

Add _:atomUri property for deduplicating OStatus/ActivityPub legacy records (#4593)

master
Eugen Rochko 7 years ago
committed by GitHub
parent
commit
ad892dbc0c
2 changed files with 17 additions and 1 deletions
  1. +7
    -1
      app/lib/activitypub/activity/create.rb
  2. +10
    -0
      app/serializers/activitypub/note_serializer.rb

+ 7
- 1
app/lib/activitypub/activity/create.rb View File

@ -4,7 +4,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
def perform def perform
return if delete_arrived_first?(object_uri) || unsupported_object_type? return if delete_arrived_first?(object_uri) || unsupported_object_type?
status = Status.find_by(uri: object_uri)
status = find_existing_status
return status unless status.nil? return status unless status.nil?
@ -23,6 +23,12 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
private private
def find_existing_status
status = Status.find_by(uri: object_uri)
status ||= Status.find_by(uri: @object['_:atomUri']) if @object['_:atomUri'].present?
status
end
def status_params def status_params
{ {
uri: @object['id'], uri: @object['id'],

+ 10
- 0
app/serializers/activitypub/note_serializer.rb View File

@ -8,6 +8,8 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
has_many :media_attachments, key: :attachment has_many :media_attachments, key: :attachment
has_many :virtual_tags, key: :tag has_many :virtual_tags, key: :tag
attribute :atom_uri, key: '_:atomUri', if: :local?
def id def id
ActivityPub::TagManager.instance.uri_for(object) ActivityPub::TagManager.instance.uri_for(object)
end end
@ -52,6 +54,14 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
object.mentions + object.tags object.mentions + object.tags
end end
def atom_uri
::TagManager.instance.uri_for(object)
end
def local?
object.account.local?
end
class MediaAttachmentSerializer < ActiveModel::Serializer class MediaAttachmentSerializer < ActiveModel::Serializer
include RoutingHelper include RoutingHelper

Loading…
Cancel
Save