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),)*
}
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 {
fn as_ref(&self) -> &str {
match self {

View file

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