From e6a67a6c269f1454ee3632d0d1013735ece9910a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 23 Aug 2017 21:49:25 +0200 Subject: [PATCH] made avatar cache cleaning more efficent after name changes --- .../siacs/conversations/entities/Contact.java | 8 +++++--- .../conversations/parser/MessageParser.java | 17 ++++++++++------- .../conversations/parser/PresenceParser.java | 4 +++- .../eu/siacs/conversations/xml/Namespace.java | 1 + 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java index e182a9331..b9657a5bb 100644 --- a/src/main/java/eu/siacs/conversations/entities/Contact.java +++ b/src/main/java/eu/siacs/conversations/entities/Contact.java @@ -256,13 +256,15 @@ public class Contact implements ListItem, Blockable { } public boolean setSystemName(String systemName) { - String old = this.systemName; + final String old = getDisplayName(); this.systemName = systemName; - return (old == null && systemName != null) || (old != null && !old.equals(systemName)); + return !old.equals(getDisplayName()); } - public void setPresenceName(String presenceName) { + public boolean setPresenceName(String presenceName) { + final String old = getDisplayName(); this.presenceName = presenceName; + return !old.equals(getDisplayName()); } public Uri getSystemAccount() { diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 28cabc756..d501bb964 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -280,12 +280,13 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } } } else if ("http://jabber.org/protocol/nick".equals(node)) { - Element i = items.findChild("item"); - Element nick = i == null ? null : i.findChild("nick", "http://jabber.org/protocol/nick"); - if (nick != null && nick.getContent() != null) { + final Element i = items.findChild("item"); + final String nick = i == null ? null : i.findChildContent("nick", Namespace.NICK); + if (nick != null) { Contact contact = account.getRoster().getContact(from); - contact.setPresenceName(nick.getContent()); - mXmppConnectionService.getAvatarService().clear(account); + if (contact.setPresenceName(nick)) { + mXmppConnectionService.getAvatarService().clear(contact); + } mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateAccountUi(); } @@ -721,10 +722,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece parseEvent(event, original.getFrom(), account); } - String nick = packet.findChildContent("nick", "http://jabber.org/protocol/nick"); + final String nick = packet.findChildContent("nick", Namespace.NICK); if (nick != null) { Contact contact = account.getRoster().getContact(from); - contact.setPresenceName(nick); + if (contact.setPresenceName(nick)) { + mXmppConnectionService.getAvatarService().clear(contact); + } } } diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index 3c123e00f..72dffc4da 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -187,7 +187,9 @@ public class PresenceParser extends AbstractParser implements final Contact contact = account.getRoster().getContact(from); if (type == null) { final String resource = from.isBareJid() ? "" : from.getResourcepart(); - contact.setPresenceName(packet.findChildContent("nick", "http://jabber.org/protocol/nick")); + if (contact.setPresenceName(packet.findChildContent("nick", Namespace.NICK))) { + mXmppConnectionService.getAvatarService().clear(contact); + } Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update")); if (avatar != null && (!contact.isSelf() || account.getAvatar() == null)) { avatar.owner = from.toBareJid(); diff --git a/src/main/java/eu/siacs/conversations/xml/Namespace.java b/src/main/java/eu/siacs/conversations/xml/Namespace.java index f5cbf5747..f63b5f331 100644 --- a/src/main/java/eu/siacs/conversations/xml/Namespace.java +++ b/src/main/java/eu/siacs/conversations/xml/Namespace.java @@ -15,4 +15,5 @@ public final class Namespace { public static final String TLS = "urn:ietf:params:xml:ns:xmpp-tls"; public static final String PUBSUB_PUBLISH_OPTIONS = "http://jabber.org/protocol/pubsub#publish-options"; public static final String PUBSUB_ERROR = "http://jabber.org/protocol/pubsub#errors"; + public static final String NICK = "http://jabber.org/protocol/nick"; }