Add public timeline TwAPI.
[akkoma] / lib / pleroma / web / activity_pub / activity_pub.ex
1 defmodule Pleroma.Web.ActivityPub.ActivityPub do
2 alias Pleroma.Repo
3 alias Pleroma.Activity
4 import Ecto.Query
5
6 def insert(map) when is_map(map) do
7 Repo.insert(%Activity{data: map})
8 end
9
10 def fetch_public_activities(opts \\ %{}) do
11 since_id = opts["since_id"] || 0
12
13 query = from activity in Activity,
14 where: fragment(~s(? @> '{"to": ["https://www.w3.org/ns/activitystreams#Public"]}'), activity.data),
15 where: activity.id > ^since_id,
16 limit: 20,
17 order_by: [desc: :inserted_at]
18
19 Repo.all(query)
20 |> Enum.reverse
21 end
22 end