From 20df3b7d6f3213bc3f5a90cc36363865b1b9e966 Mon Sep 17 00:00:00 2001
From: cel 🌸 <cel@bunny.garden>
Date: Fri, 28 Mar 2025 21:25:36 +0000
Subject: feat(filamento): `From` impls for disco types

---
 filamento/src/disco.rs | 124 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 123 insertions(+), 1 deletion(-)

(limited to 'filamento')

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)
-- 
cgit