Update note count in ActivityPub.create.
authoreal <eal@waifu.club>
Sat, 21 Apr 2018 09:58:04 +0000 (12:58 +0300)
committereal <eal@waifu.club>
Sat, 21 Apr 2018 09:58:04 +0000 (12:58 +0300)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/ostatus/handlers/note_handler.ex
test/web/activity_pub/activity_pub_test.exs

index 04b50c1cc0fc32870dad268d569648c6e8d60263..d071135c47afa737856f1dbf36759e0a8c7eb160 100644 (file)
@@ -61,7 +61,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
              additional
            ),
          {:ok, activity} <- insert(create_data, local),
-         :ok <- maybe_federate(activity) do
+         :ok <- maybe_federate(activity),
+         {:ok, actor} <- User.increase_note_count(actor) do
       {:ok, activity}
     end
   end
index b012abd51144062b7f99eddce1dfc7f52595b74b..bd6e92238efd6ee748b676a8bdd3b58be3b65034 100644 (file)
@@ -138,19 +138,15 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
              do: note |> Map.put("inReplyTo", inReplyTo),
              else: note
            ) do
-      res =
-        ActivityPub.create(%{
-          to: to,
-          actor: actor,
-          context: context,
-          object: note,
-          published: date,
-          local: false,
-          additional: %{"cc" => cc}
-        })
-
-      User.increase_note_count(actor)
-      res
+      ActivityPub.create(%{
+        to: to,
+        actor: actor,
+        context: context,
+        object: note,
+        published: date,
+        local: false,
+        additional: %{"cc" => cc}
+      })
     else
       %Activity{} = activity -> {:ok, activity}
       e -> {:error, e}
index 657d75a554c08f3c6825f227b71e15b66830fdd2..6887e88718c33d377cdabb04e085da2f780056eb 100644 (file)
@@ -83,16 +83,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
 
   describe "create activities" do
     test "removes doubled 'to' recipients" do
+      user = insert(:user)
+
       {:ok, activity} =
         ActivityPub.create(%{
           to: ["user1", "user1", "user2"],
-          actor: %User{ap_id: "1"},
+          actor: user,
           context: "",
           object: %{}
         })
 
       assert activity.data["to"] == ["user1", "user2"]
-      assert activity.actor == "1"
+      assert activity.actor == user.ap_id
       assert activity.recipients == ["user1", "user2"]
     end
   end