diff options
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() { |