convert empty resources in messages to bare jid

This commit is contained in:
Daniel Gultsch 2018-04-28 21:30:30 +02:00
parent 04f34fb968
commit effeb7b585
2 changed files with 12 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import java.util.Locale;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.utils.XmlHelper;
import eu.siacs.conversations.xmpp.InvalidJid;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
import rocks.xmpp.addr.Jid;
public class Element {
@ -154,7 +155,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;

View file

@ -37,9 +37,18 @@ 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