mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-10 11:19:19 +00:00
Add User.decrease_note_count and call it from ActivityPub.delete
This commit is contained in:
parent
62a2287bba
commit
9972678a68
3 changed files with 31 additions and 1 deletions
|
@ -322,6 +322,16 @@ defmodule Pleroma.User do
|
||||||
update_and_set_cache(cs)
|
update_and_set_cache(cs)
|
||||||
end
|
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
|
def update_note_count(%User{} = user) do
|
||||||
note_count_query =
|
note_count_query =
|
||||||
from(
|
from(
|
||||||
|
|
|
@ -172,7 +172,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
with Repo.delete(object),
|
with Repo.delete(object),
|
||||||
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
|
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
|
||||||
{:ok, activity} <- insert(data, local),
|
{:ok, activity} <- insert(data, local),
|
||||||
:ok <- maybe_federate(activity) do
|
:ok <- maybe_federate(activity),
|
||||||
|
{:ok, actor} <- User.decrease_note_count(user) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -296,6 +296,25 @@ defmodule Pleroma.UserTest do
|
||||||
assert user.info["note_count"] == 2
|
assert user.info["note_count"] == 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it decreases the info->note_count property" do
|
||||||
|
note = insert(:note)
|
||||||
|
user = User.get_by_ap_id(note.data["actor"])
|
||||||
|
|
||||||
|
assert user.info["note_count"] == nil
|
||||||
|
|
||||||
|
{:ok, user} = User.increase_note_count(user)
|
||||||
|
|
||||||
|
assert user.info["note_count"] == 1
|
||||||
|
|
||||||
|
{:ok, user} = User.decrease_note_count(user)
|
||||||
|
|
||||||
|
assert user.info["note_count"] == 0
|
||||||
|
|
||||||
|
{:ok, user} = User.decrease_note_count(user)
|
||||||
|
|
||||||
|
assert user.info["note_count"] == 0
|
||||||
|
end
|
||||||
|
|
||||||
test "it sets the info->follower_count property" do
|
test "it sets the info->follower_count property" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
follower = insert(:user)
|
follower = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue