Stop trying to shoehorn all Salmon updates into the poor database-connected

StreamEntry model. Simply render Salmon slaps as they are needed
This commit is contained in:
Eugen Rochko
2017-02-12 00:48:53 +01:00
parent 94d2182717
commit 0518492158
22 changed files with 304 additions and 266 deletions

View File

@ -7,7 +7,7 @@ class FollowService < BaseService
# @param [Account] source_account From which to follow
# @param [String] uri User URI to follow in the form of username@domain
def call(source_account, uri)
target_account = follow_remote_account_service.call(uri)
target_account = FollowRemoteAccountService.new.call(uri)
raise ActiveRecord::RecordNotFound if target_account.nil? || target_account.id == source_account.id || target_account.suspended?
raise Mastodon::NotPermitted if target_account.blocking?(source_account) || source_account.blocking?(target_account)
@ -27,7 +27,7 @@ class FollowService < BaseService
if target_account.local?
NotifyService.new.call(target_account, follow_request)
else
NotificationWorker.perform_async(stream_entry_to_xml(follow_request.stream_entry), source_account.id, target_account.id)
NotificationWorker.perform_async(build_follow_request_xml(follow_request), source_account.id, target_account.id)
AfterRemoteFollowRequestWorker.perform_async(follow_request.id)
end
@ -40,13 +40,12 @@ class FollowService < BaseService
if target_account.local?
NotifyService.new.call(target_account, follow)
else
subscribe_service.call(target_account) unless target_account.subscribed?
NotificationWorker.perform_async(stream_entry_to_xml(follow.stream_entry), source_account.id, target_account.id)
SubscribeService.new.call(target_account) unless target_account.subscribed?
NotificationWorker.perform_async(build_follow_xml(follow), source_account.id, target_account.id)
AfterRemoteFollowWorker.perform_async(follow.id)
end
MergeWorker.perform_async(target_account.id, source_account.id)
Pubsubhubbub::DistributionWorker.perform_async(follow.stream_entry.id)
follow
end
@ -55,11 +54,41 @@ class FollowService < BaseService
Redis.current
end
def follow_remote_account_service
@follow_remote_account_service ||= FollowRemoteAccountService.new
def build_follow_request_xml(follow_request)
Nokogiri::XML::Builder.new do |xml|
entry(xml, true) do
title xml, "#{follow_request.account.acct} requested to follow #{follow_request.target_account.acct}"
author(xml) do
include_author xml, follow_request.account
end
object_type xml, :activity
verb xml, :request_friend
target(xml) do
include_author xml, follow_request.target_account
end
end
end.to_xml
end
def subscribe_service
@subscribe_service ||= SubscribeService.new
def build_follow_xml(follow)
Nokogiri::XML::Builder.new do |xml|
entry(xml, true) do
title xml, "#{follow.account.acct} started following #{follow.target_account.acct}"
author(xml) do
include_author xml, follow.account
end
object_type xml, :activity
verb xml, :follow
target(xml) do
include_author xml, follow.target_account
end
end
end.to_xml
end
end