Update note count in ActivityPub.create.

This commit is contained in:
eal 2018-04-21 12:58:04 +03:00
parent d0b1c498a0
commit 22bfeac256
3 changed files with 15 additions and 16 deletions

View file

@ -61,7 +61,8 @@ def create(%{to: to, actor: actor, context: context, object: object} = params) d
additional additional
), ),
{:ok, activity} <- insert(create_data, local), {: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} {:ok, activity}
end end
end end

View file

@ -138,7 +138,6 @@ def handle_note(entry, doc \\ nil) do
do: note |> Map.put("inReplyTo", inReplyTo), do: note |> Map.put("inReplyTo", inReplyTo),
else: note else: note
) do ) do
res =
ActivityPub.create(%{ ActivityPub.create(%{
to: to, to: to,
actor: actor, actor: actor,
@ -148,9 +147,6 @@ def handle_note(entry, doc \\ nil) do
local: false, local: false,
additional: %{"cc" => cc} additional: %{"cc" => cc}
}) })
User.increase_note_count(actor)
res
else else
%Activity{} = activity -> {:ok, activity} %Activity{} = activity -> {:ok, activity}
e -> {:error, e} e -> {:error, e}

View file

@ -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 describe "create activities" do
test "removes doubled 'to' recipients" do test "removes doubled 'to' recipients" do
user = insert(:user)
{:ok, activity} = {:ok, activity} =
ActivityPub.create(%{ ActivityPub.create(%{
to: ["user1", "user1", "user2"], to: ["user1", "user1", "user2"],
actor: %User{ap_id: "1"}, actor: user,
context: "", context: "",
object: %{} object: %{}
}) })
assert activity.data["to"] == ["user1", "user2"] assert activity.data["to"] == ["user1", "user2"]
assert activity.actor == "1" assert activity.actor == user.ap_id
assert activity.recipients == ["user1", "user2"] assert activity.recipients == ["user1", "user2"]
end end
end end