From 6b81ff70e5b6f8f06d699f919d24b1ee1bd3b7d0 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 10 Feb 2017 20:26:21 +0100 Subject: [PATCH] clear avatar cache when system name changes --- .../java/eu/siacs/conversations/entities/Contact.java | 4 +++- .../conversations/services/XmppConnectionService.java | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java index b7307a8b..28c052b7 100644 --- a/src/main/java/eu/siacs/conversations/entities/Contact.java +++ b/src/main/java/eu/siacs/conversations/entities/Contact.java @@ -255,8 +255,10 @@ public class Contact implements ListItem, Blockable { this.serverName = serverName; } - public void setSystemName(String systemName) { + public boolean setSystemName(String systemName) { + String old = this.systemName; this.systemName = systemName; + return (old == null && systemName != null) || (old != null && !old.equals(systemName)); } public void setPresenceName(String presenceName) { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 0fce323d..93981f4a 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1518,16 +1518,18 @@ public class XmppConnectionService extends Service { + "#" + phoneContact.getString("lookup"); contact.setSystemAccount(systemAccount); - if (contact.setPhotoUri(phoneContact.getString("photouri"))) { + boolean needsCacheClean = contact.setPhotoUri(phoneContact.getString("photouri")); + needsCacheClean |= contact.setSystemName(phoneContact.getString("displayname")); + if (needsCacheClean) { getAvatarService().clear(contact); } - contact.setSystemName(phoneContact.getString("displayname")); withSystemAccounts.remove(contact); } for (Contact contact : withSystemAccounts) { contact.setSystemAccount(null); - contact.setSystemName(null); - if (contact.setPhotoUri(null)) { + boolean needsCacheClean = contact.setPhotoUri(null); + needsCacheClean |= contact.setSystemName(null); + if (needsCacheClean) { getAvatarService().clear(contact); } }