Add notification checks

This commit is contained in:
Sadposter 2019-04-05 14:20:13 +01:00 committed by Hannah Ward
parent 79910ce5cc
commit 007762e767
5 changed files with 28 additions and 7 deletions

View File

@ -148,6 +148,7 @@ def get_notified_from_activity(
[]
|> 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)

View File

@ -935,10 +935,10 @@ def subscribe(subscriber, %{ap_id: ap_id}) 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 @@ def muted_users(user),
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

View File

@ -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 @@ def set_subscriptions(info, subscriptions) 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 @@ def remove_from_block(info, blocked) 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

View File

@ -335,6 +335,22 @@ def maybe_notify_mentioned_recipients(
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)

View File

@ -62,6 +62,7 @@ def unblock(%User{} = blocker, params) do
def subscribe(%User{} = subscriber, params) do
with {:ok, %User{} = subscribed} <- get_user(params) do
User.subscribe(subscriber, subscribed)
|> IO.inspect
end
end