Compare commits

..

No commits in common. "f249237dc500d207e2eaf658603c1ccb88724823" and "9e196b3180b0b5fc500dcd0a59988ecb4e1162ea" have entirely different histories.

2 changed files with 21 additions and 41 deletions

View file

@ -38,12 +38,6 @@ macro_rules! strenum {
$($deep($inner),)* $($deep($inner),)*
} }
impl std::fmt::Display for $enum_name {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.as_ref())
}
}
impl AsRef<str> for $enum_name { impl AsRef<str> for $enum_name {
fn as_ref(&self) -> &str { fn as_ref(&self) -> &str {
match self { match self {

View file

@ -6,9 +6,6 @@ pub enum NormalizerError {
#[error("normalized document misses required field: {0:?}")] #[error("normalized document misses required field: {0:?}")]
Malformed(#[from] apb::FieldErr), Malformed(#[from] apb::FieldErr),
#[error("wrong object type: expected {0}, got {1}")]
WrongType(apb::BaseType, apb::BaseType),
#[error("database error while normalizing object: {0:?}")] #[error("database error while normalizing object: {0:?}")]
DbErr(#[from] sea_orm::DbErr), DbErr(#[from] sea_orm::DbErr),
} }
@ -153,11 +150,7 @@ impl Normalizer for crate::Context {
pub struct AP; pub struct AP;
impl AP { impl AP {
pub fn activity(activity: &impl apb::Activity) -> Result<crate::model::activity::Model, NormalizerError> { pub fn activity(activity: &impl apb::Activity) -> Result<crate::model::activity::Model, apb::FieldErr> {
let t = activity.base_type()?;
if !matches!(t, apb::BaseType::Object(apb::ObjectType::Activity(_))) {
return Err(NormalizerError::WrongType(apb::BaseType::Object(apb::ObjectType::Activity(apb::ActivityType::Activity)), t));
}
Ok(crate::model::activity::Model { Ok(crate::model::activity::Model {
internal: 0, internal: 0,
id: activity.id()?.to_string(), id: activity.id()?.to_string(),
@ -173,7 +166,7 @@ impl AP {
}) })
} }
pub fn activity_q(activity: &impl apb::Activity) -> Result<crate::model::activity::ActiveModel, NormalizerError> { pub fn activity_q(activity: &impl apb::Activity) -> Result<crate::model::activity::ActiveModel, apb::FieldErr> {
let mut m = AP::activity(activity)?.into_active_model(); let mut m = AP::activity(activity)?.into_active_model();
m.internal = NotSet; m.internal = NotSet;
Ok(m) Ok(m)
@ -182,11 +175,7 @@ impl AP {
pub fn attachment(document: &impl apb::Document, parent: i64) -> Result<crate::model::attachment::Model, NormalizerError> { pub fn attachment(document: &impl apb::Document, parent: i64) -> Result<crate::model::attachment::Model, apb::FieldErr> {
let t = document.base_type()?;
if !matches!(t, apb::BaseType::Object(apb::ObjectType::Document(_))) {
return Err(NormalizerError::WrongType(apb::BaseType::Object(apb::ObjectType::Document(apb::DocumentType::Document)), t));
}
Ok(crate::model::attachment::Model { Ok(crate::model::attachment::Model {
internal: 0, internal: 0,
url: document.url().id().str().unwrap_or_default(), url: document.url().id().str().unwrap_or_default(),
@ -198,7 +187,7 @@ 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) -> Result<crate::model::attachment::ActiveModel, apb::FieldErr> {
let mut m = AP::attachment(document, parent)?.into_active_model(); let mut m = AP::attachment(document, parent)?.into_active_model();
m.internal = NotSet; m.internal = NotSet;
Ok(m) Ok(m)
@ -206,25 +195,26 @@ impl AP {
pub fn object(object: &impl apb::Object) -> Result<crate::model::object::Model, NormalizerError> { pub fn object(object: &impl apb::Object) -> Result<crate::model::object::Model, apb::FieldErr> {
let t = object.base_type()?; let t = object.object_type()?;
if !matches!(t, if matches!(t,
apb::BaseType::Object( apb::ObjectType::Activity(_)
apb::ObjectType::Object | apb::ObjectType::Actor(_)
| apb::ObjectType::Note | apb::ObjectType::Collection(_)
| apb::ObjectType::Article | apb::ObjectType::Document(
| apb::ObjectType::Event // TODO lemmy posts are PAGEs...
| apb::ObjectType::Place apb::DocumentType::Document
| apb::ObjectType::Profile | apb::DocumentType::Audio
| apb::ObjectType::Document(apb::DocumentType::Page) // why Document lemmy?????? | apb::DocumentType::Image
| apb::DocumentType::Video
) )
) { ) {
return Err(NormalizerError::WrongType(apb::BaseType::Object(apb::ObjectType::Object), t)); return Err(apb::FieldErr("type"));
} }
Ok(crate::model::object::Model { Ok(crate::model::object::Model {
internal: 0, internal: 0,
id: object.id()?.to_string(), id: object.id()?.to_string(),
object_type: object.object_type()?, object_type: t,
attributed_to: object.attributed_to().id().str(), attributed_to: object.attributed_to().id().str(),
name: object.name().str(), name: object.name().str(),
summary: object.summary().str(), summary: object.summary().str(),
@ -249,7 +239,7 @@ impl AP {
}) })
} }
pub fn object_q(object: &impl apb::Object) -> Result<crate::model::object::ActiveModel, NormalizerError> { pub fn object_q(object: &impl apb::Object) -> Result<crate::model::object::ActiveModel, apb::FieldErr> {
let mut m = AP::object(object)?.into_active_model(); let mut m = AP::object(object)?.into_active_model();
m.internal = NotSet; m.internal = NotSet;
Ok(m) Ok(m)
@ -257,11 +247,7 @@ impl AP {
pub fn actor(actor: &impl apb::Actor) -> Result<crate::model::actor::Model, NormalizerError> { pub fn actor(actor: &impl apb::Actor) -> Result<crate::model::actor::Model, apb::FieldErr> {
let t = actor.base_type()?;
if !matches!(t, apb::BaseType::Object(apb::ObjectType::Actor(_))) {
return Err(NormalizerError::WrongType(apb::BaseType::Object(apb::ObjectType::Actor(apb::ActorType::Person)), t));
}
let ap_id = actor.id()?.to_string(); let ap_id = actor.id()?.to_string();
let (domain, fallback_preferred_username) = { let (domain, fallback_preferred_username) = {
let clean = ap_id let clean = ap_id
@ -297,7 +283,7 @@ impl AP {
}) })
} }
pub fn actor_q(actor: &impl apb::Actor) -> Result<crate::model::actor::ActiveModel, NormalizerError> { pub fn actor_q(actor: &impl apb::Actor) -> Result<crate::model::actor::ActiveModel, apb::FieldErr> {
let mut m = AP::actor(actor)?.into_active_model(); let mut m = AP::actor(actor)?.into_active_model();
m.internal = NotSet; m.internal = NotSet;
Ok(m) Ok(m)