Add extensive delivery of emoji reactions

This commit is contained in:
noellabo 2021-08-29 03:35:09 +09:00
parent 55889974a3
commit 6e86e744d2
5 changed files with 24 additions and 6 deletions

View file

@ -44,7 +44,10 @@ class ActivityPub::Activity::Like < ActivityPub::Activity
EmojiReaction.find_by(account: @account, status: @original_status)&.destroy!
reaction = @original_status.emoji_reactions.create!(account: @account, name: shortcode, custom_emoji: emoji, uri: @json['id'])
NotifyService.new.call(@original_status.account, :emoji_reaction, reaction) if @original_status.account.local?
if @original_status.account.local?
NotifyService.new.call(@original_status.account, :emoji_reaction, reaction)
ActivityPub::RawDistributionWorker.perform_async(Oj.dump(@json), @original_status.account.id, [@account.preferred_inbox_url])
end
rescue Seahorse::Client::NetworkingError
nil
end

View file

@ -110,7 +110,7 @@ class ActivityPub::Activity::Undo < ActivityPub::Activity
def undo_like
status = status_from_uri(target_uri)
return if status.nil? || !status.account.local?
return if status.nil?
if shortcode.present?
emoji_tag = @object['tag'].is_a?(Array) ? @object['tag']&.first : @object['tag']
@ -121,6 +121,10 @@ class ActivityPub::Activity::Undo < ActivityPub::Activity
if @account.reacted?(status, shortcode, emoji)
status.emoji_reactions.where(account: @account, name: shortcode, custom_emoji: emoji).first&.destroy
if status.account.local?
ActivityPub::RawDistributionWorker.perform_async(Oj.dump(@json), status.account.id, [@account.preferred_inbox_url])
end
else
delete_later!(object_uri)
end

View file

@ -33,6 +33,10 @@ class EmojiReaction < ApplicationRecord
self.status = status.reblog if status&.reblog?
end
def sign?
true
end
private
def queue_publish

View file

@ -5,6 +5,8 @@ class EmojiReactionService < BaseService
include Payloadable
def call(account, status, emoji)
@account = account
emoji_reaction = EmojiReaction.find_by(account_id: account.id, status_id: status.id)
return emoji_reaction unless emoji_reaction.nil?
@ -27,7 +29,8 @@ class EmojiReactionService < BaseService
status = emoji_reaction.status
if status.account.local?
NotifyService.new.call(status.account, :emoji_reaction, emoji_reaction)
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])
elsif status.account.activitypub?
ActivityPub::DeliveryWorker.perform_async(build_json(emoji_reaction), emoji_reaction.account_id, status.account.inbox_url)
end
@ -40,6 +43,6 @@ class EmojiReactionService < BaseService
end
def build_json(emoji_reaction)
Oj.dump(serialize_payload(emoji_reaction, ActivityPub::EmojiReactionSerializer))
Oj.dump(serialize_payload(emoji_reaction, ActivityPub::EmojiReactionSerializer, signer: @account))
end
end

View file

@ -4,6 +4,8 @@ class UnEmojiReactionService < BaseService
include Payloadable
def call(account, status)
@account = account
emoji_reaction = EmojiReaction.find_by!(account: account, status: status)
emoji_reaction.destroy!
@ -16,12 +18,14 @@ class UnEmojiReactionService < BaseService
def create_notification(emoji_reaction)
status = emoji_reaction.status
if !status.account.local? && status.account.activitypub?
if status.account.local?
ActivityPub::RawDistributionWorker.perform_async(build_json(emoji_reaction), status.account.id, [@account.preferred_inbox_url])
elsif status.account.activitypub?
ActivityPub::DeliveryWorker.perform_async(build_json(emoji_reaction), emoji_reaction.account_id, status.account.inbox_url)
end
end
def build_json(emoji_reaction)
Oj.dump(serialize_payload(emoji_reaction, ActivityPub::UndoEmojiReactionSerializer))
Oj.dump(serialize_payload(emoji_reaction, ActivityPub::UndoEmojiReactionSerializer, signer: @account))
end
end