1 defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
6 alias Pleroma.Notification
7 alias Pleroma.Pagination
8 alias Pleroma.ScheduledActivity
11 def get_followers(user, params \\ %{}) do
13 |> User.get_followers_query()
14 |> Pagination.fetch_paginated(params)
17 def get_friends(user, params \\ %{}) do
19 |> User.get_friends_query()
20 |> Pagination.fetch_paginated(params)
23 def get_notifications(user, params \\ %{}) do
24 options = cast_params(params)
27 |> Notification.for_user_query()
28 |> restrict(:exclude_types, options)
29 |> Pagination.fetch_paginated(params)
32 def get_scheduled_activities(user, params \\ %{}) do
34 |> ScheduledActivity.for_user_query()
35 |> Pagination.fetch_paginated(params)
38 defp cast_params(params) do
40 exclude_types: {:array, :string}
43 changeset = cast({%{}, param_types}, params, Map.keys(param_types))
47 defp restrict(query, :exclude_types, %{exclude_types: mastodon_types = [_ | _]}) do
50 |> Enum.map(&Activity.from_mastodon_notification_type/1)
54 |> where([q, a], not fragment("? @> ARRAY[?->>'type']::varchar[]", ^ap_types, a.data))
57 defp restrict(query, _, _), do: query