1
0
Fork 0
forked from alemi/upub

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

View file

@ -1,6 +1,6 @@
use apb::{Activity, ActivityType, Base}; use apb::{Activity, ActivityType, Base};
use axum::{extract::{Query, State}, http::StatusCode, Json}; 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 upub::{model::job::JobType, Context};
use crate::{AuthIdentity, Identity, builders::JsonLD}; use crate::{AuthIdentity, Identity, builders::JsonLD};

View file

@ -42,7 +42,7 @@ pub async fn paginate_activities(
collection_page(&id, offset, limit, items) 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( pub async fn paginate_objects(
id: String, id: String,
@ -59,7 +59,10 @@ pub async fn paginate_objects(
if with_users { if with_users {
select = select 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 let items = select
@ -67,7 +70,7 @@ pub async fn paginate_objects(
// TODO also limit to only local activities // TODO also limit to only local activities
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.into_model::<RichObject>() // <--- difference two .into_model::<RichObject>() // <--- difference three
.all(db) .all(db)
.await? .await?
.with_attachments(db) .with_attachments(db)