Pleroma AP detection mechanism.
authorlain <lain@soykaf.club>
Sat, 24 Feb 2018 12:06:53 +0000 (13:06 +0100)
committerlain <lain@soykaf.club>
Sat, 24 Feb 2018 12:06:53 +0000 (13:06 +0100)
lib/pleroma/web/ostatus/ostatus.ex
lib/pleroma/web/ostatus/user_representer.ex
test/web/ostatus/ostatus_test.exs
test/web/ostatus/user_representer_test.exs

index 3f5cfdc8abf3f596c7e2b6a90b3246de7c8b936a..66e1192125513729e2b77ec5e2ca1d73cde01d9b 100644 (file)
@@ -177,6 +177,13 @@ defmodule Pleroma.Web.OStatus do
   end
 
   def maybe_update(doc, user) do
+    if "true" == string_from_xpath("//author[1]/ap_enabled", doc) do
+      Transmogrifier.upgrade_user_from_ap_id(user.ap_id)
+    else
+      maybe_update_ostatus(doc, user)
+    end
+  end
+  def maybe_update_ostatus(doc, user) do
     old_data = %{
       avatar: user.avatar,
       bio: user.bio,
index 20ebb3e08b10d6f4b2c326978ff2b3d30e56cbd7..5af439c9d6c0153ec74cf06b2745c531de8409d2 100644 (file)
@@ -12,6 +12,12 @@ defmodule Pleroma.Web.OStatus.UserRepresenter do
       []
     end
 
+    ap_enabled = if user.local do
+      [{:ap_enabled, ['true']}]
+    else
+      []
+    end
+
     [
       {:id, [ap_id]},
       {:"activity:object", ['http://activitystrea.ms/schema/1.0/person']},
@@ -22,6 +28,6 @@ defmodule Pleroma.Web.OStatus.UserRepresenter do
       {:summary, [bio]},
       {:name, [nickname]},
       {:link, [rel: 'avatar', href: avatar_url], []}
-    ] ++ banner
+    ] ++ banner ++ ap_enabled
   end
 end
index 1dd381ac4f971a56ff6da6f1f1fef0cd9990e148..bb995199cac4c39c8a9b24571209a494f9004df7 100644 (file)
@@ -306,7 +306,8 @@ defmodule Pleroma.Web.OStatusTest do
         "fqn" => user,
         "bio" => "cofe",
         "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]},
-        "subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}"
+        "subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}",
+        "ap_id" => nil
       }
       assert data == expected
     end
@@ -330,7 +331,8 @@ defmodule Pleroma.Web.OStatusTest do
         "fqn" => user,
         "bio" => "cofe",
         "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]},
-        "subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}"
+        "subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}",
+        "ap_id" => nil
       }
       assert data == expected
     end
index b224203794d053273545ddde82a7144b6e0c5e93..e41dfeb3d0f7f898653ceb3162b5d9010979dc9b 100644 (file)
@@ -22,6 +22,7 @@ defmodule Pleroma.Web.OStatus.UserRepresenterTest do
     <name>#{user.nickname}</name>
     <link rel="avatar" href="#{User.avatar_url(user)}" />
     <link rel="header" href="#{User.banner_url(user)}" />
+    <ap_enabled>true</ap_enabled>
     """
 
     assert clean(res) == clean(expected)