fix: iter after flat and unpack node

flat iter gives us only objects, but we want links...
This commit is contained in:
əlemi 2024-06-22 05:08:05 +02:00
parent b801c1143e
commit b3184e7ae2
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -124,34 +124,37 @@ impl Normalizer for crate::Context {
.await?;
}
for tag in object.tag() {
match tag.link_type() {
Ok(apb::LinkType::Mention) => {
let model = crate::model::mention::ActiveModel {
internal: NotSet,
object: Set(object_model.internal),
actor: Set(tag.href().to_string()),
published: Set(now),
};
crate::model::mention::Entity::insert(model)
.exec(tx)
.await?;
},
Ok(apb::LinkType::Hashtag) => {
let hashtag = tag.name()
.unwrap_or_else(|_| tag.href().split('/').last().unwrap_or_default())
.replace('#', "");
let model = crate::model::hashtag::ActiveModel {
internal: NotSet,
object: Set(object_model.internal),
name: Set(hashtag),
published: Set(now),
};
crate::model::hashtag::Entity::insert(model)
.exec(tx)
.await?;
},
_ => {},
for tag in object.tag().flat() {
match tag {
Node::Empty | Node::Object(_) | Node::Array(_) => {},
Node::Link(l) => match l.link_type() {
Ok(apb::LinkType::Mention) => {
let model = crate::model::mention::ActiveModel {
internal: NotSet,
object: Set(object_model.internal),
actor: Set(l.href().to_string()),
published: Set(now),
};
crate::model::mention::Entity::insert(model)
.exec(tx)
.await?;
},
Ok(apb::LinkType::Hashtag) => {
let hashtag = l.name()
.unwrap_or_else(|_| l.href().split('/').last().unwrap_or_default())
.replace('#', "");
let model = crate::model::hashtag::ActiveModel {
internal: NotSet,
object: Set(object_model.internal),
name: Set(hashtag),
published: Set(now),
};
crate::model::hashtag::Entity::insert(model)
.exec(tx)
.await?;
},
_ => {},
}
}
}