aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/avatar_manager.vala
diff options
context:
space:
mode:
Diffstat (limited to 'libdino/src/service/avatar_manager.vala')
-rw-r--r--libdino/src/service/avatar_manager.vala35
1 files changed, 21 insertions, 14 deletions
diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala
index 9510389f..c9c078ab 100644
--- a/libdino/src/service/avatar_manager.vala
+++ b/libdino/src/service/avatar_manager.vala
@@ -53,6 +53,8 @@ public class AvatarManager : StreamInteractionModule, Object {
Pixbuf? image = yield avatar_storage.get_image(hash);
if (image != null) {
cached_pixbuf[hash] = image;
+ } else {
+ db.avatar.delete().with(db.avatar.hash, "=", hash).perform();
}
return image;
}
@@ -69,7 +71,12 @@ public class AvatarManager : StreamInteractionModule, Object {
}
public async Pixbuf? get_avatar(Account account, Jid jid) {
- string? hash = get_avatar_hash(account, jid);
+ Jid jid_ = jid;
+ if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
+ jid_ = jid.bare_jid;
+ }
+
+ string? hash = get_avatar_hash(account, jid_);
if (hash != null) {
return yield get_avatar_by_hash(hash);
}
@@ -77,15 +84,11 @@ public class AvatarManager : StreamInteractionModule, Object {
}
private string? get_avatar_hash(Account account, Jid jid) {
- Jid jid_ = jid;
- if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
- jid_ = jid.bare_jid;
- }
- string? user_avatars_id = user_avatars[jid_];
+ string? user_avatars_id = user_avatars[jid];
if (user_avatars_id != null) {
return user_avatars_id;
}
- string? vcard_avatars_id = vcard_avatars[jid_];
+ string? vcard_avatars_id = vcard_avatars[jid];
if (vcard_avatars_id != null) {
return vcard_avatars_id;
}
@@ -122,13 +125,17 @@ public class AvatarManager : StreamInteractionModule, Object {
on_vcard_avatar_received(account, jid, id)
);
- user_avatars = db.get_avatar_hashes(Source.USER_AVATARS);
- foreach (Jid jid in user_avatars.keys) {
- on_user_avatar_received(account, jid, user_avatars[jid]);
+ foreach (var entry in db.get_avatar_hashes(Source.USER_AVATARS).entries) {
+ on_user_avatar_received(account, entry.key, entry.value);
}
- vcard_avatars = db.get_avatar_hashes(Source.VCARD);
- foreach (Jid jid in vcard_avatars.keys) {
- on_vcard_avatar_received(account, jid, vcard_avatars[jid]);
+ foreach (var entry in db.get_avatar_hashes(Source.VCARD).entries) {
+ // FIXME: remove. temporary to remove falsely saved avatars.
+ if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(entry.key, account)) {
+ db.avatar.delete().with(db.avatar.jid, "=", entry.key.to_string()).perform();
+ continue;
+ }
+
+ on_vcard_avatar_received(account, entry.key, entry.value);
}
}
@@ -148,7 +155,7 @@ public class AvatarManager : StreamInteractionModule, Object {
private void on_vcard_avatar_received(Account account, Jid jid, string id) {
if (!vcard_avatars.has_key(jid) || vcard_avatars[jid] != id) {
vcard_avatars[jid] = id;
- if (!jid.is_full()) { // don't save muc avatars
+ if (!jid.is_full()) { // don't save MUC occupant avatars
db.set_avatar_hash(jid, id, Source.VCARD);
}
}