xmpp-rs: Use to_hex conversion from struct directly

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2019-10-23 15:03:30 +02:00
parent 6d1d441372
commit a1489a6428
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -12,7 +12,6 @@ use std::io::{self, Write};
use tokio_xmpp::Packet;
use xmpp_parsers::{
avatar::{Data, Metadata},
hashes::Hash,
iq::Iq,
ns,
pubsub::{
@ -23,15 +22,6 @@ use xmpp_parsers::{
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(
from: &Jid,
tx: &mut mpsc::UnboundedSender<Packet>,
@ -43,7 +33,7 @@ pub(crate) fn handle_metadata_pubsub_event(
if payload.is("metadata", ns::AVATAR_METADATA) {
let metadata = Metadata::try_from(payload).unwrap();
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()) {
Ok(metadata) => metadata.len(),
Err(_) => 0,