From 22bfeac25612776fa7815573f175d6bf6b5537bd Mon Sep 17 00:00:00 2001 From: eal Date: Sat, 21 Apr 2018 12:58:04 +0300 Subject: [PATCH] Update note count in ActivityPub.create. --- lib/pleroma/web/activity_pub/activity_pub.ex | 3 ++- .../web/ostatus/handlers/note_handler.ex | 22 ++++++++----------- test/web/activity_pub/activity_pub_test.exs | 6 +++-- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 04b50c1cc..d071135c4 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -61,7 +61,8 @@ def create(%{to: to, actor: actor, context: context, object: object} = params) d 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 diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex index b012abd51..bd6e92238 100644 --- a/lib/pleroma/web/ostatus/handlers/note_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex @@ -138,19 +138,15 @@ def handle_note(entry, doc \\ nil) 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} diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 657d75a55..6887e8871 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -83,16 +83,18 @@ test "adds an id to a given object if it lacks one and is a note and inserts it 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