2022-11-28 23:23:13 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusReactionService < BaseService
|
|
|
|
include Authorization
|
|
|
|
include Payloadable
|
|
|
|
|
|
|
|
def call(account, status, emoji)
|
2022-11-29 01:39:40 +01:00
|
|
|
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)
|
2022-11-28 23:23:13 +01:00
|
|
|
return reaction unless reaction.nil?
|
|
|
|
|
|
|
|
reaction = StatusReaction.create!(account: account, status: status, name: name, custom_emoji: custom_emoji)
|
|
|
|
|
|
|
|
json = Oj.dump(serialize_payload(reaction, ActivityPub::EmojiReactionSerializer))
|
|
|
|
if status.account.local?
|
2022-11-29 04:31:22 +01:00
|
|
|
NotifyService.new.call(status.account, :reaction, reaction)
|
2022-11-28 23:23:13 +01:00
|
|
|
ActivityPub::RawDistributionWorker.perform_async(json, status.account.id)
|
|
|
|
else
|
|
|
|
ActivityPub::DeliveryWorker.perform_async(json, reaction.account_id, status.account.inbox_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
ActivityTracker.increment('activity:interactions')
|
|
|
|
|
|
|
|
reaction
|
|
|
|
end
|
|
|
|
end
|