diff options
author | 2025-04-08 12:16:55 +0100 | |
---|---|---|
committer | 2025-04-08 12:16:55 +0100 | |
commit | e518e899e53c072724254bd714db914cde7db5b2 (patch) | |
tree | b9a9d3c45e2b326adb6df9756678ef4050bb3589 /filamento | |
parent | 0b19cb38183929d3f242cfd11c34426d9302697c (diff) | |
download | luz-e518e899e53c072724254bd714db914cde7db5b2.tar.gz luz-e518e899e53c072724254bd714db914cde7db5b2.tar.bz2 luz-e518e899e53c072724254bd714db914cde7db5b2.zip |
fix(filamento): caps +notify and use hex representation for avatar metadata id
Diffstat (limited to '')
-rw-r--r-- | filamento.db | bin | 0 -> 118784 bytes | |||
-rw-r--r-- | filamento/Cargo.toml | 1 | ||||
-rw-r--r-- | filamento/examples/example.rs | 23 | ||||
-rw-r--r-- | filamento/src/caps.rs | 6 | ||||
-rw-r--r-- | filamento/src/logic/online.rs | 2 | ||||
-rw-r--r-- | filamento/src/logic/process_stanza.rs | 41 |
6 files changed, 46 insertions, 27 deletions
diff --git a/filamento.db b/filamento.db Binary files differnew file mode 100644 index 0000000..6e17d1c --- /dev/null +++ b/filamento.db diff --git a/filamento/Cargo.toml b/filamento/Cargo.toml index 92c8370..d1749f4 100644 --- a/filamento/Cargo.toml +++ b/filamento/Cargo.toml @@ -20,6 +20,7 @@ sha3 = "0.10.8" base64 = "0.22.1" sha1 = "0.10.6" image = "0.25.6" +hex = "0.4.3" [dev-dependencies] tracing-subscriber = "0.3.19" diff --git a/filamento/examples/example.rs b/filamento/examples/example.rs index 8ebfde0..d7c03e4 100644 --- a/filamento/examples/example.rs +++ b/filamento/examples/example.rs @@ -12,21 +12,30 @@ impl FileStore for Files { type Err = Arc<io::Error>; async fn is_stored(&self, name: &str) -> Result<bool, Self::Err> { - Ok(tokio::fs::try_exists(format!("files/{}", name)) + tracing::debug!("checking if {} is stored", name); + let res = tokio::fs::try_exists(format!("files/{}", name)) .await - .map_err(|err| Arc::new(err))?) + .map_err(|err| Arc::new(err)); + tracing::debug!("file check res: {:?}", res); + res } async fn store(&self, name: &str, data: &[u8]) -> Result<(), Self::Err> { - Ok(tokio::fs::write(format!("files/{}", name), data) + tracing::debug!("storing {} is stored", name); + let res = tokio::fs::write(format!("files/{}", name), data) .await - .map_err(|err| Arc::new(err))?) + .map_err(|err| Arc::new(err)); + tracing::debug!("file store res: {:?}", res); + res } async fn delete(&self, name: &str) -> Result<(), Self::Err> { - Ok(tokio::fs::remove_file(format!("files/{}", name)) + tracing::debug!("deleting {}", name); + let res = tokio::fs::remove_file(format!("files/{}", name)) .await - .map_err(|err| Arc::new(err))?) + .map_err(|err| Arc::new(err)); + tracing::debug!("file delete res: {:?}", res); + res } } @@ -37,7 +46,7 @@ async fn main() { .await .unwrap(); let (client, mut recv) = Client::new( - "test@blos.sm".try_into().unwrap(), + "test@blos.sm/testing2".try_into().unwrap(), "slayed".to_string(), db, Files, diff --git a/filamento/src/caps.rs b/filamento/src/caps.rs index b3464d1..819e669 100644 --- a/filamento/src/caps.rs +++ b/filamento/src/caps.rs @@ -35,13 +35,13 @@ pub fn client_info() -> Info { Info { node: None, features: vec![ - "http://jabber.org/protocol/disco#items".to_string(), - "http://jabber.org/protocol/disco#info".to_string(), "http://jabber.org/protocol/caps".to_string(), - "http://jabber.org/protocol/nick".to_string(), + "http://jabber.org/protocol/disco#info".to_string(), + "http://jabber.org/protocol/disco#items".to_string(), "http://jabber.org/protocol/nick+notify".to_string(), "urn:xmpp:avatar:metadata+notify".to_string(), ], + // "http://jabber.org/protocol/nick".to_string(), identities: vec![Identity { name: Some("filamento 0.1.0".to_string()), category: Category::Client(identity::Client::PC), diff --git a/filamento/src/logic/online.rs b/filamento/src/logic/online.rs index 745adc1..5b57f84 100644 --- a/filamento/src/logic/online.rs +++ b/filamento/src/logic/online.rs @@ -906,7 +906,7 @@ pub async fn handle_change_avatar<Fs: FileStore + Clone>(logic: &ClientLogic<Fs> let mut sha1 = Sha1::new(); sha1.update(&data_png); let sha1_result = sha1.finalize(); - let hash = BASE64_STANDARD.encode(sha1_result); + let hash = hex::encode(sha1_result); // encode the image data as base64 let data_b64 = BASE64_STANDARD.encode(data_png.clone()); diff --git a/filamento/src/logic/process_stanza.rs b/filamento/src/logic/process_stanza.rs index c383d70..7142144 100644 --- a/filamento/src/logic/process_stanza.rs +++ b/filamento/src/logic/process_stanza.rs @@ -268,14 +268,17 @@ pub async fn recv_message<Fs: FileStore + Clone>( match items.items { ItemsType::Item(items) => { if let Some(item) = items.first() { + debug!("found item"); match &item.item { Some(Content::AvatarMetadata(metadata)) => { + debug!("found metadata"); // check if user avatar has been deleted if let Some(metadata) = metadata .info .iter() .find(|info| info.url.is_none()) { + debug!("checking if user avatar has changed"); // check if user avatar has changed match logic .db() @@ -296,8 +299,9 @@ pub async fn recv_message<Fs: FileStore + Clone>( logic.handle_error(MessageRecvError::AvatarUpdate(e).into()).await; } } + } - match logic + match logic .file_store() .is_stored(&metadata.id) .await @@ -311,28 +315,32 @@ pub async fn recv_message<Fs: FileStore + Clone>( let pep_item = logic.client().get_pep_item(Some(from.as_bare()), "urn:xmpp:avatar:data".to_string(), metadata.id.clone()).await.map_err(|err| Into::<AvatarUpdateError<Fs>>::into(err))?; match pep_item { crate::pep::Item::AvatarData(data) => { - let data = data.map(|data| data.data_b64).unwrap_or_default(); + let data = data.map(|data| data.data_b64).unwrap_or_default().replace("\n", ""); // TODO: these should all be in a separate avatarupdate function + debug!("got avatar data"); match BASE64_STANDARD.decode(data) { Ok(data) => { let mut hasher = Sha1::new(); hasher.update(&data); - let received_data_hash = BASE64_STANDARD.encode(hasher.finalize()); - if received_data_hash == metadata.id { + let received_data_hash = hex::encode(hasher.finalize()); + debug!("received_data_hash: {}, metadata_id: {}", received_data_hash, metadata.id); + if received_data_hash.to_lowercase() == metadata.id.to_lowercase() { if let Err(e) = logic.file_store().store(&received_data_hash, &data).await { logic.handle_error(Error::MessageRecv(MessageRecvError::AvatarUpdate(AvatarUpdateError::FileStore(e)))).await; } - logic - .update_sender() - .send( - UpdateMessage::AvatarChanged { - jid: from.as_bare(), - id: Some( - metadata.id.clone(), - ), - }, - ) - .await; + if changed { + logic + .update_sender() + .send( + UpdateMessage::AvatarChanged { + jid: from.as_bare(), + id: Some( + metadata.id.clone(), + ), + }, + ) + .await; + } } }, Err(e) => { @@ -347,6 +355,7 @@ pub async fn recv_message<Fs: FileStore + Clone>( } Ok(true) => { // just send the update + if changed { logic .update_sender() .send( @@ -359,10 +368,10 @@ pub async fn recv_message<Fs: FileStore + Clone>( ) .await; } + } Err(e) => { logic.handle_error(Error::MessageRecv(MessageRecvError::AvatarUpdate(e))).await; } - } } } Err(e) => { |