forked from alemi/upub
chore: refactored a little
This commit is contained in:
parent
576e809b69
commit
95ab7a50ef
2 changed files with 27 additions and 37 deletions
|
@ -17,7 +17,7 @@ pub async fn page(
|
||||||
State(ctx): State<Context>,
|
State(ctx): State<Context>,
|
||||||
AuthIdentity(auth): AuthIdentity,
|
AuthIdentity(auth): AuthIdentity,
|
||||||
Query(page): Query<Pagination>,
|
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 limit = page.batch.unwrap_or(20).min(50);
|
||||||
let offset = page.offset.unwrap_or(0);
|
let offset = page.offset.unwrap_or(0);
|
||||||
let activities = model::addressing::Entity::find_activities()
|
let activities = model::addressing::Entity::find_activities()
|
||||||
|
|
|
@ -25,43 +25,33 @@ pub async fn page(
|
||||||
AuthIdentity(auth): AuthIdentity,
|
AuthIdentity(auth): AuthIdentity,
|
||||||
Query(page): Query<Pagination>,
|
Query(page): Query<Pagination>,
|
||||||
) -> crate::Result<JsonLD<serde_json::Value>> {
|
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||||
let uid = ctx.uid(id.clone());
|
let Identity::Local(uid) = auth else {
|
||||||
match auth {
|
// local inbox is only for local users
|
||||||
Identity::Anonymous => Err(StatusCode::FORBIDDEN.into()),
|
return Err(UpubError::forbidden());
|
||||||
Identity::Remote(_) => Err(StatusCode::FORBIDDEN.into()),
|
};
|
||||||
Identity::Local(user) => if uid == user {
|
if uid != ctx.uid(id.clone()) {
|
||||||
let limit = page.batch.unwrap_or(20).min(50);
|
return Err(UpubError::forbidden());
|
||||||
let offset = page.offset.unwrap_or(0);
|
|
||||||
match model::addressing::Entity::find_activities()
|
|
||||||
.filter(Condition::all().add(model::addressing::Column::Actor.eq(&user)))
|
|
||||||
.order_by(model::addressing::Column::Published, Order::Asc)
|
|
||||||
.offset(offset)
|
|
||||||
.limit(limit)
|
|
||||||
.into_model::<EmbeddedActivity>()
|
|
||||||
.all(ctx.db())
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(activities) => {
|
|
||||||
Ok(JsonLD(
|
|
||||||
ctx.ap_collection_page(
|
|
||||||
&url!(ctx, "/users/{id}/inbox/page"),
|
|
||||||
offset, limit,
|
|
||||||
activities
|
|
||||||
.into_iter()
|
|
||||||
.map(|x| x.into())
|
|
||||||
.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())
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
let limit = page.batch.unwrap_or(20).min(50);
|
||||||
|
let offset = page.offset.unwrap_or(0);
|
||||||
|
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(JsonLD(
|
||||||
|
ctx.ap_collection_page(
|
||||||
|
&url!(ctx, "/users/{id}/inbox/page"),
|
||||||
|
offset, limit,
|
||||||
|
activities
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| x.into())
|
||||||
|
.collect()
|
||||||
|
).ld_context()
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn post(
|
pub async fn post(
|
||||||
|
|
Loading…
Reference in a new issue