aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDashie <dashie@sigpipe.me>2018-04-24 11:34:18 +0200
committerDashie <dashie@sigpipe.me>2018-04-24 11:34:18 +0200
commit9972678a68605d24373f785f783d0fe60f77afdc (patch)
tree1a1c6c93dc044bed46fcc30ba28ceb0e26d1169a /lib
parent62a2287bba87932339321dae944408781387fa2c (diff)
downloadpleroma-9972678a68605d24373f785f783d0fe60f77afdc.tar.gz
Add User.decrease_note_count and call it from ActivityPub.delete
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/user.ex10
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex3
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index c77fd6816..0bc7dcab0 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -322,6 +322,16 @@ defmodule Pleroma.User do
update_and_set_cache(cs)
end
+ def decrease_note_count(%User{} = user) do
+ note_count = (user.info["note_count"] || 0)
+ note_count = if note_count <= 0, do: 0, else: note_count - 1
+ new_info = Map.put(user.info, "note_count", note_count)
+
+ cs = info_changeset(user, %{info: new_info})
+
+ update_and_set_cache(cs)
+ end
+
def update_note_count(%User{} = user) do
note_count_query =
from(
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index d071135c4..448ea8752 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -172,7 +172,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
with Repo.delete(object),
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
{:ok, activity} <- insert(data, local),
- :ok <- maybe_federate(activity) do
+ :ok <- maybe_federate(activity),
+ {:ok, actor} <- User.decrease_note_count(user) do
{:ok, activity}
end
end