projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'refactor/db-not-null-constraints-for-lists' into 'develop'
[akkoma]
/
lib
/
pleroma
/
object.ex
diff --git
a/lib/pleroma/object.ex
b/lib/pleroma/object.ex
index 3fa407931e3bd43d8fba928852232f75f2d09192..d9b41d710cebb6296a3b2d4cb41521feb2c27030 100644
(file)
--- a/
lib/pleroma/object.ex
+++ b/
lib/pleroma/object.ex
@@
-181,7
+181,7
@@
defmodule Pleroma.Object do
data:
fragment(
"""
data:
fragment(
"""
- jsonb_set(?, '{repliesCount}',
+
safe_
jsonb_set(?, '{repliesCount}',
(coalesce((?->>'repliesCount')::int, 0) + 1)::varchar::jsonb, true)
""",
o.data,
(coalesce((?->>'repliesCount')::int, 0) + 1)::varchar::jsonb, true)
""",
o.data,
@@
-204,7
+204,7
@@
defmodule Pleroma.Object do
data:
fragment(
"""
data:
fragment(
"""
- jsonb_set(?, '{repliesCount}',
+
safe_
jsonb_set(?, '{repliesCount}',
(greatest(0, (?->>'repliesCount')::int - 1))::varchar::jsonb, true)
""",
o.data,
(greatest(0, (?->>'repliesCount')::int - 1))::varchar::jsonb, true)
""",
o.data,
@@
-248,4
+248,11
@@
defmodule Pleroma.Object do
_ -> :noop
end
end
_ -> :noop
end
end
+
+ @doc "Updates data field of an object"
+ def update_data(%Object{data: data} = object, attrs \\ %{}) do
+ object
+ |> Object.change(%{data: Map.merge(data || %{}, attrs)})
+ |> Repo.update()
+ end
end
end