-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
see who boosted/favourited a post in mastodon api (#367)
- Loading branch information
Showing
4 changed files
with
307 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
kitsune/src/http/handler/mastodon/api/v1/statuses/favourited_by.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use crate::{ | ||
consts::default_limit, | ||
error::Result, | ||
http::{ | ||
extractor::MastodonAuthExtractor, | ||
pagination::{LinkHeader, PaginatedJsonResponse}, | ||
}, | ||
}; | ||
use axum::{ | ||
debug_handler, | ||
extract::{OriginalUri, Path, State}, | ||
Json, | ||
}; | ||
use axum_extra::extract::Query; | ||
use futures_util::TryStreamExt; | ||
use kitsune_core::{ | ||
mapping::MastodonMapper, | ||
service::{ | ||
post::{GetAccountsInteractingWithPost, PostService}, | ||
url::UrlService, | ||
}, | ||
}; | ||
use kitsune_type::mastodon::Account; | ||
use serde::Deserialize; | ||
use speedy_uuid::Uuid; | ||
use utoipa::IntoParams; | ||
|
||
#[derive(Deserialize, IntoParams)] | ||
pub struct GetQuery { | ||
min_id: Option<Uuid>, | ||
max_id: Option<Uuid>, | ||
since_id: Option<Uuid>, | ||
#[serde(default = "default_limit")] | ||
limit: usize, | ||
} | ||
|
||
#[debug_handler(state = crate::state::Zustand)] | ||
#[utoipa::path( | ||
get, | ||
path = "/api/v1/statuses/{id}/favourited_by", | ||
security( | ||
("oauth_token" = []) | ||
), | ||
params(GetQuery), | ||
responses( | ||
(status = 200, description = "List of accounts that favourited the status", body = Vec<Account>) | ||
), | ||
)] | ||
pub async fn get( | ||
State(post_service): State<PostService>, | ||
State(mastodon_mapper): State<MastodonMapper>, | ||
State(url_service): State<UrlService>, | ||
OriginalUri(original_uri): OriginalUri, | ||
Query(query): Query<GetQuery>, | ||
user_data: Option<MastodonAuthExtractor>, | ||
Path(id): Path<Uuid>, | ||
) -> Result<PaginatedJsonResponse<Account>> { | ||
let fetching_account_id = user_data.map(|user_data| user_data.0.account.id); | ||
let get_favourites = GetAccountsInteractingWithPost::builder() | ||
.post_id(id) | ||
.fetching_account_id(fetching_account_id) | ||
.limit(query.limit) | ||
.since_id(query.since_id) | ||
.min_id(query.min_id) | ||
.max_id(query.max_id) | ||
.build(); | ||
|
||
let accounts: Vec<Account> = post_service | ||
.favourited_by(get_favourites) | ||
.await? | ||
.and_then(|acc| mastodon_mapper.map(acc)) | ||
.try_collect() | ||
.await?; | ||
|
||
let link_header = LinkHeader::new( | ||
&accounts, | ||
query.limit, | ||
&url_service.base_url(), | ||
original_uri.path(), | ||
|a| a.id, | ||
); | ||
|
||
Ok((link_header, Json(accounts))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
kitsune/src/http/handler/mastodon/api/v1/statuses/reblogged_by.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use crate::{ | ||
consts::default_limit, | ||
error::Result, | ||
http::{ | ||
extractor::MastodonAuthExtractor, | ||
pagination::{LinkHeader, PaginatedJsonResponse}, | ||
}, | ||
}; | ||
use axum::{ | ||
debug_handler, | ||
extract::{OriginalUri, Path, State}, | ||
Json, | ||
}; | ||
use axum_extra::extract::Query; | ||
use futures_util::TryStreamExt; | ||
use kitsune_core::{ | ||
mapping::MastodonMapper, | ||
service::{ | ||
post::{GetAccountsInteractingWithPost, PostService}, | ||
url::UrlService, | ||
}, | ||
}; | ||
use kitsune_type::mastodon::Account; | ||
use serde::Deserialize; | ||
use speedy_uuid::Uuid; | ||
use utoipa::IntoParams; | ||
|
||
#[derive(Deserialize, IntoParams)] | ||
pub struct GetQuery { | ||
min_id: Option<Uuid>, | ||
max_id: Option<Uuid>, | ||
since_id: Option<Uuid>, | ||
#[serde(default = "default_limit")] | ||
limit: usize, | ||
} | ||
|
||
#[debug_handler(state = crate::state::Zustand)] | ||
#[utoipa::path( | ||
get, | ||
path = "/api/v1/statuses/{id}/reblogged_by", | ||
security( | ||
("oauth_token" = []) | ||
), | ||
params(GetQuery), | ||
responses( | ||
(status = 200, description = "List of accounts that reblogged the status", body = Vec<Account>) | ||
), | ||
)] | ||
pub async fn get( | ||
State(post_service): State<PostService>, | ||
State(mastodon_mapper): State<MastodonMapper>, | ||
State(url_service): State<UrlService>, | ||
OriginalUri(original_uri): OriginalUri, | ||
Query(query): Query<GetQuery>, | ||
user_data: Option<MastodonAuthExtractor>, | ||
Path(id): Path<Uuid>, | ||
) -> Result<PaginatedJsonResponse<Account>> { | ||
let fetching_account_id = user_data.map(|user_data| user_data.0.account.id); | ||
let get_reblogs = GetAccountsInteractingWithPost::builder() | ||
.post_id(id) | ||
.fetching_account_id(fetching_account_id) | ||
.limit(query.limit) | ||
.since_id(query.since_id) | ||
.min_id(query.min_id) | ||
.max_id(query.max_id) | ||
.build(); | ||
|
||
let accounts: Vec<Account> = post_service | ||
.reblogged_by(get_reblogs) | ||
.await? | ||
.and_then(|acc| mastodon_mapper.map(acc)) | ||
.try_collect() | ||
.await?; | ||
|
||
let link_header = LinkHeader::new( | ||
&accounts, | ||
query.limit, | ||
&url_service.base_url(), | ||
original_uri.path(), | ||
|a| a.id, | ||
); | ||
|
||
Ok((link_header, Json(accounts))) | ||
} |