2017-08-08 21:52:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub::Activity::Update < ActivityPub::Activity
|
2018-05-02 16:08:16 +02:00
|
|
|
SUPPORTED_TYPES = %w(Application Group Organization Person Service).freeze
|
|
|
|
|
2017-08-08 21:52:15 +02:00
|
|
|
def perform
|
2018-05-02 16:08:16 +02:00
|
|
|
update_account if equals_or_includes_any?(@object['type'], SUPPORTED_TYPES)
|
2019-03-11 00:49:31 +01:00
|
|
|
update_poll if equals_or_includes_any?(@object['type'], %w(Question))
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def update_account
|
|
|
|
return if @account.uri != object_uri
|
2018-09-18 16:45:58 +02:00
|
|
|
|
2018-08-26 20:21:03 +02:00
|
|
|
ActivityPub::ProcessAccountService.new.call(@account.username, @account.domain, @object, signed_with_known_key: true)
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
2019-03-11 00:49:31 +01:00
|
|
|
|
|
|
|
def update_poll
|
|
|
|
return reject_payload! if invalid_origin?(@object['id'])
|
|
|
|
status = Status.find_by(uri: object_uri, account_id: @account.id)
|
|
|
|
return if status.nil? || status.poll_id.nil?
|
|
|
|
poll = Poll.find(status.poll_id)
|
|
|
|
return if poll.nil?
|
|
|
|
|
|
|
|
ActivityPub::ProcessPollService.new.call(poll, @object)
|
|
|
|
end
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|