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
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
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)
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
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
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)