Merge branch 'account-subscriptions' into 'develop'
MastoAPI: accept notify param in follow request See merge request pleroma/pleroma!3555
This commit is contained in:
commit
b96a58ff28
@ -159,6 +159,7 @@ See [Admin-API](admin_api.md)
|
||||
"muting": false,
|
||||
"muting_notifications": false,
|
||||
"subscribing": true,
|
||||
"notifying": true,
|
||||
"requested": false,
|
||||
"domain_blocking": false,
|
||||
"showing_reblogs": true,
|
||||
@ -183,6 +184,7 @@ See [Admin-API](admin_api.md)
|
||||
"muting": false,
|
||||
"muting_notifications": false,
|
||||
"subscribing": false,
|
||||
"notifying": false,
|
||||
"requested": false,
|
||||
"domain_blocking": false,
|
||||
"showing_reblogs": true,
|
||||
|
@ -226,6 +226,12 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
||||
type: :boolean,
|
||||
description: "Receive this account's reblogs in home timeline? Defaults to true.",
|
||||
default: true
|
||||
},
|
||||
notify: %Schema{
|
||||
type: :boolean,
|
||||
description:
|
||||
"Receive notifications for all statuses posted by the account? Defaults to false.",
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -688,6 +694,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
||||
"requested" => false,
|
||||
"domain_blocking" => false,
|
||||
"subscribing" => false,
|
||||
"notifying" => false,
|
||||
"endorsed" => true
|
||||
},
|
||||
%{
|
||||
@ -702,6 +709,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
||||
"requested" => true,
|
||||
"domain_blocking" => false,
|
||||
"subscribing" => false,
|
||||
"notifying" => false,
|
||||
"endorsed" => false
|
||||
},
|
||||
%{
|
||||
@ -716,6 +724,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
||||
"requested" => false,
|
||||
"domain_blocking" => true,
|
||||
"subscribing" => true,
|
||||
"notifying" => true,
|
||||
"endorsed" => false
|
||||
}
|
||||
]
|
||||
|
@ -196,7 +196,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
|
||||
"muting_notifications" => false,
|
||||
"requested" => false,
|
||||
"showing_reblogs" => true,
|
||||
"subscribing" => false
|
||||
"subscribing" => false,
|
||||
"notifying" => false
|
||||
},
|
||||
"settings_store" => %{
|
||||
"pleroma-fe" => %{}
|
||||
|
@ -24,7 +24,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do
|
||||
muting_notifications: %Schema{type: :boolean},
|
||||
requested: %Schema{type: :boolean},
|
||||
showing_reblogs: %Schema{type: :boolean},
|
||||
subscribing: %Schema{type: :boolean}
|
||||
subscribing: %Schema{type: :boolean},
|
||||
notifying: %Schema{type: :boolean}
|
||||
},
|
||||
example: %{
|
||||
"blocked_by" => false,
|
||||
@ -38,7 +39,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do
|
||||
"muting_notifications" => false,
|
||||
"requested" => false,
|
||||
"showing_reblogs" => true,
|
||||
"subscribing" => false
|
||||
"subscribing" => false,
|
||||
"notifying" => false
|
||||
}
|
||||
})
|
||||
end
|
||||
|
@ -284,7 +284,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
|
||||
"muting_notifications" => false,
|
||||
"requested" => false,
|
||||
"showing_reblogs" => true,
|
||||
"subscribing" => false
|
||||
"subscribing" => false,
|
||||
"notifying" => false
|
||||
},
|
||||
"skip_thread_containment" => false,
|
||||
"tags" => []
|
||||
|
@ -24,6 +24,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
||||
with {:ok, follower, _followed, _} <- result do
|
||||
options = cast_params(params)
|
||||
set_reblogs_visibility(options[:reblogs], result)
|
||||
set_subscription(options[:notify], result)
|
||||
{:ok, follower}
|
||||
end
|
||||
end
|
||||
@ -36,6 +37,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
||||
CommonAPI.show_reblogs(follower, followed)
|
||||
end
|
||||
|
||||
defp set_subscription(true, {:ok, follower, followed, _}) do
|
||||
User.subscribe(follower, followed)
|
||||
end
|
||||
|
||||
defp set_subscription(false, {:ok, follower, followed, _}) do
|
||||
User.unsubscribe(follower, followed)
|
||||
end
|
||||
|
||||
defp set_subscription(_, _), do: {:ok, nil}
|
||||
|
||||
@spec get_followers(User.t(), map()) :: list(User.t())
|
||||
def get_followers(user, params \\ %{}) do
|
||||
user
|
||||
@ -73,7 +84,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
||||
exclude_visibilities: {:array, :string},
|
||||
reblogs: :boolean,
|
||||
with_muted: :boolean,
|
||||
account_ap_id: :string
|
||||
account_ap_id: :string,
|
||||
notify: :boolean
|
||||
}
|
||||
|
||||
changeset = cast({%{}, param_types}, params, Map.keys(param_types))
|
||||
|
@ -101,6 +101,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||
User.following?(target, reading_user)
|
||||
end
|
||||
|
||||
subscribing =
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
:inverse_subscription,
|
||||
target,
|
||||
reading_user,
|
||||
&User.subscribed_to?(&2, &1)
|
||||
)
|
||||
|
||||
# NOTE: adjust UserRelationship.view_relationships_option/2 on new relation-related flags
|
||||
%{
|
||||
id: to_string(target.id),
|
||||
@ -138,14 +147,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||
target,
|
||||
&User.muted_notifications?(&1, &2)
|
||||
),
|
||||
subscribing:
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
:inverse_subscription,
|
||||
target,
|
||||
reading_user,
|
||||
&User.subscribed_to?(&2, &1)
|
||||
),
|
||||
subscribing: subscribing,
|
||||
notifying: subscribing,
|
||||
requested: follow_state == :follow_pending,
|
||||
domain_blocking: User.blocks_domain?(reading_user, target),
|
||||
showing_reblogs:
|
||||
|
@ -922,6 +922,27 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "following with subscription and unsubscribing" do
|
||||
%{conn: conn} = oauth_access(["follow"])
|
||||
followed = insert(:user)
|
||||
|
||||
ret_conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/accounts/#{followed.id}/follow", %{notify: true})
|
||||
|
||||
assert %{"id" => _id, "subscribing" => true} =
|
||||
json_response_and_validate_schema(ret_conn, 200)
|
||||
|
||||
ret_conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/accounts/#{followed.id}/follow", %{notify: false})
|
||||
|
||||
assert %{"id" => _id, "subscribing" => false} =
|
||||
json_response_and_validate_schema(ret_conn, 200)
|
||||
end
|
||||
|
||||
test "following / unfollowing errors", %{user: user, conn: conn} do
|
||||
# self follow
|
||||
conn_res = post(conn, "/api/v1/accounts/#{user.id}/follow")
|
||||
|
@ -270,6 +270,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||
muting: false,
|
||||
muting_notifications: false,
|
||||
subscribing: false,
|
||||
notifying: false,
|
||||
requested: false,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: true,
|
||||
@ -295,6 +296,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||
muting: true,
|
||||
muting_notifications: true,
|
||||
subscribing: true,
|
||||
notifying: true,
|
||||
showing_reblogs: false,
|
||||
id: to_string(other_user.id)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user