fedibird-fe/app/services/un_emoji_reaction_service.rb

32 lines
906 B
Ruby
Raw Normal View History

2021-05-19 05:58:27 +00:00
# frozen_string_literal: true
class UnEmojiReactionService < BaseService
include Payloadable
def call(account, status)
@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
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)
Oj.dump(serialize_payload(emoji_reaction, ActivityPub::UndoEmojiReactionSerializer, signer: @account))
2021-05-19 05:58:27 +00:00
end
end