Try to fetch AP user data first.
This commit is contained in:
parent
68752b2047
commit
b99eeb2bdf
3 changed files with 20 additions and 2 deletions
|
@ -228,12 +228,21 @@ def get_cached_user_info(user) do
|
||||||
Cachex.get!(:user_cache, key, fallback: fn(_) -> user_info(user) end)
|
Cachex.get!(:user_cache, key, fallback: fn(_) -> user_info(user) end)
|
||||||
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
|
def get_or_fetch_by_nickname(nickname) do
|
||||||
with %User{} = user <- get_by_nickname(nickname) do
|
with %User{} = user <- get_by_nickname(nickname) do
|
||||||
user
|
user
|
||||||
else _e ->
|
else _e ->
|
||||||
with [_nick, _domain] <- String.split(nickname, "@"),
|
with [_nick, _domain] <- String.split(nickname, "@"),
|
||||||
{:ok, user} <- OStatus.make_user(nickname) do
|
{:ok, user} <- fetch_by_nickname(nickname) do
|
||||||
user
|
user
|
||||||
else _e -> nil
|
else _e -> nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
alias Pleroma.{Activity, Repo, Object, Upload, User, Notification}
|
alias Pleroma.{Activity, Repo, Object, Upload, User, Notification}
|
||||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
|
alias Pleroma.Web.WebFinger
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
import Pleroma.Web.ActivityPub.Utils
|
import Pleroma.Web.ActivityPub.Utils
|
||||||
require Logger
|
require Logger
|
||||||
|
@ -253,6 +254,12 @@ def make_user_from_ap_id(ap_id) do
|
||||||
end
|
end
|
||||||
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
|
def publish(actor, activity) do
|
||||||
{:ok, followers} = User.get_followers(actor)
|
{:ok, followers} = User.get_followers(actor)
|
||||||
|
|
||||||
|
|
|
@ -71,12 +71,14 @@ defp webfinger_from_xml(doc) do
|
||||||
subject = XML.string_from_xpath("//Subject", doc)
|
subject = XML.string_from_xpath("//Subject", doc)
|
||||||
salmon = XML.string_from_xpath(~s{//Link[@rel="salmon"]/@href}, 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)
|
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 = %{
|
data = %{
|
||||||
"magic_key" => magic_key,
|
"magic_key" => magic_key,
|
||||||
"topic" => topic,
|
"topic" => topic,
|
||||||
"subject" => subject,
|
"subject" => subject,
|
||||||
"salmon" => salmon,
|
"salmon" => salmon,
|
||||||
"subscribe_address" => subscribe_address
|
"subscribe_address" => subscribe_address,
|
||||||
|
"ap_id" => ap_id
|
||||||
}
|
}
|
||||||
{:ok, data}
|
{:ok, data}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue