2022-11-29 07:23:13 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-11-29 17:15:52 +09:00
|
|
|
class ReactService < BaseService
|
2022-11-29 07:23:13 +09:00
|
|
|
include Authorization
|
|
|
|
include Payloadable
|
|
|
|
|
|
|
|
def call(account, status, emoji)
|
2023-05-08 05:05:44 +09:00
|
|
|
authorize_with account, status, :react?
|
|
|
|
|
2022-11-29 09:39:40 +09:00
|
|
|
name, domain = emoji.split('@')
|
2023-05-17 21:26:40 +09:00
|
|
|
return unless domain.nil? || status.local?
|
|
|
|
|
2022-11-29 09:39:40 +09:00
|
|
|
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-29 07:23:13 +09:00
|
|
|
return reaction unless reaction.nil?
|
|
|
|
|
|
|
|
reaction = StatusReaction.create!(account: account, status: status, name: name, custom_emoji: custom_emoji)
|
|
|
|
|
2023-11-13 11:59:36 +09:00
|
|
|
Trends.statuses.register(status)
|
|
|
|
|
|
|
|
create_notification(reaction)
|
2023-12-30 03:50:42 +09:00
|
|
|
increment_statistics
|
2023-11-13 11:59:36 +09:00
|
|
|
|
|
|
|
reaction
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_notification(reaction)
|
|
|
|
status = reaction.status
|
|
|
|
|
2022-11-29 07:23:13 +09:00
|
|
|
if status.account.local?
|
2023-11-13 11:59:36 +09:00
|
|
|
LocalNotificationWorker.perform_async(status.account_id, reaction.id, 'StatusReaction', 'reaction')
|
|
|
|
elsif status.account.activitypub?
|
|
|
|
ActivityPub::DeliveryWorker.perform_async(build_json(reaction), reaction.account_id, status.account.inbox_url)
|
2022-11-29 07:23:13 +09:00
|
|
|
end
|
2023-11-13 11:59:36 +09:00
|
|
|
end
|
2022-11-29 07:23:13 +09:00
|
|
|
|
2023-12-30 03:50:42 +09:00
|
|
|
def increment_statistics
|
2022-11-29 07:23:13 +09:00
|
|
|
ActivityTracker.increment('activity:interactions')
|
2023-11-13 11:59:36 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def build_json(reaction)
|
|
|
|
Oj.dump(serialize_payload(reaction, ActivityPub::EmojiReactionSerializer))
|
2022-11-29 07:23:13 +09:00
|
|
|
end
|
|
|
|
end
|