Add notification checks
This commit is contained in:
parent
79910ce5cc
commit
007762e767
@ -148,6 +148,7 @@ defmodule Pleroma.Notification do
|
||||
[]
|
||||
|> Utils.maybe_notify_to_recipients(activity)
|
||||
|> Utils.maybe_notify_mentioned_recipients(activity)
|
||||
|> Utils.maybe_notify_subscribers(activity)
|
||||
|> Enum.uniq()
|
||||
|
||||
User.get_users_from_set(recipients, local_only)
|
||||
|
@ -935,10 +935,10 @@ defmodule Pleroma.User do
|
||||
|
||||
def unsubscribe(unsubscriber, %{ap_id: ap_id}) do
|
||||
info_cng =
|
||||
subscriber.info
|
||||
unsubscriber.info
|
||||
|> User.Info.remove_from_subscriptions(ap_id)
|
||||
|
||||
change(subscriber)
|
||||
change(unsubscriber)
|
||||
|> put_embed(:info, info_cng)
|
||||
|> update_and_set_cache()
|
||||
end
|
||||
@ -1005,6 +1005,9 @@ defmodule Pleroma.User do
|
||||
def blocked_users(user),
|
||||
do: Repo.all(from(u in User, where: u.ap_id in ^user.info.blocks))
|
||||
|
||||
def subscribed_users(user),
|
||||
do: Repo.all(from(u in User, where: u.ap_id in ^user.info.subscriptions))
|
||||
|
||||
def block_domain(user, domain) do
|
||||
info_cng =
|
||||
user.info
|
||||
|
@ -22,7 +22,7 @@ defmodule Pleroma.User.Info do
|
||||
field(:domain_blocks, {:array, :string}, default: [])
|
||||
field(:mutes, {:array, :string}, default: [])
|
||||
field(:muted_reblogs, {:array, :string}, default: [])
|
||||
field(:subscribed_to, {:array, :string}, default: [])
|
||||
field(:subscriptions, {:array, :string}, default: [])
|
||||
field(:deactivated, :boolean, default: false)
|
||||
field(:no_rich_text, :boolean, default: false)
|
||||
field(:ap_enabled, :boolean, default: false)
|
||||
@ -98,8 +98,8 @@ defmodule Pleroma.User.Info do
|
||||
params = %{subscriptions: subscriptions}
|
||||
|
||||
info
|
||||
|> cast(params, [:subscribed_to])
|
||||
|> validate_required([:subscribed_to])
|
||||
|> cast(params, [:subscriptions])
|
||||
|> validate_required([:subscriptions])
|
||||
end
|
||||
|
||||
def add_to_mutes(info, muted) do
|
||||
@ -119,11 +119,11 @@ defmodule Pleroma.User.Info do
|
||||
end
|
||||
|
||||
def add_to_subscriptions(info, subscribed) do
|
||||
set_subscriptions(info, Enum.uniq([subscribed | info.subscribed_to]))
|
||||
set_subscriptions(info, Enum.uniq([subscribed | info.subscriptions]))
|
||||
end
|
||||
|
||||
def remove_from_subscriptions(info, subscribed) do
|
||||
set_subscriptions(info, List.delete(info.subscribed_to, subscribed))
|
||||
set_subscriptions(info, List.delete(info.subscriptions, subscribed))
|
||||
end
|
||||
|
||||
def set_domain_blocks(info, domain_blocks) do
|
||||
|
@ -335,6 +335,22 @@ 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}}
|
||||
) when type == "Create" do
|
||||
with %User{} = user <- User.get_by_ap_id(actor) do
|
||||
subscriber_ids =
|
||||
user
|
||||
|> User.subscribed_users()
|
||||
|> 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)
|
||||
|
@ -62,6 +62,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
||||
def subscribe(%User{} = subscriber, params) do
|
||||
with {:ok, %User{} = subscribed} <- get_user(params) do
|
||||
User.subscribe(subscriber, subscribed)
|
||||
|> IO.inspect
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user