diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 851496d..7db6435 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -419,22 +419,29 @@ paths: description: Profile not found /api/v1/directory: get: - summary: List accounts visible in the directory. + summary: List profiles visible in the directory. parameters: - name: offset in: query - description: How many accounts to skip before returning results. + description: How many profiles to skip before returning results. required: false schema: type: integer default: 0 - name: limit in: query - description: How many accounts to load. + description: How many profiles to load. required: false schema: type: integer default: 40 + - name: local + in: query + description: Only return local profiles. + required: false + schema: + type: boolean + default: true responses: 200: description: Successful operation diff --git a/src/mastodon_api/directory/types.rs b/src/mastodon_api/directory/types.rs index 6d14724..69586d6 100644 --- a/src/mastodon_api/directory/types.rs +++ b/src/mastodon_api/directory/types.rs @@ -4,6 +4,8 @@ use crate::mastodon_api::pagination::PageSize; fn default_page_size() -> PageSize { PageSize::new(40) } +fn default_only_local() -> bool { true } + /// https://docs.joinmastodon.org/methods/instance/directory/ #[derive(Deserialize)] pub struct DirectoryQueryParams { @@ -12,4 +14,7 @@ pub struct DirectoryQueryParams { #[serde(default = "default_page_size")] pub limit: PageSize, + + #[serde(default = "default_only_local")] + pub local: bool, } diff --git a/src/mastodon_api/directory/views.rs b/src/mastodon_api/directory/views.rs index 4cca412..c30f431 100644 --- a/src/mastodon_api/directory/views.rs +++ b/src/mastodon_api/directory/views.rs @@ -21,6 +21,7 @@ async fn profile_directory( get_current_user(db_client, auth.token()).await?; let profiles = get_profiles( db_client, + query_params.local, query_params.offset, query_params.limit.inner(), ).await?; diff --git a/src/models/profiles/queries.rs b/src/models/profiles/queries.rs index 793ce84..2b11ffb 100644 --- a/src/models/profiles/queries.rs +++ b/src/models/profiles/queries.rs @@ -159,21 +159,28 @@ pub async fn get_profile_by_acct( pub async fn get_profiles( db_client: &impl GenericClient, + only_local: bool, offset: u16, limit: u16, ) -> Result, DatabaseError> { - let rows = db_client.query( + let condition = if only_local { "WHERE actor_id IS NULL" } else { "" }; + let statement = format!( " SELECT actor_profile FROM actor_profile + {condition} ORDER BY username LIMIT $1 OFFSET $2 ", + condition=condition, + ); + let rows = db_client.query( + &statement, &[&i64::from(limit), &i64::from(offset)], ).await?; let profiles = rows.iter() .map(|row| row.try_get("actor_profile")) - .collect::, _>>()?; + .collect::>()?; Ok(profiles) }