update_and_set_cache(cng)
end
+ def subscribe(subscriber, %{ap_id: ap_id}) do
+ info_cng =
+ subscriber.info
+ |> User.Info.add_to_subscriptions(ap_id)
+
+ change(subscriber)
+ |> put_embed(:info, info_cng)
+ |> update_and_set_cache()
+ end
+
+ def unsubscribe(unsubscriber, %{ap_id: ap_id}) do
+ info_cng =
+ subscriber.info
+ |> User.Info.remove_from_subscriptions(ap_id)
+
+ change(subscriber)
+ |> put_embed(:info, info_cng)
+ |> update_and_set_cache()
+ end
+
def block(blocker, %User{ap_id: ap_id} = blocked) do
# sever any follow relationships to prevent leaks per activitypub (Pleroma issue #213)
blocker =
field(:domain_blocks, {:array, :string}, default: [])
field(:mutes, {:array, :string}, default: [])
field(:muted_reblogs, {:array, :string}, default: [])
+ field(:subscribed_to, {:array, :string}, default: [])
field(:deactivated, :boolean, default: false)
field(:no_rich_text, :boolean, default: false)
field(:ap_enabled, :boolean, default: false)
|> validate_required([:blocks])
end
+ def set_subscriptions(info, subscriptions) do
+ params = %{subscriptions: subscriptions}
+
+ info
+ |> cast(params, [:subscribed_to])
+ |> validate_required([:subscribed_to])
+ end
+
def add_to_mutes(info, muted) do
set_mutes(info, Enum.uniq([muted | info.mutes]))
end
set_blocks(info, List.delete(info.blocks, blocked))
end
+ def add_to_subscriptions(info, subscribed) do
+ set_subscriptions(info, Enum.uniq([subscribed | info.subscribed_to]))
+ end
+
+ def remove_from_subscriptions(info, subscribed) do
+ set_subscriptions(info, List.delete(info.subscribed_to, subscribed))
+ end
+
def set_domain_blocks(info, domain_blocks) do
params = %{domain_blocks: domain_blocks}
post("/blocks/create", TwitterAPI.Controller, :block)
post("/blocks/destroy", TwitterAPI.Controller, :unblock)
+
+ post("/subscriptions/create", TwitterAPI.Controller, :subscribe)
+ post("/subscriptions/destroy", TwitterAPI.Controller, :unsubscribe)
end
end
end
end
+ def subscribe(%User{} = subscriber, params) do
+ with {:ok, %User{} = subscribed} <- get_user(params) do
+ User.subscribe(subscriber, subscribed)
+ end
+ end
+
+ def unsubscribe(%User{} = unsubscriber, params) do
+ with {:ok, %User{} = unsubscribed} <- get_user(params) do
+ User.unsubscribe(unsubscriber, unsubscribed)
+ end
+ end
+
def repeat(%User{} = user, ap_id_or_id) do
with {:ok, _announce, %{data: %{"id" => id}}} <- CommonAPI.repeat(ap_id_or_id, user),
%Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do
end
end
+ def subscribe(%{assigns: %{user: user}} = conn, params) do
+ case TwitterAPI.subscribe(user, params) do
+ {:ok, user, subscribed} ->
+ conn
+ |> put_view(UserView)
+ |> render("show.json", %{user: subscribed, for: user})
+
+ {:error, msg} ->
+ forbidden_json_reply(conn, msg)
+ end
+ end
+
+ def unsubscribe(%{assigns: %{user: user}} = conn, params) do
+ case TwitterAPI.unsubscribe(user, params) do
+ {:ok, user, unsubscribed} ->
+ conn
+ |> put_view(UserView)
+ |> render("show.json", %{user: unsubscribed, for: user})
+
+ {:error, msg} ->
+ forbidden_json_reply(conn, msg)
+ end
+ end
+
def fetch_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
with %Activity{} = activity <- Activity.get_by_id(id),
true <- Visibility.visible_for_user?(activity, user) do