aboutsummaryrefslogtreecommitdiffstats
path: root/filamento/examples
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--filamento/examples/example.rs224
1 files changed, 113 insertions, 111 deletions
diff --git a/filamento/examples/example.rs b/filamento/examples/example.rs
index 8119743..65fe166 100644
--- a/filamento/examples/example.rs
+++ b/filamento/examples/example.rs
@@ -1,120 +1,122 @@
-use std::{path::Path, str::FromStr, sync::Arc, time::Duration};
+// use std::{path::Path, str::FromStr, sync::Arc, time::Duration};
-use filamento::{Client, db::Db, files::FileStore};
-use jid::JID;
-use tokio::io::{self, AsyncReadExt};
-use tracing::info;
+// use filamento::{Client, db::Db, files::FileStore};
+// use jid::JID;
+// use tokio::io::{self, AsyncReadExt};
+// use tracing::info;
-#[derive(Clone, Debug)]
-pub struct Files;
+// #[derive(Clone, Debug)]
+// pub struct Files;
-impl FileStore for Files {
- type Err = Arc<io::Error>;
+// impl FileStore for Files {
+// type Err = Arc<io::Error>;
- async fn is_stored(&self, name: &str) -> Result<bool, Self::Err> {
- tracing::debug!("checking if {} is stored", name);
- let res = tokio::fs::try_exists(format!("files/{}", name))
- .await
- .map_err(|err| Arc::new(err));
- tracing::debug!("file check res: {:?}", res);
- res
- }
+// async fn is_stored(&self, name: &str) -> Result<bool, Self::Err> {
+// tracing::debug!("checking if {} is stored", name);
+// let res = tokio::fs::try_exists(format!("files/{}", name))
+// .await
+// .map_err(|err| Arc::new(err));
+// tracing::debug!("file check res: {:?}", res);
+// res
+// }
- async fn store(&self, name: &str, data: &[u8]) -> Result<(), Self::Err> {
- tracing::debug!("storing {} is stored", name);
- let res = tokio::fs::write(format!("files/{}", name), data)
- .await
- .map_err(|err| Arc::new(err));
- tracing::debug!("file store res: {:?}", res);
- res
- }
+// async fn store(&self, name: &str, data: &[u8]) -> Result<(), Self::Err> {
+// tracing::debug!("storing {} is stored", name);
+// let res = tokio::fs::write(format!("files/{}", name), data)
+// .await
+// .map_err(|err| Arc::new(err));
+// tracing::debug!("file store res: {:?}", res);
+// res
+// }
- async fn delete(&self, name: &str) -> Result<(), Self::Err> {
- tracing::debug!("deleting {}", name);
- let res = tokio::fs::remove_file(format!("files/{}", name))
- .await
- .map_err(|err| Arc::new(err));
- tracing::debug!("file delete res: {:?}", res);
- res
- }
-}
+// async fn delete(&self, name: &str) -> Result<(), Self::Err> {
+// tracing::debug!("deleting {}", name);
+// let res = tokio::fs::remove_file(format!("files/{}", name))
+// .await
+// .map_err(|err| Arc::new(err));
+// tracing::debug!("file delete res: {:?}", res);
+// res
+// }
+// }
-#[tokio::main]
-async fn main() {
- tracing_subscriber::fmt::init();
- let db = Db::create_connect_and_migrate(Path::new("./filamento.db"))
- .await
- .unwrap();
- let (client, mut recv) = Client::new(
- "test@blos.sm/testing2".try_into().unwrap(),
- "slayed".to_string(),
- db,
- Files,
- );
+// #[tokio::main]
+// async fn main() {
+// tracing_subscriber::fmt::init();
+// let db = Db::create_connect_and_migrate(Path::new("./filamento.db"))
+// .await
+// .unwrap();
+// let (client, mut recv) = Client::new(
+// "test@blos.sm/testing2".try_into().unwrap(),
+// "slayed".to_string(),
+// db,
+// Files,
+// );
- tokio::spawn(async move {
- while let Some(msg) = recv.recv().await {
- info!("{:#?}", msg)
- }
- });
+// 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!("changing nick");
- client
- .change_nick(Some("britney".to_string()))
- .await
- .unwrap();
- let mut profile_pic = tokio::fs::File::open("files/britney_starbies.jpg")
- .await
- .unwrap();
- let mut data = Vec::new();
- profile_pic.read_to_end(&mut data).await.unwrap();
- client.change_avatar(Some(data)).await.unwrap();
- info!("sending message");
- client
- .send_message(
- JID::from_str("cel@blos.sm").unwrap(),
- filamento::chat::Body {
- body: "hallo!!!".to_string(),
- },
- )
- .await
- .unwrap();
- info!("sent message");
- client
- .send_message(
- JID::from_str("cel@blos.sm").unwrap(),
- filamento::chat::Body {
- body: "hallo 2".to_string(),
- },
- )
- .await
- .unwrap();
- tokio::time::sleep(Duration::from_secs(15)).await;
- // info!("sending disco query");
- // let info = client.disco_info(None, None).await.unwrap();
- // info!("got disco result: {:#?}", info);
- // let items = client.disco_items(None, None).await.unwrap();
- // info!("got disco result: {:#?}", items);
- // let info = client
- // .disco_info(Some("blos.sm".parse().unwrap()), None)
- // .await
- // .unwrap();
- // info!("got disco result: {:#?}", info);
- // let items = client
- // .disco_items(Some("blos.sm".parse().unwrap()), None)
- // .await
- // .unwrap();
- // info!("got disco result: {:#?}", items);
- // let info = client
- // .disco_info(Some("pubsub.blos.sm".parse().unwrap()), None)
- // .await
- // .unwrap();
- // info!("got disco result: {:#?}", info);
- // let items = client
- // .disco_items(Some("pubsub.blos.sm".parse().unwrap()), None)
- // .await
- // .unwrap();
- // info!("got disco result: {:#?}", items);
-}
+// client.connect().await.unwrap();
+// tokio::time::sleep(Duration::from_secs(5)).await;
+// info!("changing nick");
+// client
+// .change_nick(Some("britney".to_string()))
+// .await
+// .unwrap();
+// let mut profile_pic = tokio::fs::File::open("files/britney_starbies.jpg")
+// .await
+// .unwrap();
+// let mut data = Vec::new();
+// profile_pic.read_to_end(&mut data).await.unwrap();
+// client.change_avatar(Some(data)).await.unwrap();
+// info!("sending message");
+// client
+// .send_message(
+// JID::from_str("cel@blos.sm").unwrap(),
+// filamento::chat::Body {
+// body: "hallo!!!".to_string(),
+// },
+// )
+// .await
+// .unwrap();
+// info!("sent message");
+// client
+// .send_message(
+// JID::from_str("cel@blos.sm").unwrap(),
+// filamento::chat::Body {
+// body: "hallo 2".to_string(),
+// },
+// )
+// .await
+// .unwrap();
+// tokio::time::sleep(Duration::from_secs(15)).await;
+// // info!("sending disco query");
+// // let info = client.disco_info(None, None).await.unwrap();
+// // info!("got disco result: {:#?}", info);
+// // let items = client.disco_items(None, None).await.unwrap();
+// // info!("got disco result: {:#?}", items);
+// // let info = client
+// // .disco_info(Some("blos.sm".parse().unwrap()), None)
+// // .await
+// // .unwrap();
+// // info!("got disco result: {:#?}", info);
+// // let items = client
+// // .disco_items(Some("blos.sm".parse().unwrap()), None)
+// // .await
+// // .unwrap();
+// // info!("got disco result: {:#?}", items);
+// // let info = client
+// // .disco_info(Some("pubsub.blos.sm".parse().unwrap()), None)
+// // .await
+// // .unwrap();
+// // info!("got disco result: {:#?}", info);
+// // let items = client
+// // .disco_items(Some("pubsub.blos.sm".parse().unwrap()), None)
+// // .await
+// // .unwrap();
+// // info!("got disco result: {:#?}", items);
+// }
+
+fn main() {}