2024-04-11 00:52:44 +02:00
|
|
|
use axum::{extract::{Path, State}, http::StatusCode, Json};
|
|
|
|
use mastodon_async_entities::account::{Account, AccountId};
|
|
|
|
use sea_orm::EntityTrait;
|
|
|
|
|
2024-04-11 16:59:47 +02:00
|
|
|
use crate::{model, server::{auth::AuthIdentity, Context}};
|
2024-04-11 00:52:44 +02:00
|
|
|
|
|
|
|
pub async fn view(
|
|
|
|
State(ctx): State<Context>,
|
2024-04-11 16:59:47 +02:00
|
|
|
AuthIdentity(_auth): AuthIdentity,
|
2024-04-11 00:52:44 +02:00
|
|
|
Path(id): Path<String>
|
|
|
|
) -> Result<Json<Account>, StatusCode> {
|
|
|
|
match model::user::Entity::find_by_id(ctx.uid(id))
|
|
|
|
.find_also_related(model::config::Entity)
|
|
|
|
.one(ctx.db())
|
|
|
|
.await
|
|
|
|
{
|
2024-04-11 16:59:47 +02:00
|
|
|
Err(_e) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
2024-04-11 00:52:44 +02:00
|
|
|
Ok(None) => Err(StatusCode::NOT_FOUND),
|
2024-04-11 16:59:47 +02:00
|
|
|
Ok(Some((_x, None))) => Err(StatusCode::NOT_IMPLEMENTED), // TODO remote user
|
2024-04-11 00:52:44 +02:00
|
|
|
Ok(Some((x, Some(cfg)))) => Ok(Json(Account {
|
2024-04-11 16:59:47 +02:00
|
|
|
acct: x.preferred_username.clone(),
|
|
|
|
avatar: x.icon.as_deref().unwrap_or("").to_string(),
|
2024-04-11 00:52:44 +02:00
|
|
|
avatar_static: x.icon.unwrap_or_default(),
|
2024-04-11 16:59:47 +02:00
|
|
|
created_at: time::OffsetDateTime::from_unix_timestamp(x.created.timestamp()).unwrap(),
|
2024-04-11 00:52:44 +02:00
|
|
|
display_name: x.name.unwrap_or_default(),
|
|
|
|
// TODO hide these maybe
|
|
|
|
followers_count: x.followers_count as u64,
|
|
|
|
following_count: x.following_count as u64,
|
2024-04-11 16:59:47 +02:00
|
|
|
header: x.image.as_deref().unwrap_or("").to_string(),
|
2024-04-11 00:52:44 +02:00
|
|
|
header_static: x.image.unwrap_or_default(),
|
2024-04-11 16:59:47 +02:00
|
|
|
id: AccountId::new(x.id.clone()),
|
2024-04-11 00:52:44 +02:00
|
|
|
locked: !cfg.accept_follow_requests,
|
|
|
|
note: x.summary.unwrap_or_default(),
|
2024-04-11 16:59:47 +02:00
|
|
|
statuses_count: 0, // TODO keep track in each user
|
2024-04-11 00:52:44 +02:00
|
|
|
url: x.id,
|
|
|
|
username: x.preferred_username,
|
|
|
|
source: None,
|
|
|
|
moved: None,
|
2024-04-11 16:59:47 +02:00
|
|
|
fields: None, // TODO user fields
|
2024-04-11 00:52:44 +02:00
|
|
|
bot: None,
|
|
|
|
})),
|
|
|
|
}
|
|
|
|
}
|