1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Activity.Ir.Topics do
7 alias Pleroma.Web.ActivityPub.Visibility
9 def get_activity_topics(activity) do
12 |> generate_topics(activity)
16 defp generate_topics(%{data: %{"type" => "Answer"}}, _) do
20 defp generate_topics(object, activity) do
21 ["user", "list"] ++ visibility_tags(object, activity)
24 defp visibility_tags(object, activity) do
25 case Visibility.get_visibility(activity) do
28 ["public", "public:local"]
32 |> item_creation_tags(object, activity)
42 defp item_creation_tags(tags, %{data: %{"type" => "Create"}} = object, activity) do
43 tags ++ hashtags_to_topics(object) ++ attachment_topics(object, activity)
46 defp item_creation_tags(tags, _, _) do
50 defp hashtags_to_topics(%{data: %{"tag" => tags}}) do
52 |> Enum.filter(&is_bitstring(&1))
53 |> Enum.map(fn tag -> "hashtag:" <> tag end)
56 defp hashtags_to_topics(_), do: []
58 defp attachment_topics(%{data: %{"attachment" => []}}, _act), do: []
60 defp attachment_topics(_object, %{local: true}), do: ["public:media", "public:local:media"]
62 defp attachment_topics(_object, _act), do: ["public:media"]