Exclude reblogs from `GET /api/pleroma/admin/statuses` by default
[akkoma] / lib / pleroma / activity / ir / topics.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Activity.Ir.Topics do
6 alias Pleroma.Object
7 alias Pleroma.Web.ActivityPub.Visibility
8
9 def get_activity_topics(activity) do
10 activity
11 |> Object.normalize()
12 |> generate_topics(activity)
13 |> List.flatten()
14 end
15
16 defp generate_topics(%{data: %{"type" => "Answer"}}, _) do
17 []
18 end
19
20 defp generate_topics(object, activity) do
21 ["user", "list"] ++ visibility_tags(object, activity)
22 end
23
24 defp visibility_tags(object, activity) do
25 case Visibility.get_visibility(activity) do
26 "public" ->
27 if activity.local do
28 ["public", "public:local"]
29 else
30 ["public"]
31 end
32 |> item_creation_tags(object, activity)
33
34 "direct" ->
35 ["direct"]
36
37 _ ->
38 []
39 end
40 end
41
42 defp item_creation_tags(tags, %{data: %{"type" => "Create"}} = object, activity) do
43 tags ++ hashtags_to_topics(object) ++ attachment_topics(object, activity)
44 end
45
46 defp item_creation_tags(tags, _, _) do
47 tags
48 end
49
50 defp hashtags_to_topics(%{data: %{"tag" => tags}}) do
51 tags
52 |> Enum.filter(&is_bitstring(&1))
53 |> Enum.map(fn tag -> "hashtag:" <> tag end)
54 end
55
56 defp hashtags_to_topics(_), do: []
57
58 defp attachment_topics(%{data: %{"attachment" => []}}, _act), do: []
59
60 defp attachment_topics(_object, %{local: true}), do: ["public:media", "public:local:media"]
61
62 defp attachment_topics(_object, _act), do: ["public:media"]
63 end