chore: refactored a little

This commit is contained in:
əlemi 2024-04-12 22:56:29 +02:00
parent 576e809b69
commit 95ab7a50ef
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 27 additions and 37 deletions

View file

@ -17,7 +17,7 @@ pub async fn page(
State(ctx): State<Context>,
AuthIdentity(auth): AuthIdentity,
Query(page): Query<Pagination>,
) -> Result<JsonLD<serde_json::Value>, UpubError> {
) -> crate::Result<JsonLD<serde_json::Value>> {
let limit = page.batch.unwrap_or(20).min(50);
let offset = page.offset.unwrap_or(0);
let activities = model::addressing::Entity::find_activities()

View file

@ -25,23 +25,23 @@ pub async fn page(
AuthIdentity(auth): AuthIdentity,
Query(page): Query<Pagination>,
) -> crate::Result<JsonLD<serde_json::Value>> {
let uid = ctx.uid(id.clone());
match auth {
Identity::Anonymous => Err(StatusCode::FORBIDDEN.into()),
Identity::Remote(_) => Err(StatusCode::FORBIDDEN.into()),
Identity::Local(user) => if uid == user {
let Identity::Local(uid) = auth else {
// local inbox is only for local users
return Err(UpubError::forbidden());
};
if uid != ctx.uid(id.clone()) {
return Err(UpubError::forbidden());
}
let limit = page.batch.unwrap_or(20).min(50);
let offset = page.offset.unwrap_or(0);
match model::addressing::Entity::find_activities()
.filter(Condition::all().add(model::addressing::Column::Actor.eq(&user)))
let activities = model::addressing::Entity::find_activities()
.filter(Condition::all().add(model::addressing::Column::Actor.eq(&uid)))
.order_by(model::addressing::Column::Published, Order::Asc)
.offset(offset)
.limit(limit)
.into_model::<EmbeddedActivity>()
.all(ctx.db())
.await
{
Ok(activities) => {
.await?;
Ok(JsonLD(
ctx.ap_collection_page(
&url!(ctx, "/users/{id}/inbox/page"),
@ -52,16 +52,6 @@ pub async fn page(
.collect()
).ld_context()
))
},
Err(e) => {
tracing::error!("failed paginating user inbox for {id}: {e}");
Err(StatusCode::INTERNAL_SERVER_ERROR.into())
},
}
} else {
Err(StatusCode::FORBIDDEN.into())
},
}
}
pub async fn post(