diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-05-02 20:52:10 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-05-02 20:52:10 +0200 |
commit | 787e2ad15a91ba208df71f15f8c964af04ecd2b8 (patch) | |
tree | 83b9a61462e89f17feb50711973fb6452aceaefc /src/main/java/de/pixart/messenger | |
parent | 7b4c05b7b45d159bf0168d2492708fd5314b335b (diff) |
convert empty resources in messages to bare jid
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r-- | src/main/java/de/pixart/messenger/xml/Element.java | 3 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/InvalidJid.java | 12 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/xml/Element.java b/src/main/java/de/pixart/messenger/xml/Element.java index d9eb626d3..f90efa555 100644 --- a/src/main/java/de/pixart/messenger/xml/Element.java +++ b/src/main/java/de/pixart/messenger/xml/Element.java @@ -10,6 +10,7 @@ import java.util.Locale; import de.pixart.messenger.utils.XmlHelper; import de.pixart.messenger.xmpp.InvalidJid; +import de.pixart.messenger.xmpp.stanzas.MessagePacket; import rocks.xmpp.addr.Jid; public class Element { @@ -152,7 +153,7 @@ public class Element { try { return Jid.ofEscaped(jid); } catch (final IllegalArgumentException e) { - return new InvalidJid(jid); + return InvalidJid.of(jid, this instanceof MessagePacket); } } return null; diff --git a/src/main/java/de/pixart/messenger/xmpp/InvalidJid.java b/src/main/java/de/pixart/messenger/xmpp/InvalidJid.java index fd4ca4b90..a22bd6cef 100644 --- a/src/main/java/de/pixart/messenger/xmpp/InvalidJid.java +++ b/src/main/java/de/pixart/messenger/xmpp/InvalidJid.java @@ -37,10 +37,20 @@ public class InvalidJid implements Jid { private final String value; - public InvalidJid(String jid) { + private InvalidJid(String jid) { this.value = jid; } + public static Jid of(String jid, boolean fallback) { + final int pos = jid.indexOf('/'); + if (fallback && pos >= 0 && jid.length() >= pos + 1) { + if (jid.substring(pos + 1).trim().isEmpty()) { + return Jid.ofEscaped(jid.substring(0, pos)); + } + } + return new InvalidJid(jid); + } + @Override @NonNull public String toString() { |