1
0
Fork 0
forked from fedi/mastodon
mastodon/app/lib/activitypub/activity/delete.rb
Eugen Rochko 1b5806b744 Define missing JSON-LD properties (#4767)
Using _: property names is discouraged, as in the future,
canonicalization may throw an error when encountering that instead
of discarding it silently like it does now.

We are defining some ActivityStreams properties which we expect
to land in ActivityStreams eventually, to ensure that future versions
of Mastodon will remain compatible with this even once that happens.
Those would be `locked`, `sensitive` and `Hashtag`

We are defining a custom context inline for some properties which we
do not expect to land in any other context. `atomUri`, `inReplyToAtomUri`
and `conversation` are part of the custom defined OStatus context.
2017-09-02 14:01:23 +02:00

46 lines
1 KiB
Ruby

# frozen_string_literal: true
class ActivityPub::Activity::Delete < ActivityPub::Activity
def perform
if @account.uri == object_uri
delete_person
else
delete_note
end
end
private
def delete_person
SuspendAccountService.new.call(@account)
end
def delete_note
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?
forward_for_reblogs(status)
delete_now!(status)
end
def forward_for_reblogs(status)
return if @json['signature'].blank?
ActivityPub::RawDistributionWorker.push_bulk(status.reblogs.includes(:account).references(:account).merge(Account.local).pluck(:account_id)) do |account_id|
[payload, account_id]
end
end
def delete_now!(status)
RemoveStatusService.new.call(status)
end
def payload
@payload ||= Oj.dump(@json)
end
end