aboutsummaryrefslogtreecommitdiffstats
path: root/filamento
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-03-26 15:57:24 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2025-03-26 15:57:24 +0000
commit521a8915f273dc2cda59080a2393e40e4f25db50 (patch)
tree5fd01f240084566bb8d32261819f7ab14022346e /filamento
parent4d1be876f8bccf8018728d5ee474f91c256da5c9 (diff)
downloadluz-521a8915f273dc2cda59080a2393e40e4f25db50.tar.gz
luz-521a8915f273dc2cda59080a2393e40e4f25db50.tar.bz2
luz-521a8915f273dc2cda59080a2393e40e4f25db50.zip
feat(filamento): create example
Diffstat (limited to 'filamento')
-rw-r--r--filamento/.gitignore1
-rw-r--r--filamento/Cargo.toml6
-rw-r--r--filamento/examples/example.rs35
-rw-r--r--filamento/filamento.dbbin90112 -> 94208 bytes
-rw-r--r--filamento/src/db.rs2
5 files changed, 43 insertions, 1 deletions
diff --git a/filamento/.gitignore b/filamento/.gitignore
index 8bb4037..ec8a40b 100644
--- a/filamento/.gitignore
+++ b/filamento/.gitignore
@@ -1 +1,2 @@
filamento.db
+.sqlx/
diff --git a/filamento/Cargo.toml b/filamento/Cargo.toml
index 821a6a0..aed261d 100644
--- a/filamento/Cargo.toml
+++ b/filamento/Cargo.toml
@@ -15,3 +15,9 @@ jid = { version = "0.1.0", path = "../jid", features = ["sqlx"] }
uuid = { version = "1.13.1", features = ["v4"] }
tracing = "0.1.41"
chrono = "0.4.40"
+
+[dev-dependencies]
+tracing-subscriber = "0.3.19"
+
+[[example]]
+name = "example"
diff --git a/filamento/examples/example.rs b/filamento/examples/example.rs
new file mode 100644
index 0000000..f2b787b
--- /dev/null
+++ b/filamento/examples/example.rs
@@ -0,0 +1,35 @@
+use std::{path::Path, str::FromStr, time::Duration};
+
+use filamento::{Client, db::Db};
+use jid::JID;
+use tracing::info;
+
+#[tokio::main]
+async fn main() {
+ tracing_subscriber::fmt::init();
+ let db = Db::create_connect_and_migrate(Path::new("./filamentoa.db"))
+ .await
+ .unwrap();
+ let (client, mut recv) =
+ Client::new("test@blos.sm".try_into().unwrap(), "slayed".to_string(), db);
+
+ tokio::spawn(async move {
+ while let Some(msg) = recv.recv().await {
+ info!("{:#?}", msg)
+ }
+ });
+
+ client.connect().await.unwrap();
+ tokio::time::sleep(Duration::from_secs(5)).await;
+ info!("sending message");
+ client
+ .send_message(
+ JID::from_str("cel@blos.sm").unwrap(),
+ filamento::chat::Body {
+ body: "hallo!!!".to_string(),
+ },
+ )
+ .await
+ .unwrap();
+ println!("sent message");
+}
diff --git a/filamento/filamento.db b/filamento/filamento.db
index 5c3c720..c32c939 100644
--- a/filamento/filamento.db
+++ b/filamento/filamento.db
Binary files differ
diff --git a/filamento/src/db.rs b/filamento/src/db.rs
index aea40ac..f34fea6 100644
--- a/filamento/src/db.rs
+++ b/filamento/src/db.rs
@@ -1,7 +1,7 @@
use std::{collections::HashSet, path::Path};
use jid::JID;
-use sqlx::{migrate, Error, SqlitePool};
+use sqlx::{Error, SqlitePool, migrate};
use uuid::Uuid;
use crate::{