This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
mastodon/app/services/react_service.rb

28 lines
980 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2022-11-29 00:15:52 -08:00
class ReactService < BaseService
include Authorization
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 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-28 19:31:22 -08:00
NotifyService.new.call(status.account, :reaction, reaction)
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