Add Follow activity insertion
This commit is contained in:
parent
a83fa053de
commit
8075badafe
|
@ -6,7 +6,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
def insert(map) when is_map(map) do
|
def insert(map) when is_map(map) do
|
||||||
map = Map.put_new_lazy(map, "id", &generate_activity_id/0)
|
map = Map.put_new_lazy(map, "id", &generate_activity_id/0)
|
||||||
|
|
||||||
map = if map["object"] do
|
map = if is_map(map["object"]) do
|
||||||
object = Map.put_new_lazy(map["object"], "id", &generate_object_id/0)
|
object = Map.put_new_lazy(map["object"], "id", &generate_object_id/0)
|
||||||
Repo.insert!(%Object{data: object})
|
Repo.insert!(%Object{data: object})
|
||||||
Map.put(map, "object", object)
|
Map.put(map, "object", object)
|
||||||
|
|
|
@ -103,9 +103,14 @@ def fetch_status(user, id) do
|
||||||
|
|
||||||
def follow(%User{} = follower, followed_id) do
|
def follow(%User{} = follower, followed_id) do
|
||||||
with %User{} = followed <- Repo.get(User, followed_id),
|
with %User{} = followed <- Repo.get(User, followed_id),
|
||||||
{ :ok, follower } <- User.follow(follower, followed)
|
{ :ok, follower } <- User.follow(follower, followed),
|
||||||
|
{ :ok, activity } <- ActivityPub.insert(%{
|
||||||
|
"type" => "Follow",
|
||||||
|
"actor" => follower.ap_id,
|
||||||
|
"object" => followed.ap_id
|
||||||
|
})
|
||||||
do
|
do
|
||||||
{ :ok, follower, followed }
|
{ :ok, follower, followed, activity }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ def friends_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
|
def follow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
|
||||||
{ :ok, _user, follower } = TwitterAPI.follow(user, followed_id)
|
{ :ok, _user, follower, _activity } = TwitterAPI.follow(user, followed_id)
|
||||||
|
|
||||||
response = follower |> UserRepresenter.to_json(%{for: user})
|
response = follower |> UserRepresenter.to_json(%{for: user})
|
||||||
|
|
||||||
|
|
|
@ -107,11 +107,13 @@ test "Follow another user" do
|
||||||
{ :ok, user } = UserBuilder.insert
|
{ :ok, user } = UserBuilder.insert
|
||||||
{ :ok, following } = UserBuilder.insert(%{nickname: "guy"})
|
{ :ok, following } = UserBuilder.insert(%{nickname: "guy"})
|
||||||
|
|
||||||
{:ok, user, following } = TwitterAPI.follow(user, following.id)
|
{:ok, user, following, activity } = TwitterAPI.follow(user, following.id)
|
||||||
|
|
||||||
user = Repo.get(User, user.id)
|
user = Repo.get(User, user.id)
|
||||||
|
follow = Repo.get(Activity, activity.id)
|
||||||
|
|
||||||
assert user.following == [User.ap_followers(following)]
|
assert user.following == [User.ap_followers(following)]
|
||||||
|
assert follow == activity
|
||||||
end
|
end
|
||||||
|
|
||||||
test "Unfollow another user" do
|
test "Unfollow another user" do
|
||||||
|
|
Loading…
Reference in New Issue