2021-04-09 00:22:17 +00:00
|
|
|
use actix_web::{get, web, HttpResponse};
|
2021-10-05 18:10:14 +00:00
|
|
|
use actix_web_httpauth::extractors::bearer::BearerAuth;
|
2021-04-09 00:22:17 +00:00
|
|
|
|
|
|
|
use crate::config::Config;
|
|
|
|
use crate::database::{Pool, get_database_client};
|
|
|
|
use crate::errors::HttpError;
|
2021-10-05 18:10:14 +00:00
|
|
|
use crate::mastodon_api::oauth::auth::get_current_user;
|
2021-04-09 00:22:17 +00:00
|
|
|
use crate::mastodon_api::statuses::types::Status;
|
|
|
|
use crate::models::posts::queries::get_posts;
|
|
|
|
|
|
|
|
#[get("/api/v1/timelines/home")]
|
|
|
|
pub async fn home_timeline(
|
2021-10-05 18:10:14 +00:00
|
|
|
auth: BearerAuth,
|
2021-04-09 00:22:17 +00:00
|
|
|
config: web::Data<Config>,
|
|
|
|
db_pool: web::Data<Pool>,
|
|
|
|
) -> Result<HttpResponse, HttpError> {
|
|
|
|
let db_client = &**get_database_client(&db_pool).await?;
|
2021-10-05 18:10:14 +00:00
|
|
|
let current_user = get_current_user(db_client, auth.token()).await?;
|
2021-04-09 00:22:17 +00:00
|
|
|
let statuses: Vec<Status> = get_posts(db_client, ¤t_user.id).await?
|
|
|
|
.into_iter()
|
|
|
|
.map(|post| Status::from_post(post, &config.instance_url()))
|
|
|
|
.collect();
|
|
|
|
Ok(HttpResponse::Ok().json(statuses))
|
|
|
|
}
|