2021-05-19 05:58:27 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UnEmojiReactionService < BaseService
|
|
|
|
include Payloadable
|
|
|
|
|
|
|
|
def call(account, status)
|
2021-08-28 18:35:09 +00:00
|
|
|
@account = account
|
|
|
|
|
2021-05-19 05:58:27 +00:00
|
|
|
emoji_reaction = EmojiReaction.find_by!(account: account, status: status)
|
|
|
|
|
|
|
|
emoji_reaction.destroy!
|
|
|
|
create_notification(emoji_reaction)
|
|
|
|
emoji_reaction
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_notification(emoji_reaction)
|
|
|
|
status = emoji_reaction.status
|
|
|
|
|
2021-08-28 18:35:09 +00:00
|
|
|
if status.account.local?
|
|
|
|
ActivityPub::RawDistributionWorker.perform_async(build_json(emoji_reaction), status.account.id, [@account.preferred_inbox_url])
|
|
|
|
elsif status.account.activitypub?
|
2021-05-19 05:58:27 +00:00
|
|
|
ActivityPub::DeliveryWorker.perform_async(build_json(emoji_reaction), emoji_reaction.account_id, status.account.inbox_url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_json(emoji_reaction)
|
2021-08-28 18:35:09 +00:00
|
|
|
Oj.dump(serialize_payload(emoji_reaction, ActivityPub::UndoEmojiReactionSerializer, signer: @account))
|
2021-05-19 05:58:27 +00:00
|
|
|
end
|
|
|
|
end
|