Try to fetch AP user data first.
authorlain <lain@soykaf.club>
Sun, 18 Feb 2018 11:27:05 +0000 (12:27 +0100)
committerlain <lain@soykaf.club>
Sun, 18 Feb 2018 11:27:05 +0000 (12:27 +0100)
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/web_finger/web_finger.ex

index 2ca4d406b4dc8b48d7890de084c715ebcfbd1908..f88c1240a5e0b3d8758d5ec6d70b775edee00095 100644 (file)
@@ -228,12 +228,21 @@ defmodule Pleroma.User do
     Cachex.get!(:user_cache, key, fallback: fn(_) -> user_info(user) end)
   end
 
+  def fetch_by_nickname(nickname) do
+    ap_try = ActivityPub.make_user_from_nickname(nickname)
+
+    case ap_try do
+      {:ok, user} -> {:ok, user}
+      _ -> OStatus.make_user(nickname)
+    end
+  end
+
   def get_or_fetch_by_nickname(nickname) do
     with %User{} = user <- get_by_nickname(nickname)  do
       user
     else _e ->
       with [_nick, _domain] <- String.split(nickname, "@"),
-           {:ok, user} <- OStatus.make_user(nickname) do
+           {:ok, user} <- fetch_by_nickname(nickname) do
         user
       else _e -> nil
       end
index a5e8b98e9f27c49e64fc7bd4e3d51c8618c0b75e..d171913f81e11ff440e3391af76fb6fd19ec33fd 100644 (file)
@@ -1,6 +1,7 @@
 defmodule Pleroma.Web.ActivityPub.ActivityPub do
   alias Pleroma.{Activity, Repo, Object, Upload, User, Notification}
   alias Pleroma.Web.ActivityPub.Transmogrifier
+  alias Pleroma.Web.WebFinger
   import Ecto.Query
   import Pleroma.Web.ActivityPub.Utils
   require Logger
@@ -253,6 +254,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     end
   end
 
+  def make_user_from_nickname(nickname) do
+    with {:ok, %{"ap_id" => ap_id}} when not is_nil(ap_id) <- WebFinger.finger(nickname) do
+      make_user_from_ap_id(ap_id)
+    end
+  end
+
   def publish(actor, activity) do
     {:ok, followers} = User.get_followers(actor)
 
index 09957e13316da154353433b1d8433dd40f37277a..54cbf4ceab3a4cd5921c1c4621c60a5fc215ba2d 100644 (file)
@@ -71,12 +71,14 @@ defmodule Pleroma.Web.WebFinger do
     subject = XML.string_from_xpath("//Subject", doc)
     salmon = XML.string_from_xpath(~s{//Link[@rel="salmon"]/@href}, doc)
     subscribe_address = XML.string_from_xpath(~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template}, doc)
+    ap_id = XML.string_from_xpath(~s{//Link[@rel="self" and @type="application/activity+json"]/@href}, doc)
     data = %{
       "magic_key" => magic_key,
       "topic" => topic,
       "subject" => subject,
       "salmon" => salmon,
-      "subscribe_address" => subscribe_address
+      "subscribe_address" => subscribe_address,
+      "ap_id" => ap_id
     }
     {:ok, data}
   end