Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Activity.Ir.Topics do
  5. alias Pleroma.Object
  6. alias Pleroma.Web.ActivityPub.Visibility
  7. def get_activity_topics(activity) do
  8. activity
  9. |> Object.normalize(fetch: false)
  10. |> generate_topics(activity)
  11. |> List.flatten()
  12. end
  13. defp generate_topics(%{data: %{"type" => "Answer"}}, _) do
  14. []
  15. end
  16. defp generate_topics(object, activity) do
  17. ["user", "list"] ++ visibility_tags(object, activity)
  18. end
  19. defp visibility_tags(object, activity) do
  20. case Visibility.get_visibility(activity) do
  21. "public" ->
  22. if activity.local do
  23. ["public", "public:local"]
  24. else
  25. ["public"]
  26. end
  27. |> item_creation_tags(object, activity)
  28. "direct" ->
  29. ["direct"]
  30. _ ->
  31. []
  32. end
  33. end
  34. defp item_creation_tags(tags, object, %{data: %{"type" => "Create"}} = activity) do
  35. tags ++
  36. remote_topics(activity) ++ hashtags_to_topics(object) ++ attachment_topics(object, activity)
  37. end
  38. defp item_creation_tags(tags, _, _) do
  39. tags
  40. end
  41. defp hashtags_to_topics(object) do
  42. object
  43. |> Object.hashtags()
  44. |> Enum.map(fn hashtag -> "hashtag:" <> hashtag end)
  45. end
  46. defp remote_topics(%{local: true}), do: []
  47. defp remote_topics(%{actor: actor}) when is_binary(actor),
  48. do: ["public:remote:" <> URI.parse(actor).host]
  49. defp remote_topics(_), do: []
  50. defp attachment_topics(%{data: %{"attachment" => []}}, _act), do: []
  51. defp attachment_topics(_object, %{local: true}), do: ["public:media", "public:local:media"]
  52. defp attachment_topics(_object, %{actor: actor}) when is_binary(actor),
  53. do: ["public:media", "public:remote:media:" <> URI.parse(actor).host]
  54. defp attachment_topics(_object, _act), do: ["public:media"]
  55. end