2021-05-19 05:58:27 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class EmojiReactionService < BaseService
|
|
|
|
include Authorization
|
|
|
|
include Payloadable
|
|
|
|
|
|
|
|
def call(account, status, emoji)
|
2021-08-28 18:35:09 +00:00
|
|
|
@account = account
|
|
|
|
|
2021-05-19 05:58:27 +00:00
|
|
|
emoji_reaction = EmojiReaction.find_by(account_id: account.id, status_id: status.id)
|
|
|
|
|
|
|
|
return emoji_reaction unless emoji_reaction.nil?
|
|
|
|
|
|
|
|
shortcode, domain = emoji.split("@")
|
|
|
|
|
|
|
|
custom_emoji = CustomEmoji.find_by(shortcode: shortcode, domain: domain)
|
|
|
|
|
|
|
|
emoji_reaction = EmojiReaction.create!(account: account, status: status, name: shortcode, custom_emoji: custom_emoji)
|
|
|
|
|
|
|
|
create_notification(emoji_reaction)
|
|
|
|
bump_potential_friendship(account, status)
|
|
|
|
|
|
|
|
emoji_reaction
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_notification(emoji_reaction)
|
|
|
|
status = emoji_reaction.status
|
|
|
|
|
|
|
|
if status.account.local?
|
2021-08-28 18:35:09 +00:00
|
|
|
NotifyService.new.call(status.account, :emoji_reaction, emoji_reaction) if status.account.local?
|
|
|
|
ActivityPub::RawDistributionWorker.perform_async(build_json(emoji_reaction), status.account.id, [@account.preferred_inbox_url])
|
2021-05-19 05:58:27 +00:00
|
|
|
elsif status.account.activitypub?
|
|
|
|
ActivityPub::DeliveryWorker.perform_async(build_json(emoji_reaction), emoji_reaction.account_id, status.account.inbox_url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def bump_potential_friendship(account, status)
|
|
|
|
ActivityTracker.increment('activity:interactions')
|
|
|
|
return if account.following?(status.account_id)
|
|
|
|
PotentialFriendshipTracker.record(account.id, status.account_id, :emoji_reaction)
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_json(emoji_reaction)
|
2021-08-28 18:35:09 +00:00
|
|
|
Oj.dump(serialize_payload(emoji_reaction, ActivityPub::EmojiReactionSerializer, signer: @account))
|
2021-05-19 05:58:27 +00:00
|
|
|
end
|
|
|
|
end
|