1 defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
6 alias Pleroma.Notification
7 alias Pleroma.Pagination
8 alias Pleroma.ScheduledActivity
10 alias Pleroma.Web.CommonAPI
12 def follow(follower, followed, params \\ %{}) do
13 options = cast_params(params)
14 reblogs = options[:reblogs]
17 if not User.following?(follower, followed) do
18 CommonAPI.follow(follower, followed)
20 {:ok, follower, followed, nil}
23 with {:ok, follower, followed, _} <- result do
26 false -> CommonAPI.hide_reblogs(follower, followed)
27 _ -> CommonAPI.show_reblogs(follower, followed)
30 {:ok, follower} -> {:ok, follower}
36 def get_followers(user, params \\ %{}) do
38 |> User.get_followers_query()
39 |> Pagination.fetch_paginated(params)
42 def get_friends(user, params \\ %{}) do
44 |> User.get_friends_query()
45 |> Pagination.fetch_paginated(params)
48 def get_notifications(user, params \\ %{}) do
49 options = cast_params(params)
52 |> Notification.for_user_query()
53 |> restrict(:exclude_types, options)
54 |> Pagination.fetch_paginated(params)
57 def get_scheduled_activities(user, params \\ %{}) do
59 |> ScheduledActivity.for_user_query()
60 |> Pagination.fetch_paginated(params)
63 defp cast_params(params) do
65 exclude_types: {:array, :string},
69 changeset = cast({%{}, param_types}, params, Map.keys(param_types))
73 defp restrict(query, :exclude_types, %{exclude_types: mastodon_types = [_ | _]}) do
76 |> Enum.map(&Activity.from_mastodon_notification_type/1)
80 |> where([q, a], not fragment("? @> ARRAY[?->>'type']::varchar[]", ^ap_types, a.data))
83 defp restrict(query, _, _), do: query