aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/common_api/utils.ex
diff options
context:
space:
mode:
authorlambda <lain@soykaf.club>2019-04-10 10:04:20 +0000
committerlambda <lain@soykaf.club>2019-04-10 10:04:20 +0000
commit6504b43f96860d1911ed9a17d1c487a6e8ac93ba (patch)
tree8414fc2108941ccadd9b9fd4dd37c9d3cf731399 /lib/pleroma/web/common_api/utils.ex
parentc8440b5e0c97c5d5c03e4b99e30a61df6ab95319 (diff)
parentbe8350baa2f8c9cf9be3f53ee4a0041dada1386f (diff)
downloadpleroma-6504b43f96860d1911ed9a17d1c487a6e8ac93ba.tar.gz
Merge branch 'feature/user-status-subscriptions' into 'develop'
Add ability to subscribe to users See merge request pleroma/pleroma!1024
Diffstat (limited to 'lib/pleroma/web/common_api/utils.ex')
-rw-r--r--lib/pleroma/web/common_api/utils.ex19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 051db6c79..7b9f0ea06 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -12,6 +12,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.Endpoint
alias Pleroma.Web.MediaProxy
@@ -335,6 +336,24 @@ defmodule Pleroma.Web.CommonAPI.Utils do
def maybe_notify_mentioned_recipients(recipients, _), do: recipients
+ def maybe_notify_subscribers(
+ recipients,
+ %Activity{data: %{"actor" => actor, "type" => type}} = activity
+ )
+ when type == "Create" do
+ with %User{} = user <- User.get_cached_by_ap_id(actor) do
+ subscriber_ids =
+ user
+ |> User.subscribers()
+ |> Enum.filter(&Visibility.visible_for_user?(activity, &1))
+ |> Enum.map(& &1.ap_id)
+
+ recipients ++ subscriber_ids
+ end
+ end
+
+ def maybe_notify_subscribers(recipients, _), do: recipients
+
def maybe_extract_mentions(%{"tag" => tag}) do
tag
|> Enum.filter(fn x -> is_map(x) end)