From f1bbb065ec63053b1e0dd0c78ba11376cbab451d Mon Sep 17 00:00:00 2001 From: Marvin W Date: Mon, 6 Oct 2025 20:12:19 +0200 Subject: Files: Use GFile instead of uri/path strings In some situations (like VFS or other abstractions), the file reference can have an invalid or unusabe path. Passing the GFile instead and opening it directly increases probability we can actually access it. --- libdino/src/service/avatar_manager.vala | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'libdino/src') diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala index 927b108d..0c98a8f3 100644 --- a/libdino/src/service/avatar_manager.vala +++ b/libdino/src/service/avatar_manager.vala @@ -106,9 +106,12 @@ public class AvatarManager : StreamInteractionModule, Object { return get_avatar_hash(account, jid) != null; } - public void publish(Account account, string file) { + public void publish(Account account, File file) { + debug("Publish avatar from %s", file.get_uri()); + FileInputStream file_stream = null; try { - Pixbuf pixbuf = new Pixbuf.from_file(file); + file_stream = file.read(); + Pixbuf pixbuf = new Pixbuf.from_stream(file_stream); if (pixbuf.width >= pixbuf.height && pixbuf.width > MAX_PIXEL) { int dest_height = (int) ((float) MAX_PIXEL / pixbuf.width * pixbuf.height); pixbuf = pixbuf.scale_simple(MAX_PIXEL, dest_height, InterpType.BILINEAR); @@ -121,9 +124,18 @@ public class AvatarManager : StreamInteractionModule, Object { XmppStream stream = stream_interactor.get_stream(account); if (stream != null) { Xmpp.Xep.UserAvatars.publish_png(stream, buffer, pixbuf.width, pixbuf.height); + debug("Publishing %u png bytes via user-avatars.", buffer.length); + } else { + warning("No stream when trying to publish."); } } catch (Error e) { warning(e.message); + } finally { + try { + if (file_stream != null) file_stream.close(); + } catch (Error e) { + // Ignore + } } } @@ -257,6 +269,7 @@ public class AvatarManager : StreamInteractionModule, Object { DataOutputStream fos = new DataOutputStream(file.create(FileCreateFlags.REPLACE_DESTINATION)); yield fos.write_bytes_async(data); } catch (Error e) { + warning("Error writing avatar file: %s", e.message); // Ignore: we failed in storing, so we refuse to display later... } } -- cgit v1.3