Add Follow activity insertion
authordtluna <dtluna@openmailbox.org>
Tue, 4 Apr 2017 00:30:07 +0000 (03:30 +0300)
committerdtluna <dtluna@openmailbox.org>
Tue, 4 Apr 2017 00:30:07 +0000 (03:30 +0300)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/twitter_api/twitter_api.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex
test/web/twitter_api/twitter_api_test.exs

index b01def6939937e59d6ff96747e2943f4631bb3fe..ec9c5e97027bbc81fe01d9bdd33e6be34eccf0ee 100644 (file)
@@ -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)
index 2aaa73b78ff4fde7249cbc332d39606082d8def6..e1b6f248713c5fadbaeff35200d48d2f65dd4e6c 100644 (file)
@@ -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
 
index 2154f34f7de828aa55c2b385ef1f6fd6f1e1fc28..a13a205fcc879fe72e517b636b3aeb1f86c7b5c2 100644 (file)
@@ -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})
 
index 99b6a6cb2eecf9f7d2661c45c138b766d495b23d..ad932131ac2522ccf153d158368f0562ba7b4aaa 100644 (file)
@@ -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