aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoger Braun <roger@rogerbraun.net>2018-02-11 17:20:02 +0100
committerlain <lain@soykaf.club>2018-02-11 17:20:43 +0100
commitae1ec858f442aba7c2b2aea12dd60585517be17a (patch)
treef25333260c4417237268937b4c44eec2a169fe47 /lib
parentc1d26751e6cd5fdfeb256e4b3ba81e1a7039894f (diff)
downloadpleroma-ae1ec858f442aba7c2b2aea12dd60585517be17a.tar.gz
Basic AP user building.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/user.ex17
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex20
-rw-r--r--lib/pleroma/web/ostatus/ostatus.ex7
3 files changed, 35 insertions, 9 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index e544d3772..47aefaeba 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -80,9 +80,15 @@ defmodule Pleroma.User do
|> validate_length(:name, max: 100)
|> put_change(:local, false)
if changes.valid? do
- followers = User.ap_followers(%User{nickname: changes.changes[:nickname]})
- changes
- |> put_change(:follower_address, followers)
+ case changes.changes[:info]["source_data"] do
+ %{"followers" => followers} ->
+ changes
+ |> put_change(:follower_address, followers)
+ _ ->
+ followers = User.ap_followers(%User{nickname: changes.changes[:nickname]})
+ changes
+ |> put_change(:follower_address, followers)
+ end
else
changes
end
@@ -386,4 +392,9 @@ defmodule Pleroma.User do
_ -> :error
end
end
+
+ def insert_or_update_user(data) do
+ cs = User.remote_user_creation(data)
+ Repo.insert(cs, on_conflict: :replace_all, conflict_target: :nickname)
+ end
end
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 7b85770b7..4d0de71e4 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -5,6 +5,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
import Pleroma.Web.ActivityPub.Utils
require Logger
+ @httpoison Application.get_env(:pleroma, :httpoison)
+
def get_recipients(data) do
(data["to"] || []) ++ (data["cc"] || [])
end
@@ -232,4 +234,22 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
def prepare_incoming(_) do
:error
end
+
+ def make_user_from_ap_id(ap_id) do
+ with {:ok, %{status_code: 200, body: body}} <- @httpoison.get(ap_id, ["Accept": "application/activity+json"]),
+ {:ok, data} <- Poison.decode(body)
+ do
+ user_data = %{
+ ap_id: data["id"],
+ info: %{
+ "ap_enabled" => true,
+ "source_data" => data
+ },
+ nickname: "#{data["preferredUsername"]}@#{URI.parse(ap_id).host}",
+ name: data["name"]
+ }
+
+ User.insert_or_update_user(user_data)
+ end
+ end
end
diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex
index c35ba42be..91c4474c5 100644
--- a/lib/pleroma/web/ostatus/ostatus.ex
+++ b/lib/pleroma/web/ostatus/ostatus.ex
@@ -218,11 +218,6 @@ defmodule Pleroma.Web.OStatus do
end
end
- def insert_or_update_user(data) do
- cs = User.remote_user_creation(data)
- Repo.insert(cs, on_conflict: :replace_all, conflict_target: :nickname)
- end
-
def make_user(uri, update \\ false) do
with {:ok, info} <- gather_user_info(uri) do
data = %{
@@ -236,7 +231,7 @@ defmodule Pleroma.Web.OStatus do
with false <- update,
%User{} = user <- User.get_by_ap_id(data.ap_id) do
{:ok, user}
- else _e -> insert_or_update_user(data)
+ else _e -> User.insert_or_update_user(data)
end
end
end