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