diff options
author | kaniini <nenolod@gmail.com> | 2019-03-03 15:49:19 +0000 |
---|---|---|
committer | kaniini <nenolod@gmail.com> | 2019-03-03 15:49:19 +0000 |
commit | c93479c6f5c2f112dc53d19681fb9cc6df31aff0 (patch) | |
tree | 7e38a7fd944f13ee1a29955214a96adaa71ce85d /lib | |
parent | dfdbb6f125090d55de1afd755cd55f2e1f7e77bc (diff) | |
parent | 8a1e0c9bee4173a7cd2c6b6174293097d78bea19 (diff) | |
download | pleroma-c93479c6f5c2f112dc53d19681fb9cc6df31aff0.tar.gz |
Merge branch 'count-only-public-statuses' into 'develop'
Increment user note count only on public activities #703
See merge request pleroma/pleroma!884
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 7282d4239..783491b67 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -81,6 +81,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp check_remote_limit(_), do: true + def increase_note_count_if_public(actor, object) do + if is_public?(object), do: User.increase_note_count(actor), else: {:ok, actor} + end + + def decrease_note_count_if_public(actor, object) do + if is_public?(object), do: User.decrease_note_count(actor), else: {:ok, actor} + end + def insert(map, local \\ true) when is_map(map) do with nil <- Activity.normalize(map), map <- lazy_put_activity_defaults(map), @@ -163,7 +171,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do ), {:ok, activity} <- insert(create_data, local), # Changing note count prior to enqueuing federation task in order to avoid race conditions on updating user.info - {:ok, _actor} <- User.increase_note_count(actor), + {:ok, _actor} <- increase_note_count_if_public(actor, activity), :ok <- maybe_federate(activity) do {:ok, activity} end @@ -312,7 +320,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do with {:ok, _} <- Object.delete(object), {:ok, activity} <- insert(data, local), # Changing note count prior to enqueuing federation task in order to avoid race conditions on updating user.info - {:ok, _actor} <- User.decrease_note_count(user), + {:ok, _actor} <- decrease_note_count_if_public(user, object), :ok <- maybe_federate(activity) do {:ok, activity} end |