diff options
author | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-02-09 10:17:21 +0300 |
---|---|---|
committer | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-02-09 10:17:21 +0300 |
commit | 7c3991f59eccc47551257dfe41817e71d0eb6717 (patch) | |
tree | 1f3b2b88a46100e850469ec4ebb66c982b16c1df /lib/pleroma/object.ex | |
parent | 4e6bbdc7b549e630141cb10d383a42055f06dc16 (diff) | |
download | pleroma-7c3991f59eccc47551257dfe41817e71d0eb6717.tar.gz |
[#1505] Fixed `replies` serialization (included objects' ids instead of activities' ids).
Diffstat (limited to 'lib/pleroma/object.ex')
-rw-r--r-- | lib/pleroma/object.ex | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 52556bf31..f316f8b36 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -301,4 +301,26 @@ defmodule Pleroma.Object do def local?(%Object{data: %{"id" => id}}) do String.starts_with?(id, Pleroma.Web.base_url() <> "/") end + + def replies(object, opts \\ []) do + object = Object.normalize(object) + + query = + Object + |> where( + [o], + fragment("(?)->>'inReplyTo' = ?", o.data, ^object.data["id"]) + ) + |> order_by([o], asc: o.id) + + if opts[:self_only] do + actor = object.data["actor"] + where(query, [o], fragment("(?)->>'actor' = ?", o.data, ^actor)) + else + query + end + end + + def self_replies(object, opts \\ []), + do: replies(object, Keyword.put(opts, :self_only, true)) end |