aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-03-28 21:25:36 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2025-03-28 21:25:36 +0000
commit20df3b7d6f3213bc3f5a90cc36363865b1b9e966 (patch)
treea72e360a0adbfa624f9200691e1ba3fe83199ad4
parent7d122d244622c664a7f5d8d99efc739dba5e6a3d (diff)
downloadluz-20df3b7d6f3213bc3f5a90cc36363865b1b9e966.tar.gz
luz-20df3b7d6f3213bc3f5a90cc36363865b1b9e966.tar.bz2
luz-20df3b7d6f3213bc3f5a90cc36363865b1b9e966.zip
feat(filamento): `From` impls for disco types
-rw-r--r--filamento/src/disco.rs124
-rw-r--r--stanza/src/xep_0030/items.rs10
2 files changed, 128 insertions, 6 deletions
diff --git a/filamento/src/disco.rs b/filamento/src/disco.rs
index 233dd5f..86e339e 100644
--- a/filamento/src/disco.rs
+++ b/filamento/src/disco.rs
@@ -1,4 +1,5 @@
-use stanza::xep_0030::info;
+use jid::JID;
+use stanza::xep_0030::{info, items};
pub use feature::Feature;
pub use identity::Identity;
@@ -9,7 +10,104 @@ pub struct Info {
identities: Vec<Identity>,
}
+impl From<info::Query> for Info {
+ fn from(value: info::Query) -> Self {
+ let features = value
+ .features
+ .into_iter()
+ .map(|feature| feature.into())
+ .collect();
+ let identities = value
+ .identities
+ .into_iter()
+ .map(|identity| identity.into())
+ .collect();
+
+ Self {
+ node: value.node,
+ features,
+ identities,
+ }
+ }
+}
+
+impl From<Info> for info::Query {
+ fn from(value: Info) -> Self {
+ let features = value
+ .features
+ .into_iter()
+ .map(|feature| feature.into())
+ .collect();
+ let identities = value
+ .identities
+ .into_iter()
+ .map(|identity| identity.into())
+ .collect();
+
+ Self {
+ node: value.node,
+ features,
+ identities,
+ }
+ }
+}
+
+pub struct Items {
+ node: Option<String>,
+ items: Vec<Item>,
+}
+
+impl From<items::Query> for Items {
+ fn from(value: items::Query) -> Self {
+ let items = value.items.into_iter().map(|item| item.into()).collect();
+
+ Self {
+ node: value.node,
+ items,
+ }
+ }
+}
+
+impl From<Items> for items::Query {
+ fn from(value: Items) -> Self {
+ let items = value.items.into_iter().map(|item| item.into()).collect();
+
+ Self {
+ node: value.node,
+ items,
+ }
+ }
+}
+
+pub struct Item {
+ jid: JID,
+ name: Option<String>,
+ node: Option<String>,
+}
+
+impl From<items::Item> for Item {
+ fn from(value: items::Item) -> Self {
+ Self {
+ jid: value.jid,
+ name: value.name,
+ node: value.node,
+ }
+ }
+}
+
+impl From<Item> for items::Item {
+ fn from(value: Item) -> Self {
+ Self {
+ jid: value.jid,
+ name: value.name,
+ node: value.node,
+ }
+ }
+}
+
mod feature {
+ use stanza::xep_0030::info;
+
// https://xmpp.org/registrar/disco-features.html
pub enum Feature {
DNSSRV,
@@ -74,6 +172,20 @@ mod feature {
Unknown(String),
}
+ impl From<info::Feature> for Feature {
+ fn from(value: info::Feature) -> Self {
+ value.var.as_str().into()
+ }
+ }
+
+ impl From<Feature> for info::Feature {
+ fn from(value: Feature) -> Self {
+ Self {
+ var: value.to_string(),
+ }
+ }
+ }
+
impl From<&str> for Feature {
fn from(value: &str) -> Self {
match value {
@@ -940,6 +1052,16 @@ mod identity {
}
}
+ impl From<Identity> for info::Identity {
+ fn from(value: Identity) -> Self {
+ Self {
+ category: value.category.to_string(),
+ name: value.name,
+ r#type: value.category.r#type(),
+ }
+ }
+ }
+
// TODO: separate crate for disco registry
/// categories taken from [XMPP Disco Categories](https://xmpp.org/registrar/disco-categories.html)
diff --git a/stanza/src/xep_0030/items.rs b/stanza/src/xep_0030/items.rs
index 78fe332..7af2bbf 100644
--- a/stanza/src/xep_0030/items.rs
+++ b/stanza/src/xep_0030/items.rs
@@ -8,8 +8,8 @@ pub const XMLNS: &str = "http://jabber.org/protocol/disco#items";
#[derive(Debug, Clone)]
pub struct Query {
- node: Option<String>,
- items: Vec<Item>,
+ pub node: Option<String>,
+ pub items: Vec<Item>,
}
impl FromElement for Query {
@@ -35,9 +35,9 @@ impl IntoElement for Query {
#[derive(Debug, Clone)]
pub struct Item {
- jid: JID,
- name: Option<String>,
- node: Option<String>,
+ pub jid: JID,
+ pub name: Option<String>,
+ pub node: Option<String>,
}
impl FromElement for Item {