diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c596d5..a8ab3ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Add empty `spoiler_text` property to Mastodon API Status object. - Added `error` and `error_description` fields to Mastodon API error responses. - Store information about failed activity deliveries in database. +- Added `/api/v1/accounts/{account_id}/aliases` API endpoint. ### Changed diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 366fa6f..e8f013a 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -544,6 +544,23 @@ paths: $ref: '#/components/schemas/Subscription' 404: description: Profile not found + /api/v1/accounts/{account_id}/aliases: + get: + summary: Get actor's aliases. + parameters: + - $ref: '#/components/parameters/account_id' + responses: + 200: + description: Successful operation + content: + application/json: + schema: + description: Profile list + type: array + items: + $ref: '#/components/schemas/Account' + 404: + description: Profile not found /api/v1/accounts/{account_id}/follow: post: summary: Follow the given actor. diff --git a/src/mastodon_api/accounts/views.rs b/src/mastodon_api/accounts/views.rs index a288067..7d4912c 100644 --- a/src/mastodon_api/accounts/views.rs +++ b/src/mastodon_api/accounts/views.rs @@ -67,6 +67,7 @@ use crate::mastodon_api::{ }; use crate::models::{ posts::queries::get_posts_by_author, + profiles::helpers::find_aliases, profiles::queries::{ get_profile_by_acct, get_profile_by_id, @@ -797,6 +798,28 @@ async fn get_account_subscribers( Ok(HttpResponse::Ok().json(subscriptions)) } +#[get("/{account_id}/aliases")] +async fn get_account_aliases( + connection_info: ConnectionInfo, + config: web::Data, + db_pool: web::Data, + account_id: web::Path, +) -> Result { + let db_client = &**get_database_client(&db_pool).await?; + let profile = get_profile_by_id(db_client, &account_id).await?; + let aliases = find_aliases(db_client, &profile).await?; + let base_url = get_request_base_url(connection_info); + let instance_url = config.instance_url(); + let accounts: Vec = aliases.into_iter() + .map(|profile| Account::from_profile( + &base_url, + &instance_url, + profile, + )) + .collect(); + Ok(HttpResponse::Ok().json(accounts)) +} + pub fn account_api_scope() -> Scope { web::scope("/api/v1/accounts") // Routes without account ID @@ -819,4 +842,5 @@ pub fn account_api_scope() -> Scope { .service(get_account_followers) .service(get_account_following) .service(get_account_subscribers) + .service(get_account_aliases) }