fix: oops mixing activity and object of course...

This commit is contained in:
əlemi 2024-06-08 02:51:17 +02:00
parent 8386854ed7
commit 03bca17897
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 10 additions and 8 deletions

View file

@ -86,7 +86,7 @@ impl FromQueryResult for RichActivity {
fn from_query_result(res: &QueryResult, _pre: &str) -> Result<Self, DbErr> {
Ok(RichActivity {
activity: model::activity::Model::from_query_result(res, model::activity::Entity.table_name())?,
object: model::object::Model::from_query_result(res, model::activity::Entity.table_name()).ok(),
object: model::object::Model::from_query_result(res, model::object::Entity.table_name()).ok(),
liked: res.try_get(model::like::Entity.table_name(), &model::like::Column::Actor.to_string()).ok(),
attachments: None,
})
@ -119,7 +119,7 @@ pub struct RichObject {
impl FromQueryResult for RichObject {
fn from_query_result(res: &QueryResult, _pre: &str) -> Result<Self, DbErr> {
Ok(RichObject {
object: model::object::Model::from_query_result(res, model::activity::Entity.table_name())?,
object: model::object::Model::from_query_result(res, model::object::Entity.table_name())?,
liked: res.try_get(model::like::Entity.table_name(), &model::like::Column::Actor.to_string()).ok(),
attachments: None,
})
@ -144,8 +144,7 @@ impl BatchFillable for Vec<RichActivity> {
async fn with_attachments(mut self, tx: &impl ConnectionTrait) -> Result<Self, DbErr> {
let objects : Vec<model::object::Model> = self
.iter()
.filter_map(|x| x.object.as_ref())
.map(|o| o.clone())
.filter_map(|x| x.object.as_ref().cloned())
.collect();
let attachments = objects.load_many(model::attachment::Entity, tx).await?;

View file

@ -1,6 +1,6 @@
use apb::{Activity, ActivityType, Base};
use axum::{extract::{Query, State}, http::StatusCode, Json};
use sea_orm::{ActiveValue::{NotSet, Set}, ColumnTrait, Condition, EntityTrait};
use sea_orm::{ActiveValue::{NotSet, Set}, EntityTrait};
use upub::{model::job::JobType, Context};
use crate::{AuthIdentity, Identity, builders::JsonLD};

View file

@ -42,7 +42,7 @@ pub async fn paginate_activities(
collection_page(&id, offset, limit, items)
}
// TODO can we merge these two??? there are basically only two differences
// TODO can we merge these two??? there are basically only three differences
pub async fn paginate_objects(
id: String,
@ -59,7 +59,10 @@ pub async fn paginate_objects(
if with_users {
select = select
.join(sea_orm::JoinType::InnerJoin, upub::model::activity::Relation::Actors.def());
.join(
sea_orm::JoinType::InnerJoin,
upub::model::object::Relation::Actors.def() // <--- difference two
);
}
let items = select
@ -67,7 +70,7 @@ pub async fn paginate_objects(
// TODO also limit to only local activities
.limit(limit)
.offset(offset)
.into_model::<RichObject>() // <--- difference two
.into_model::<RichObject>() // <--- difference three
.all(db)
.await?
.with_attachments(db)