diff options
author | Marvin W <git@larma.de> | 2017-03-24 10:40:48 +0100 |
---|---|---|
committer | Marvin W <git@larma.de> | 2017-03-24 15:18:39 +0100 |
commit | b63e5f5f9fc0fcd85adf2f93f65d61abd4cc0681 (patch) | |
tree | 20543c6e78d28df345304c7d595383338c7676ce /libdino/src/service/avatar_manager.vala | |
parent | c0314212a0d951494fe6397fa53a9c5689a3ff87 (diff) | |
download | dino-b63e5f5f9fc0fcd85adf2f93f65d61abd4cc0681.tar.gz dino-b63e5f5f9fc0fcd85adf2f93f65d61abd4cc0681.zip |
Some caching and fix gpgme on some systems
Diffstat (limited to 'libdino/src/service/avatar_manager.vala')
-rw-r--r-- | libdino/src/service/avatar_manager.vala | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala index 1c0a3b51..de3d86fb 100644 --- a/libdino/src/service/avatar_manager.vala +++ b/libdino/src/service/avatar_manager.vala @@ -22,6 +22,7 @@ public class AvatarManager : StreamInteractionModule, Object { private HashMap<Jid, string> user_avatars = new HashMap<Jid, string>(Jid.hash_func, Jid.equals_func); private HashMap<Jid, string> vcard_avatars = new HashMap<Jid, string>(Jid.hash_func, Jid.equals_func); private AvatarStorage avatar_storage = new AvatarStorage(get_storage_dir()); + private HashMap<string, Pixbuf> cached_pixbuf = new HashMap<string, Pixbuf>(); private const int MAX_PIXEL = 192; public static void start(StreamInteractor stream_interactor, Database db) { @@ -45,6 +46,17 @@ public class AvatarManager : StreamInteractionModule, Object { modules.add(new Xep.VCard.Module(avatar_storage)); } + private Pixbuf? get_avatar_by_hash(string hash) { + if (cached_pixbuf.has_key(hash)) { + return cached_pixbuf[hash]; + } + Pixbuf? image = avatar_storage.get_image(hash); + if (image != null) { + cached_pixbuf[hash] = image; + } + return image; + } + public Pixbuf? get_avatar(Account account, Jid jid) { Jid jid_ = jid; if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) { @@ -52,11 +64,11 @@ public class AvatarManager : StreamInteractionModule, Object { } string? user_avatars_id = user_avatars[jid_]; if (user_avatars_id != null) { - return avatar_storage.get_image(user_avatars_id); + return get_avatar_by_hash(user_avatars_id); } string? vcard_avatars_id = vcard_avatars[jid_]; if (vcard_avatars_id != null) { - return avatar_storage.get_image(vcard_avatars_id); + return get_avatar_by_hash(vcard_avatars_id); } return null; } |