Merge branch 'notification-cleanup' into 'develop'
Minor cleanup and comment fixes See merge request pleroma/pleroma!4397
This commit is contained in:
commit
4fc1a62264
4 changed files with 24 additions and 27 deletions
0
changelog.d/notification-cleanup.skip
Normal file
0
changelog.d/notification-cleanup.skip
Normal file
|
|
@ -526,9 +526,7 @@ defmodule Pleroma.Notification do
|
||||||
%Activity{data: %{"type" => "Create"}} = activity,
|
%Activity{data: %{"type" => "Create"}} = activity,
|
||||||
local_only
|
local_only
|
||||||
) do
|
) do
|
||||||
notification_enabled_ap_ids =
|
notification_enabled_ap_ids = Utils.get_notified_subscribers(activity)
|
||||||
[]
|
|
||||||
|> Utils.maybe_notify_subscribers(activity)
|
|
||||||
|
|
||||||
potential_receivers =
|
potential_receivers =
|
||||||
User.get_users_from_set(notification_enabled_ap_ids, local_only: local_only)
|
User.get_users_from_set(notification_enabled_ap_ids, local_only: local_only)
|
||||||
|
|
|
||||||
|
|
@ -233,8 +233,8 @@ defmodule Pleroma.User do
|
||||||
for {_relationship_type, [{_outgoing_relation, outgoing_relation_target}, _]} <-
|
for {_relationship_type, [{_outgoing_relation, outgoing_relation_target}, _]} <-
|
||||||
@user_relationships_config do
|
@user_relationships_config do
|
||||||
# `def blocked_users_relation/2`, `def muted_users_relation/2`,
|
# `def blocked_users_relation/2`, `def muted_users_relation/2`,
|
||||||
# `def reblog_muted_users_relation/2`, `def notification_muted_users/2`,
|
# `def reblog_muted_users_relation/2`, `def notification_muted_users_relation/2`,
|
||||||
# `def subscriber_users/2`, `def endorsed_users_relation/2`
|
# `def subscriber_users_relation/2`, `def endorsed_users_relation/2`
|
||||||
def unquote(:"#{outgoing_relation_target}_relation")(user, restrict_deactivated? \\ false) do
|
def unquote(:"#{outgoing_relation_target}_relation")(user, restrict_deactivated? \\ false) do
|
||||||
target_users_query = assoc(user, unquote(outgoing_relation_target))
|
target_users_query = assoc(user, unquote(outgoing_relation_target))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -402,28 +402,6 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
|
|
||||||
def maybe_notify_mentioned_recipients(recipients, _), do: recipients
|
def maybe_notify_mentioned_recipients(recipients, _), do: recipients
|
||||||
|
|
||||||
def maybe_notify_subscribers(
|
|
||||||
recipients,
|
|
||||||
%Activity{data: %{"actor" => actor, "type" => "Create"}} = activity
|
|
||||||
) do
|
|
||||||
# Do not notify subscribers if author is making a reply
|
|
||||||
with %Object{data: object} <- Object.normalize(activity, fetch: false),
|
|
||||||
nil <- object["inReplyTo"],
|
|
||||||
%User{} = user <- User.get_cached_by_ap_id(actor) do
|
|
||||||
subscriber_ids =
|
|
||||||
user
|
|
||||||
|> User.subscriber_users()
|
|
||||||
|> Enum.filter(&Visibility.visible_for_user?(activity, &1))
|
|
||||||
|> Enum.map(& &1.ap_id)
|
|
||||||
|
|
||||||
recipients ++ subscriber_ids
|
|
||||||
else
|
|
||||||
_e -> recipients
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def maybe_notify_subscribers(recipients, _), do: recipients
|
|
||||||
|
|
||||||
def maybe_notify_followers(recipients, %Activity{data: %{"type" => "Move"}} = activity) do
|
def maybe_notify_followers(recipients, %Activity{data: %{"type" => "Move"}} = activity) do
|
||||||
with %User{} = user <- User.get_cached_by_ap_id(activity.actor) do
|
with %User{} = user <- User.get_cached_by_ap_id(activity.actor) do
|
||||||
user
|
user
|
||||||
|
|
@ -437,6 +415,27 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
|
|
||||||
def maybe_notify_followers(recipients, _), do: recipients
|
def maybe_notify_followers(recipients, _), do: recipients
|
||||||
|
|
||||||
|
def get_notified_subscribers(
|
||||||
|
%Activity{data: %{"actor" => actor, "type" => "Create"}} = activity
|
||||||
|
) do
|
||||||
|
# Do not notify subscribers if author is making a reply
|
||||||
|
with %Object{data: object} <- Object.normalize(activity, fetch: false),
|
||||||
|
nil <- object["inReplyTo"],
|
||||||
|
%User{} = user <- User.get_cached_by_ap_id(actor) do
|
||||||
|
subscriber_ids =
|
||||||
|
user
|
||||||
|
|> User.subscriber_users()
|
||||||
|
|> Enum.filter(&Visibility.visible_for_user?(activity, &1))
|
||||||
|
|> Enum.map(& &1.ap_id)
|
||||||
|
|
||||||
|
subscriber_ids
|
||||||
|
else
|
||||||
|
_e -> []
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_notified_subscribers(_), do: []
|
||||||
|
|
||||||
def maybe_extract_mentions(%{"tag" => tag}) do
|
def maybe_extract_mentions(%{"tag" => tag}) do
|
||||||
tag
|
tag
|
||||||
|> Enum.filter(fn x -> is_map(x) && x["type"] == "Mention" end)
|
|> Enum.filter(fn x -> is_map(x) && x["type"] == "Mention" end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue