aboutsummaryrefslogtreecommitdiffstats
path: root/filamento
diff options
context:
space:
mode:
Diffstat (limited to 'filamento')
-rw-r--r--filamento/examples/example.rs10
-rw-r--r--filamento/src/lib.rs9
-rw-r--r--filamento/src/logic/online.rs7
3 files changed, 21 insertions, 5 deletions
diff --git a/filamento/examples/example.rs b/filamento/examples/example.rs
index d7c03e4..8119743 100644
--- a/filamento/examples/example.rs
+++ b/filamento/examples/example.rs
@@ -2,10 +2,10 @@ use std::{path::Path, str::FromStr, sync::Arc, time::Duration};
use filamento::{Client, db::Db, files::FileStore};
use jid::JID;
-use tokio::io;
+use tokio::io::{self, AsyncReadExt};
use tracing::info;
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub struct Files;
impl FileStore for Files {
@@ -65,6 +65,12 @@ async fn main() {
.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(
diff --git a/filamento/src/lib.rs b/filamento/src/lib.rs
index 42646be..7946241 100644
--- a/filamento/src/lib.rs
+++ b/filamento/src/lib.rs
@@ -191,6 +191,15 @@ pub struct Client<Fs: FileStore> {
timeout: Duration,
}
+impl<Fs: FileStore> Client<Fs> {
+ pub fn with_timeout(&self, timeout: Duration) -> Self {
+ Self {
+ sender: self.sender.clone(),
+ timeout,
+ }
+ }
+}
+
impl<Fs: FileStore> Clone for Client<Fs> {
fn clone(&self) -> Self {
Self {
diff --git a/filamento/src/logic/online.rs b/filamento/src/logic/online.rs
index 5b57f84..d9441d7 100644
--- a/filamento/src/logic/online.rs
+++ b/filamento/src/logic/online.rs
@@ -1,4 +1,4 @@
-use std::io::Cursor;
+use std::{io::Cursor, time::Duration};
use base64::{prelude::BASE64_STANDARD, Engine};
use chrono::Utc;
@@ -897,7 +897,8 @@ pub async fn handle_change_avatar<Fs: FileStore + Clone>(logic: &ClientLogic<Fs>
// convert the image to png;
let mut data_png = Vec::new();
- image.write_to(&mut Cursor::new(&mut data_png), image::ImageFormat::Png)?;
+ let image = image.resize(192, 192, image::imageops::FilterType::Nearest);
+ image.write_to(&mut Cursor::new(&mut data_png), image::ImageFormat::Jpeg)?;
// calculate the length of the data in bytes.
let bytes = data_png.len().try_into()?;
@@ -915,7 +916,7 @@ pub async fn handle_change_avatar<Fs: FileStore + Clone>(logic: &ClientLogic<Fs>
logic.client().publish(pep::Item::AvatarData(Some(avatar::Data { hash: hash.clone(), data_b64 })), "urn:xmpp:avatar:data".to_string()).await?;
// publish the metadata to the metadata node
- logic.client().publish(pep::Item::AvatarMetadata(Some(avatar::Metadata { bytes, hash: hash.clone(), r#type: "image/png".to_string() })), "urn:xmpp:avatar:metadata".to_string()).await?;
+ logic.client().publish(pep::Item::AvatarMetadata(Some(avatar::Metadata { bytes, hash: hash.clone(), r#type: "image/jpeg".to_string() })), "urn:xmpp:avatar:metadata".to_string()).await?;
// if everything went well, save the data to the disk.