fix: updates should now work!
This commit is contained in:
parent
e1f1548e7e
commit
6fed451513
5 changed files with 34 additions and 21 deletions
|
@ -17,7 +17,7 @@ pub async fn fetch(ctx: upub::Context, uri: String, save: bool) -> Result<(), Pu
|
|||
match obj.base_type() {
|
||||
Ok(apb::BaseType::Object(apb::ObjectType::Actor(_))) => {
|
||||
upub::model::actor::Entity::insert(
|
||||
upub::AP::actor_q(&obj).unwrap()
|
||||
upub::AP::actor_q(&obj, None).unwrap()
|
||||
).exec(&tx).await.unwrap();
|
||||
},
|
||||
Ok(apb::BaseType::Object(apb::ObjectType::Activity(_))) => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use futures::TryStreamExt;
|
||||
use sea_orm::{ActiveModelTrait, ActiveValue::{Set, Unchanged}, ColumnTrait, EntityTrait, QueryFilter};
|
||||
use sea_orm::{ActiveModelTrait, ActiveValue::Set, ColumnTrait, EntityTrait, QueryFilter};
|
||||
use upub::traits::Fetcher;
|
||||
|
||||
pub async fn update_users(ctx: upub::Context, days: i64) -> Result<(), sea_orm::DbErr> {
|
||||
|
@ -18,9 +18,8 @@ pub async fn update_users(ctx: upub::Context, days: i64) -> Result<(), sea_orm::
|
|||
match ctx.pull(&user.id).await.map(|x| x.actor()) {
|
||||
Err(e) => tracing::warn!("could not update user {}: {e}", user.id),
|
||||
Ok(Err(e)) => tracing::warn!("could not update user {}: {e}", user.id),
|
||||
Ok(Ok(doc)) => match upub::AP::actor_q(&doc) {
|
||||
Ok(Ok(doc)) => match upub::AP::actor_q(&doc, Some(user.internal)) {
|
||||
Ok(mut u) => {
|
||||
u.internal = Unchanged(user.internal);
|
||||
u.updated = Set(chrono::Utc::now());
|
||||
insertions.push((user.id, u));
|
||||
count += 1;
|
||||
|
|
|
@ -305,7 +305,7 @@ impl Fetcher for crate::Context {
|
|||
}
|
||||
}
|
||||
|
||||
let user_model = AP::actor_q(&document)?;
|
||||
let user_model = AP::actor_q(&document, None)?;
|
||||
|
||||
// TODO this may fail: while fetching, remote server may fetch our service actor.
|
||||
// if it does so with http signature, we will fetch that actor in background
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use apb::{field::OptionalString, Collection, Document, Endpoints, Node, Object, PublicKey};
|
||||
use sea_orm::{sea_query::Expr, ActiveValue::{NotSet, Set}, ColumnTrait, ConnectionTrait, DbErr, EntityTrait, IntoActiveModel, QueryFilter};
|
||||
use sea_orm::{sea_query::Expr, ActiveModelTrait, ActiveValue::{Unchanged, NotSet, Set}, ColumnTrait, ConnectionTrait, DbErr, EntityTrait, IntoActiveModel, QueryFilter};
|
||||
|
||||
use super::Addresser;
|
||||
|
||||
|
@ -89,7 +89,7 @@ impl Normalizer for crate::Context {
|
|||
published: Set(chrono::Utc::now()),
|
||||
},
|
||||
Node::Object(o) =>
|
||||
AP::attachment_q(o.as_document()?, object_model.internal)?,
|
||||
AP::attachment_q(o.as_document()?, object_model.internal, None)?,
|
||||
};
|
||||
crate::model::attachment::Entity::insert(attachment_model)
|
||||
.exec(tx)
|
||||
|
@ -109,7 +109,7 @@ impl Normalizer for crate::Context {
|
|||
None
|
||||
};
|
||||
|
||||
let mut attachment_model = AP::attachment_q(img, object_model.internal)?;
|
||||
let mut attachment_model = AP::attachment_q(img, object_model.internal, None)?;
|
||||
|
||||
// ugly fix for lemmy
|
||||
if let Some(m) = media_type {
|
||||
|
@ -169,9 +169,13 @@ impl AP {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn activity_q(activity: &impl apb::Activity) -> Result<crate::model::activity::ActiveModel, NormalizerError> {
|
||||
pub fn activity_q(activity: &impl apb::Activity, internal: Option<i64>) -> Result<crate::model::activity::ActiveModel, NormalizerError> {
|
||||
let mut m = AP::activity(activity)?.into_active_model();
|
||||
m.internal = NotSet;
|
||||
m = m.reset_all();
|
||||
match internal {
|
||||
Some(x) => m.internal = Unchanged(x),
|
||||
None => m.internal = NotSet,
|
||||
}
|
||||
Ok(m)
|
||||
}
|
||||
|
||||
|
@ -194,9 +198,13 @@ impl AP {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn attachment_q(document: &impl apb::Document, parent: i64) -> Result<crate::model::attachment::ActiveModel, NormalizerError> {
|
||||
pub fn attachment_q(document: &impl apb::Document, parent: i64, internal: Option<i64>) -> Result<crate::model::attachment::ActiveModel, NormalizerError> {
|
||||
let mut m = AP::attachment(document, parent)?.into_active_model();
|
||||
m.internal = NotSet;
|
||||
m = m.reset_all();
|
||||
match internal {
|
||||
Some(x) => m.internal = Unchanged(x),
|
||||
None => m.internal = NotSet,
|
||||
}
|
||||
Ok(m)
|
||||
}
|
||||
|
||||
|
@ -246,9 +254,13 @@ impl AP {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn object_q(object: &impl apb::Object) -> Result<crate::model::object::ActiveModel, NormalizerError> {
|
||||
pub fn object_q(object: &impl apb::Object, internal: Option<i64>) -> Result<crate::model::object::ActiveModel, NormalizerError> {
|
||||
let mut m = AP::object(object)?.into_active_model();
|
||||
m.internal = NotSet;
|
||||
m = m.reset_all();
|
||||
match internal {
|
||||
Some(x) => m.internal = Unchanged(x),
|
||||
None => m.internal = NotSet,
|
||||
}
|
||||
Ok(m)
|
||||
}
|
||||
|
||||
|
@ -294,9 +306,13 @@ impl AP {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn actor_q(actor: &impl apb::Actor) -> Result<crate::model::actor::ActiveModel, NormalizerError> {
|
||||
pub fn actor_q(actor: &impl apb::Actor, internal: Option<i64>) -> Result<crate::model::actor::ActiveModel, NormalizerError> {
|
||||
let mut m = AP::actor(actor)?.into_active_model();
|
||||
m.internal = NotSet;
|
||||
m = m.reset_all();
|
||||
match internal {
|
||||
Some(x) => m.internal = Unchanged(x),
|
||||
None => m.internal = NotSet,
|
||||
}
|
||||
Ok(m)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use apb::{target::Addressed, Activity, Base, Object};
|
||||
use sea_orm::{sea_query::Expr, ActiveModelTrait, ActiveValue::{NotSet, Set, Unchanged}, ColumnTrait, Condition, DatabaseTransaction, EntityTrait, QueryFilter, QuerySelect, SelectColumns};
|
||||
use sea_orm::{sea_query::Expr, ActiveModelTrait, ActiveValue::{NotSet, Set}, ColumnTrait, Condition, DatabaseTransaction, EntityTrait, QueryFilter, QuerySelect, SelectColumns};
|
||||
use crate::{ext::{AnyQuery, LoggableError}, model, traits::{fetch::Pull, Fetcher, Normalizer}};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
@ -265,8 +265,7 @@ pub async fn update(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
|
|||
let internal_uid = crate::model::actor::Entity::ap_to_internal(&oid, tx)
|
||||
.await?
|
||||
.ok_or(ProcessorError::Incomplete)?;
|
||||
let mut actor_model = crate::AP::actor_q(object_node.as_actor()?)?;
|
||||
actor_model.internal = Unchanged(internal_uid);
|
||||
let mut actor_model = crate::AP::actor_q(object_node.as_actor()?, Some(internal_uid))?;
|
||||
actor_model.updated = Set(chrono::Utc::now());
|
||||
actor_model.update(tx).await?;
|
||||
},
|
||||
|
@ -274,8 +273,7 @@ pub async fn update(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
|
|||
let internal_oid = crate::model::object::Entity::ap_to_internal(&oid, tx)
|
||||
.await?
|
||||
.ok_or(ProcessorError::Incomplete)?;
|
||||
let mut object_model = crate::AP::object_q(&object_node)?;
|
||||
object_model.internal = Unchanged(internal_oid);
|
||||
let mut object_model = crate::AP::object_q(&object_node, Some(internal_oid))?;
|
||||
object_model.updated = Set(chrono::Utc::now());
|
||||
object_model.update(tx).await?;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue