xmpp-rs: Use to_hex conversion from struct directly
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
6d1d441372
commit
a1489a6428
1 changed files with 1 additions and 11 deletions
|
@ -12,7 +12,6 @@ use std::io::{self, Write};
|
||||||
use tokio_xmpp::Packet;
|
use tokio_xmpp::Packet;
|
||||||
use xmpp_parsers::{
|
use xmpp_parsers::{
|
||||||
avatar::{Data, Metadata},
|
avatar::{Data, Metadata},
|
||||||
hashes::Hash,
|
|
||||||
iq::Iq,
|
iq::Iq,
|
||||||
ns,
|
ns,
|
||||||
pubsub::{
|
pubsub::{
|
||||||
|
@ -23,15 +22,6 @@ use xmpp_parsers::{
|
||||||
Jid,
|
Jid,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Update xmpp-parsers to get this function for free on Hash.
|
|
||||||
fn hash_to_hex(hash: &Hash) -> String {
|
|
||||||
let mut bytes = vec![];
|
|
||||||
for byte in hash.hash.iter() {
|
|
||||||
bytes.push(format!("{:02x}", byte));
|
|
||||||
}
|
|
||||||
bytes.join("")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn handle_metadata_pubsub_event(
|
pub(crate) fn handle_metadata_pubsub_event(
|
||||||
from: &Jid,
|
from: &Jid,
|
||||||
tx: &mut mpsc::UnboundedSender<Packet>,
|
tx: &mut mpsc::UnboundedSender<Packet>,
|
||||||
|
@ -43,7 +33,7 @@ pub(crate) fn handle_metadata_pubsub_event(
|
||||||
if payload.is("metadata", ns::AVATAR_METADATA) {
|
if payload.is("metadata", ns::AVATAR_METADATA) {
|
||||||
let metadata = Metadata::try_from(payload).unwrap();
|
let metadata = Metadata::try_from(payload).unwrap();
|
||||||
for info in metadata.infos {
|
for info in metadata.infos {
|
||||||
let filename = format!("data/{}/{}", from, hash_to_hex(&*info.id));
|
let filename = format!("data/{}/{}", from, &*info.id.to_hex());
|
||||||
let file_length = match fs::metadata(filename.clone()) {
|
let file_length = match fs::metadata(filename.clone()) {
|
||||||
Ok(metadata) => metadata.len(),
|
Ok(metadata) => metadata.len(),
|
||||||
Err(_) => 0,
|
Err(_) => 0,
|
||||||
|
|
Loading…
Reference in a new issue