fedibird-fe/app/services/emoji_reaction_service.rb

49 lines
1.6 KiB
Ruby
Raw Normal View History

2021-05-19 05:58:27 +00:00
# frozen_string_literal: true
class EmojiReactionService < BaseService
include Authorization
include Payloadable
def call(account, status, emoji)
@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?
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)
Oj.dump(serialize_payload(emoji_reaction, ActivityPub::EmojiReactionSerializer, signer: @account))
2021-05-19 05:58:27 +00:00
end
end