aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/object.ex
diff options
context:
space:
mode:
authorIvan Tashkinov <ivant.business@gmail.com>2019-04-01 08:49:32 +0300
committerIvan Tashkinov <ivant.business@gmail.com>2019-04-01 08:49:32 +0300
commitbaffdcc480cea13269ef0e3af58f0a848892bb9a (patch)
treea9499083c412b24173fa14717cec7041c6f3f45c /lib/pleroma/object.ex
parent642075b1a935c42181a10ea695b2289883126136 (diff)
parentdc39d8d3fb941bad9fe26586c321bb00a0b92fe4 (diff)
downloadpleroma-baffdcc480cea13269ef0e3af58f0a848892bb9a.tar.gz
[#923] Merge remote-tracking branch 'remotes/upstream/develop' into twitter_oauth
# Conflicts: # mix.exs
Diffstat (limited to 'lib/pleroma/object.ex')
-rw-r--r--lib/pleroma/object.ex46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex
index 193ae3fa8..8a670645d 100644
--- a/lib/pleroma/object.ex
+++ b/lib/pleroma/object.ex
@@ -133,4 +133,50 @@ defmodule Pleroma.Object do
e -> e
end
end
+
+ def increase_replies_count(ap_id) do
+ Object
+ |> where([o], fragment("?->>'id' = ?::text", o.data, ^to_string(ap_id)))
+ |> update([o],
+ set: [
+ data:
+ fragment(
+ """
+ jsonb_set(?, '{repliesCount}',
+ (coalesce((?->>'repliesCount')::int, 0) + 1)::varchar::jsonb, true)
+ """,
+ o.data,
+ o.data
+ )
+ ]
+ )
+ |> Repo.update_all([])
+ |> case do
+ {1, [object]} -> set_cache(object)
+ _ -> {:error, "Not found"}
+ end
+ end
+
+ def decrease_replies_count(ap_id) do
+ Object
+ |> where([o], fragment("?->>'id' = ?::text", o.data, ^to_string(ap_id)))
+ |> update([o],
+ set: [
+ data:
+ fragment(
+ """
+ jsonb_set(?, '{repliesCount}',
+ (greatest(0, (?->>'repliesCount')::int - 1))::varchar::jsonb, true)
+ """,
+ o.data,
+ o.data
+ )
+ ]
+ )
+ |> Repo.update_all([])
+ |> case do
+ {1, [object]} -> set_cache(object)
+ _ -> {:error, "Not found"}
+ end
+ end
end