Change relationship direction of subscriptions
This commit is contained in:
parent
d35f6551c1
commit
9ca91cbb87
12 changed files with 84 additions and 94 deletions
|
|
@ -343,7 +343,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
with %User{} = user <- User.get_by_ap_id(actor) do
|
||||
subscriber_ids =
|
||||
user
|
||||
|> User.subscribed_users()
|
||||
|> User.subscribers()
|
||||
|> Enum.map(& &1.ap_id)
|
||||
|
||||
recipients ++ subscriber_ids
|
||||
|
|
|
|||
|
|
@ -863,6 +863,26 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||
json(conn, %{})
|
||||
end
|
||||
|
||||
def subscribe(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||
with %User{} = subscription_target <- User.get_by_id(id) do
|
||||
{:ok, subscription_target} = User.subscribe(user, subscription_target)
|
||||
|
||||
conn
|
||||
|> put_view(AccountView)
|
||||
|> render("relationship.json", %{user: user, target: subscription_target})
|
||||
end
|
||||
end
|
||||
|
||||
def unsubscribe(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||
with %User{} = subscription_target <- User.get_by_id(id) do
|
||||
{:ok, subscription_target} = User.unsubscribe(user, subscription_target)
|
||||
|
||||
conn
|
||||
|> put_view(AccountView)
|
||||
|> render("relationship.json", %{user: user, target: subscription_target})
|
||||
end
|
||||
end
|
||||
|
||||
def status_search(user, query) do
|
||||
fetched =
|
||||
if Regex.match?(~r/https?:/, query) do
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
blocking: User.blocks?(user, target),
|
||||
muting: User.mutes?(user, target),
|
||||
muting_notifications: false,
|
||||
subscribing: User.subscribed_to?(user, target),
|
||||
requested: requested,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: User.showing_reblogs?(user, target),
|
||||
|
|
|
|||
|
|
@ -311,6 +311,9 @@ defmodule Pleroma.Web.Router do
|
|||
|
||||
post("/domain_blocks", MastodonAPIController, :block_domain)
|
||||
delete("/domain_blocks", MastodonAPIController, :unblock_domain)
|
||||
|
||||
post("/pleroma/accounts/:id/subscribe", MastodonAPIController, :subscribe)
|
||||
post("/pleroma/accounts/:id/unsubscribe", MastodonAPIController, :unsubscribe)
|
||||
end
|
||||
|
||||
scope [] do
|
||||
|
|
@ -495,9 +498,6 @@ defmodule Pleroma.Web.Router do
|
|||
post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
|
||||
post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
|
||||
|
||||
post("/pleroma/subscriptions/create", TwitterAPI.Controller, :subscribe)
|
||||
post("/pleroma/subscriptions/destroy", TwitterAPI.Controller, :unsubscribe)
|
||||
|
||||
post("/friendships/create", TwitterAPI.Controller, :follow)
|
||||
post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
|
||||
|
||||
|
|
|
|||
|
|
@ -59,20 +59,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
|||
end
|
||||
end
|
||||
|
||||
def subscribe(%User{} = subscriber, params) do
|
||||
with {:ok, %User{} = subscribed} <- get_user(params),
|
||||
{:ok, subscriber} <- User.subscribe(subscriber, subscribed) do
|
||||
{:ok, subscriber, subscribed}
|
||||
end
|
||||
end
|
||||
|
||||
def unsubscribe(%User{} = unsubscriber, params) do
|
||||
with {:ok, %User{} = unsubscribed} <- get_user(params),
|
||||
{:ok, unsubscriber} <- User.unsubscribe(unsubscriber, unsubscribed) do
|
||||
{:ok, 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
|
||||
|
|
|
|||
|
|
@ -269,30 +269,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller 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
|
||||
|
|
|
|||
|
|
@ -47,16 +47,15 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
|
|||
for_user = assigns[:for]
|
||||
image = User.avatar_url(user) |> MediaProxy.url()
|
||||
|
||||
{following, follows_you, statusnet_blocking, subscribed} =
|
||||
{following, follows_you, statusnet_blocking} =
|
||||
if for_user do
|
||||
{
|
||||
User.following?(for_user, user),
|
||||
User.following?(user, for_user),
|
||||
User.blocks?(for_user, user),
|
||||
User.subscribed_to?(for_user, user)
|
||||
User.blocks?(for_user, user)
|
||||
}
|
||||
else
|
||||
{false, false, false, false}
|
||||
{false, false, false}
|
||||
end
|
||||
|
||||
user_info = User.get_cached_user_info(user)
|
||||
|
|
@ -117,8 +116,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
|
|||
"pleroma" =>
|
||||
%{
|
||||
"confirmation_pending" => user_info.confirmation_pending,
|
||||
"tags" => user.tags,
|
||||
"subscribed" => subscribed
|
||||
"tags" => user.tags
|
||||
}
|
||||
|> maybe_with_activation_status(user, for_user)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue