aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordtluna <dtluna@openmailbox.org>2017-04-04 03:30:07 +0300
committerdtluna <dtluna@openmailbox.org>2017-04-04 03:30:07 +0300
commit8075badafe60d396c236d8d6d911cbb60ae9c5b6 (patch)
tree3433b5002fab6e8463b60d72e1f7b1b08c78a0ce
parenta83fa053de4c95cab0b54f3b5fc9ee3622fca63b (diff)
downloadpleroma-8075badafe60d396c236d8d6d911cbb60ae9c5b6.tar.gz
Add Follow activity insertion
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex2
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api.ex9
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api_controller.ex2
-rw-r--r--test/web/twitter_api/twitter_api_test.exs4
4 files changed, 12 insertions, 5 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index b01def693..ec9c5e970 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -6,7 +6,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
def insert(map) when is_map(map) do
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)
Repo.insert!(%Object{data: object})
Map.put(map, "object", object)
diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex
index 2aaa73b78..e1b6f2487 100644
--- a/lib/pleroma/web/twitter_api/twitter_api.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api.ex
@@ -103,9 +103,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
def follow(%User{} = follower, followed_id) do
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
- { :ok, follower, followed }
+ { :ok, follower, followed, activity }
end
end
diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
index 2154f34f7..a13a205fc 100644
--- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
@@ -44,7 +44,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
end
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})
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 99b6a6cb2..ad932131a 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -107,11 +107,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{ :ok, user } = UserBuilder.insert
{ :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)
+ follow = Repo.get(Activity, activity.id)
assert user.following == [User.ap_followers(following)]
+ assert follow == activity
end
test "Unfollow another user" do