diff options
Diffstat (limited to 'app/lib/activitypub/activity/delete.rb')
-rw-r--r-- | app/lib/activitypub/activity/delete.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/app/lib/activitypub/activity/delete.rb b/app/lib/activitypub/activity/delete.rb index 8270fed1b..dc76dd3e2 100644 --- a/app/lib/activitypub/activity/delete.rb +++ b/app/lib/activitypub/activity/delete.rb @@ -21,11 +21,14 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity def delete_note return if object_uri.nil? + unless invalid_origin?(object_uri) + RedisLock.acquire(lock_options) { |_lock| delete_later!(object_uri) } + Tombstone.find_or_create_by(uri: object_uri, account: @account) + end + @status = Status.find_by(uri: object_uri, account: @account) @status ||= Status.find_by(uri: @object['atomUri'], account: @account) if @object.is_a?(Hash) && @object['atomUri'].present? - delete_later!(object_uri) - return if @status.nil? if @status.public_visibility? || @status.unlisted_visibility? @@ -68,4 +71,17 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity def payload @payload ||= Oj.dump(@json) end + + def lock_options + { redis: Redis.current, key: "create:#{object_uri}" } + end + + def invalid_origin?(url) + return true if unsupported_uri_scheme?(url) + + needle = Addressable::URI.parse(url).host + haystack = Addressable::URI.parse(@account.uri).host + + !haystack.casecmp(needle).zero? + end end |