From fb02300234f547363242f0a768b6d35e7a1a87be Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 24 Feb 2018 13:06:53 +0100 Subject: [PATCH] Pleroma AP detection mechanism. --- lib/pleroma/web/ostatus/ostatus.ex | 7 +++++++ lib/pleroma/web/ostatus/user_representer.ex | 8 +++++++- test/web/ostatus/ostatus_test.exs | 6 ++++-- test/web/ostatus/user_representer_test.exs | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 3f5cfdc8a..66e119212 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -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, diff --git a/lib/pleroma/web/ostatus/user_representer.ex b/lib/pleroma/web/ostatus/user_representer.ex index 20ebb3e08..5af439c9d 100644 --- a/lib/pleroma/web/ostatus/user_representer.ex +++ b/lib/pleroma/web/ostatus/user_representer.ex @@ -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 diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index 1dd381ac4..bb995199c 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -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 diff --git a/test/web/ostatus/user_representer_test.exs b/test/web/ostatus/user_representer_test.exs index b22420379..e41dfeb3d 100644 --- a/test/web/ostatus/user_representer_test.exs +++ b/test/web/ostatus/user_representer_test.exs @@ -22,6 +22,7 @@ defmodule Pleroma.Web.OStatus.UserRepresenterTest do #{user.nickname} + true """ assert clean(res) == clean(expected)