From a81d0ef216193ea4927aebc111a18ff20e37d038 Mon Sep 17 00:00:00 2001 From: silverpill Date: Wed, 2 Feb 2022 21:31:40 +0000 Subject: [PATCH] Remove get_relationships function and use get_relationship instead --- docs/openapi.yaml | 23 +++++++++++++++++++- src/mastodon_api/accounts/views.rs | 9 ++++---- src/models/relationships/queries.rs | 33 ----------------------------- 3 files changed, 26 insertions(+), 39 deletions(-) diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 7155c4c..76e23e9 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -87,6 +87,27 @@ paths: $ref: '#/components/schemas/Account' 400: description: Invalid user data + /api/v1/accounts/relationships: + get: + summary: Find out whether a given actor is followed, blocked, muted, etc. + parameters: + - name: 'id[]' + in: query + description: Actor IDs to check + required: true + schema: + type: string + format: uuid + responses: + 200: + description: Successful operation + content: + application/json: + schema: + description: Relationship list + type: array + items: + $ref: '#/components/schemas/Relationship' /api/v1/accounts/{account_id}/statuses: get: summary: Posts created by the given actor. @@ -601,7 +622,7 @@ components: type: object properties: id: - description: The account id. + description: Target profile id. type: string format: uuid following: diff --git a/src/mastodon_api/accounts/views.rs b/src/mastodon_api/accounts/views.rs index 58d6601..f1a1c42 100644 --- a/src/mastodon_api/accounts/views.rs +++ b/src/mastodon_api/accounts/views.rs @@ -33,7 +33,6 @@ use crate::models::relationships::queries::{ get_followers, get_following, get_relationship, - get_relationships, unfollow, }; use crate::models::users::queries::{ @@ -185,12 +184,12 @@ async fn get_relationships_view( ) -> Result { let db_client = &**get_database_client(&db_pool).await?; let current_user = get_current_user(db_client, auth.token()).await?; - let relationships = get_relationships( + let relationship = get_relationship( db_client, - current_user.id, - vec![query_params.into_inner().id], + ¤t_user.id, + &query_params.id, ).await?; - Ok(HttpResponse::Ok().json(relationships)) + Ok(HttpResponse::Ok().json(vec![relationship])) } #[post("/{account_id}/follow")] diff --git a/src/models/relationships/queries.rs b/src/models/relationships/queries.rs index bfe96ae..cc2ea14 100644 --- a/src/models/relationships/queries.rs +++ b/src/models/relationships/queries.rs @@ -18,39 +18,6 @@ use super::types::{ Relationship, }; -pub async fn get_relationships( - db_client: &impl GenericClient, - source_id: Uuid, - target_ids: Vec, -) -> Result, DatabaseError> { - let rows = db_client.query( - " - SELECT - actor_profile.id AS profile_id, - EXISTS ( - SELECT 1 FROM relationship - WHERE source_id = $1 AND target_id = actor_profile.id - ) AS following, - EXISTS ( - SELECT 1 FROM relationship - WHERE source_id = actor_profile.id AND target_id = $1 - ) AS followed_by, - EXISTS ( - SELECT 1 FROM follow_request - WHERE source_id = $1 AND target_id = actor_profile.id - AND request_status = $3 - ) AS requested - FROM actor_profile - WHERE actor_profile.id = ANY($2) - ", - &[&source_id, &target_ids, &FollowRequestStatus::Pending], - ).await?; - let relationships = rows.iter() - .map(Relationship::try_from) - .collect::>()?; - Ok(relationships) -} - pub async fn get_relationship( db_client: &impl GenericClient, source_id: &Uuid,