2023-11-08 09:43:47 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UnreactService < BaseService
|
|
|
|
include Payloadable
|
|
|
|
|
|
|
|
def call(account, status, emoji)
|
|
|
|
name, domain = emoji.split('@')
|
|
|
|
custom_emoji = CustomEmoji.find_by(shortcode: name, domain: domain)
|
|
|
|
reaction = StatusReaction.find_by(account: account, status: status, name: name, custom_emoji: custom_emoji)
|
|
|
|
return if reaction.nil?
|
|
|
|
|
|
|
|
reaction.destroy!
|
2023-11-13 11:59:36 +09:00
|
|
|
create_notification(reaction) if !status.account.local? && status.account.activitypub?
|
|
|
|
reaction
|
|
|
|
end
|
2023-11-08 09:43:47 +09:00
|
|
|
|
2023-11-13 11:59:36 +09:00
|
|
|
private
|
2023-11-08 09:43:47 +09:00
|
|
|
|
2023-11-13 11:59:36 +09:00
|
|
|
def create_notification(reaction)
|
|
|
|
status = reaction.status
|
|
|
|
ActivityPub::DeliveryWorker.perform_async(build_json(reaction), reaction.account_id, status.account.inbox_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_json(reaction)
|
|
|
|
Oj.dump(serialize_payload(reaction, ActivityPub::UndoEmojiReactionSerializer))
|
2023-11-08 09:43:47 +09:00
|
|
|
end
|
|
|
|
end
|