From 521a8915f273dc2cda59080a2393e40e4f25db50 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Wed, 26 Mar 2025 15:57:24 +0000 Subject: feat(filamento): create example --- filamento/.gitignore | 1 + filamento/Cargo.toml | 6 ++++++ filamento/examples/example.rs | 35 +++++++++++++++++++++++++++++++++++ filamento/filamento.db | Bin 90112 -> 94208 bytes filamento/src/db.rs | 2 +- 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 filamento/examples/example.rs (limited to 'filamento') 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 Binary files a/filamento/filamento.db and b/filamento/filamento.db 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::{ -- cgit