Refactor react services
This commit is contained in:
parent
2df879f481
commit
39ef8cac9a
@ -6,6 +6,7 @@ class PotentialFriendshipTracker
|
|||||||
|
|
||||||
WEIGHTS = {
|
WEIGHTS = {
|
||||||
reply: 1,
|
reply: 1,
|
||||||
|
reaction: 5,
|
||||||
favourite: 10,
|
favourite: 10,
|
||||||
reblog: 20,
|
reblog: 20,
|
||||||
}.freeze
|
}.freeze
|
||||||
|
@ -16,16 +16,34 @@ class ReactService < BaseService
|
|||||||
|
|
||||||
reaction = StatusReaction.create!(account: account, status: status, name: name, custom_emoji: custom_emoji)
|
reaction = StatusReaction.create!(account: account, status: status, name: name, custom_emoji: custom_emoji)
|
||||||
|
|
||||||
json = Oj.dump(serialize_payload(reaction, ActivityPub::EmojiReactionSerializer))
|
Trends.statuses.register(status)
|
||||||
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
|
|
||||||
|
|
||||||
ActivityTracker.increment('activity:interactions')
|
create_notification(reaction)
|
||||||
|
bump_potential_friendship(account, status)
|
||||||
|
|
||||||
reaction
|
reaction
|
||||||
end
|
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 bump_potential_friendship(account, status)
|
||||||
|
ActivityTracker.increment('activity:interactions')
|
||||||
|
return if account.following?(status.account_id)
|
||||||
|
|
||||||
|
PotentialFriendshipTracker.record(account.id, status.account_id, :reaction)
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_json(reaction)
|
||||||
|
Oj.dump(serialize_payload(reaction, ActivityPub::EmojiReactionSerializer))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -10,14 +10,18 @@ class UnreactService < BaseService
|
|||||||
return if reaction.nil?
|
return if reaction.nil?
|
||||||
|
|
||||||
reaction.destroy!
|
reaction.destroy!
|
||||||
|
create_notification(reaction) if !status.account.local? && status.account.activitypub?
|
||||||
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
|
|
||||||
|
|
||||||
reaction
|
reaction
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user