diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-12-18 21:23:01 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-12-18 21:23:01 +0100 |
commit | 08534f519d3b3da073ba73432c92e95accaafef9 (patch) | |
tree | 3b9c4a81c35d927c003161be463ba5cf6084e606 /src/main/java/de/pixart | |
parent | 05c5e2a5c320876ecad9ae5fda953ceeb5c590c0 (diff) |
support for jid escapting when displaying localpart only
Diffstat (limited to 'src/main/java/de/pixart')
3 files changed, 16 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Contact.java b/src/main/java/de/pixart/messenger/entities/Contact.java index 1124b19e1..02fe85eac 100644 --- a/src/main/java/de/pixart/messenger/entities/Contact.java +++ b/src/main/java/de/pixart/messenger/entities/Contact.java @@ -121,7 +121,7 @@ public class Contact implements ListItem, Blockable { } else if (this.presenceName != null && mutualPresenceSubscription()) { return this.presenceName; } else if (jid.hasLocalpart()) { - return jid.getLocalpart(); + return jid.getUnescapedLocalpart(); } else { return jid.getDomainpart(); } diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 36f5c46f6..63ff27ebf 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -463,7 +463,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl if (generatedName != null) { return generatedName; } else { - return getJid().getLocalpart(); + return getJid().getUnescapedLocalpart(); } } } else { diff --git a/src/main/java/de/pixart/messenger/xmpp/jid/Jid.java b/src/main/java/de/pixart/messenger/xmpp/jid/Jid.java index 123e6ee8f..af21019b8 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jid/Jid.java +++ b/src/main/java/de/pixart/messenger/xmpp/jid/Jid.java @@ -21,6 +21,8 @@ public final class Jid { private final String domainpart; private final String resourcepart; + private static final char[] JID_ESCAPING_CHARS = {' ','"','&','\'','/',':','<','>','@','\\'}; + // It's much more efficient to store the full JID as well as the parts instead of figuring them // all out every time (since some characters are displayed but aren't used for comparisons). private final String displayjid; @@ -29,6 +31,18 @@ public final class Jid { return localpart; } + public String getUnescapedLocalpart() { + if (localpart == null || !localpart.contains("\\")) { + return localpart; + } else { + String localpart = this.localpart; + for(char c : JID_ESCAPING_CHARS) { + localpart = localpart.replace(String.format ("\\%02x", (int)c),String.valueOf(c)); + } + return localpart; + } + } + public String getDomainpart() { return IDN.toUnicode(domainpart); } |