about summary refs log tree commit diff
path: root/app/services/follow_service.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-02-12 00:48:53 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-02-12 01:19:14 +0100
commit0518492158af247f3b99a8f27f4498d1bcc91117 (patch)
tree4e82d1e73bd9a8ac1096d788b684283c8f8c93dd /app/services/follow_service.rb
parent94d21827174c52a6b70ba2e45f098223f5d904fa (diff)
Stop trying to shoehorn all Salmon updates into the poor database-connected
StreamEntry model. Simply render Salmon slaps as they are needed
Diffstat (limited to 'app/services/follow_service.rb')
-rw-r--r--app/services/follow_service.rb47
1 files changed, 38 insertions, 9 deletions
diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb
index ac0392d16..5a4250636 100644
--- a/app/services/follow_service.rb
+++ b/app/services/follow_service.rb
@@ -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