aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/avatar_manager.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2025-10-06 20:12:19 +0200
committerMarvin W <git@larma.de>2025-11-01 18:04:43 -0400
commitf1bbb065ec63053b1e0dd0c78ba11376cbab451d (patch)
treec8ba1ee43637b29f868e6d8ddd63714e6fb4618d /libdino/src/service/avatar_manager.vala
parent3c37cdbd1d2e5abbd0ab46a110b479432929b535 (diff)
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.
Diffstat (limited to 'libdino/src/service/avatar_manager.vala')
-rw-r--r--libdino/src/service/avatar_manager.vala17
1 files changed, 15 insertions, 2 deletions
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...
}
}