mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-22 10:38:07 +01:00
Refactor react services
This commit is contained in:
parent
421e3ea8ba
commit
8eda40cfb3
2 changed files with 35 additions and 16 deletions
|
@ -16,16 +16,31 @@ class ReactService < BaseService
|
|||
|
||||
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?
|
||||
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
|
||||
Trends.statuses.register(status)
|
||||
|
||||
ActivityTracker.increment('activity:interactions')
|
||||
create_notification(reaction)
|
||||
increment_statistics
|
||||
|
||||
reaction
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_notification(reaction)
|
||||
status = reaction.status
|
||||
|
||||
if status.account.local?
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
def increment_statistics
|
||||
ActivityTracker.increment('activity:interactions')
|
||||
end
|
||||
|
||||
def build_json(reaction)
|
||||
Oj.dump(serialize_payload(reaction, ActivityPub::EmojiReactionSerializer))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,14 +10,18 @@ class UnreactService < BaseService
|
|||
return if reaction.nil?
|
||||
|
||||
reaction.destroy!
|
||||
|
||||
json = Oj.dump(serialize_payload(reaction, ActivityPub::UndoEmojiReactionSerializer))
|
||||
if status.account.local?
|
||||
ActivityPub::RawDistributionWorker.perform_async(json, status.account.id)
|
||||
else
|
||||
ActivityPub::DeliveryWorker.perform_async(json, reaction.account_id, status.account.inbox_url)
|
||||
end
|
||||
|
||||
create_notification(reaction) if !status.account.local? && status.account.activitypub?
|
||||
reaction
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_notification(reaction)
|
||||
status = reaction.status
|
||||
ActivityPub::DeliveryWorker.perform_async(build_json(reaction), reaction.account_id, status.account.inbox_url)
|
||||
end
|
||||
|
||||
def build_json(reaction)
|
||||
Oj.dump(serialize_payload(reaction, ActivityPub::UndoEmojiReactionSerializer))
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue