From df3273a6fc4d4f1604f0d6b0f2509af0d973631d Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 18 May 2020 09:14:57 +0200 Subject: [PATCH] fix jid.withResource() for domain jids --- .../siacs/conversations/entities/Contact.java | 4 ++-- .../services/XmppConnectionService.java | 2 +- .../eu/siacs/conversations/utils/UIHelper.java | 2 +- .../siacs/conversations/xmpp/WrappedJid.java | 18 ++++++++++++------ .../conversations/xmpp/XmppConnection.java | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java index 9aedb27d4..d95dae80b 100644 --- a/src/main/java/eu/siacs/conversations/entities/Contact.java +++ b/src/main/java/eu/siacs/conversations/entities/Contact.java @@ -451,13 +451,13 @@ public class Contact implements ListItem, Blockable { @Override public boolean isDomainBlocked() { - return getAccount().isBlocked(Jid.ofDomain(this.getJid().getDomain())); + return getAccount().isBlocked(this.getJid().getDomain()); } @Override public Jid getBlockedJid() { if (isDomainBlocked()) { - return Jid.ofDomain(getJid().getDomain()); + return getJid().getDomain(); } else { return getJid(); } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 061fe7ec9..694a49bed 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2821,7 +2821,7 @@ public class XmppConnectionService extends Service { boolean changed = false; for (ListIterator iterator = cryptoTargets.listIterator(); iterator.hasNext(); ) { Jid jid = iterator.next(); - if (!members.contains(jid) && !members.contains(Jid.ofDomain(jid.getDomain()))) { + if (!members.contains(jid) && !members.contains(jid.getDomain())) { iterator.remove(); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": removed " + jid + " from crypto targets of " + conversation.getName()); changed = true; diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index 7b30f6cd0..238fd0875 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -520,7 +520,7 @@ public class UIHelper { return ((Conversation) conversation).getMucOptions().getSelf().getName(); } else { final Jid jid = conversation.getAccount().getJid(); - return jid.getLocal() != null ? jid.getLocal() : Jid.ofDomain(jid.getDomain()).toString(); + return jid.getLocal() != null ? jid.getLocal() : jid.getDomain().toString(); } } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/WrappedJid.java b/src/main/java/eu/siacs/conversations/xmpp/WrappedJid.java index 878b3c302..aeee5c6e4 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/WrappedJid.java +++ b/src/main/java/eu/siacs/conversations/xmpp/WrappedJid.java @@ -40,13 +40,19 @@ public class WrappedJid implements eu.siacs.conversations.xmpp.Jid { @Override public eu.siacs.conversations.xmpp.Jid withResource(CharSequence resource) { + final Localpart localpart = inner.getLocalpartOrNull(); try { - return new WrappedJid( - JidCreate.fullFrom( - inner.getLocalpartOrThrow(), - inner.getDomain(), - Resourcepart.from(resource.toString()) - )); + final Resourcepart resourcepart = Resourcepart.from(resource.toString()); + if (localpart == null) { + return new WrappedJid(JidCreate.domainFullFrom(inner.getDomain(),resourcepart)); + } else { + return new WrappedJid( + JidCreate.fullFrom( + localpart, + inner.getDomain(), + resourcepart + )); + } } catch (XmppStringprepException e) { throw new IllegalArgumentException(e); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 5f4481318..b7398749d 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1276,7 +1276,7 @@ public class XmppConnection implements Runnable { private void sendServiceDiscoveryItems(final Jid server) { mPendingServiceDiscoveries.incrementAndGet(); final IqPacket iq = new IqPacket(IqPacket.TYPE.GET); - iq.setTo(Jid.ofDomain(server.getDomain())); + iq.setTo(server.getDomain()); iq.query("http://jabber.org/protocol/disco#items"); this.sendIqPacket(iq, (account, packet) -> { if (packet.getType() == IqPacket.TYPE.RESULT) { @@ -1641,7 +1641,7 @@ public class XmppConnection implements Runnable { public Identity getServerIdentity() { synchronized (this.disco) { - ServiceDiscoveryResult result = disco.get(Jid.ofDomain(account.getJid().getDomain())); + ServiceDiscoveryResult result = disco.get(account.getJid().getDomain()); if (result == null) { return Identity.UNKNOWN; }