From 400c8461fc1fb9a76a91b2ffffba9c533684534a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 13 Jun 2020 22:53:24 +0200 Subject: [PATCH] fix feature discovery in jingle file transfer for empty resources --- .../siacs/conversations/entities/Message.java | 18 +++++++----------- .../ui/util/PresenceSelector.java | 9 ++++++--- .../jingle/JingleFileTransferConnection.java | 14 +++++--------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index 4263a6ef8..44b8db691 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -6,6 +6,8 @@ import android.graphics.Color; import android.text.SpannableStringBuilder; import android.util.Log; +import com.google.common.base.Strings; + import org.json.JSONException; import java.lang.ref.WeakReference; @@ -21,6 +23,7 @@ import java.util.Set; import eu.siacs.conversations.Config; import eu.siacs.conversations.crypto.axolotl.FingerprintStatus; import eu.siacs.conversations.services.AvatarService; +import eu.siacs.conversations.ui.util.PresenceSelector; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.Emoticons; import eu.siacs.conversations.utils.GeoHelper; @@ -745,19 +748,12 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable } public boolean fixCounterpart() { - Presences presences = conversation.getContact().getPresences(); - if (counterpart != null && presences.has(counterpart.getResource())) { + final Presences presences = conversation.getContact().getPresences(); + if (counterpart != null && presences.has(Strings.nullToEmpty(counterpart.getResource()))) { return true; } else if (presences.size() >= 1) { - try { - counterpart = Jid.of(conversation.getJid().getLocal(), - conversation.getJid().getDomain(), - presences.toResourceArray()[0]); - return true; - } catch (IllegalArgumentException e) { - counterpart = null; - return false; - } + counterpart = PresenceSelector.getNextCounterpart(getContact(),presences.toResourceArray()[0]); + return true; } else { counterpart = null; return false; diff --git a/src/main/java/eu/siacs/conversations/ui/util/PresenceSelector.java b/src/main/java/eu/siacs/conversations/ui/util/PresenceSelector.java index 870fdc268..2f29e5b76 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/PresenceSelector.java +++ b/src/main/java/eu/siacs/conversations/ui/util/PresenceSelector.java @@ -112,12 +112,15 @@ public class PresenceSelector { builder.create().show(); } - public static Jid getNextCounterpart(final Contact contact, final String resource) { + return getNextCounterpart(contact.getJid(), resource); + } + + public static Jid getNextCounterpart(final Jid jid, final String resource) { if (resource.isEmpty()) { - return contact.getJid().asBareJid(); + return jid.asBareJid(); } else { - return contact.getJid().withResource(resource); + return jid.withResource(resource); } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java index 36948d48b..0cab56279 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java @@ -4,6 +4,7 @@ import android.util.Base64; import android.util.Log; import com.google.common.base.Preconditions; +import com.google.common.base.Strings; import com.google.common.collect.Collections2; import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; @@ -416,15 +417,10 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple } private List getRemoteFeatures() { - final Jid jid = this.id.with; - String resource = jid != null ? jid.getResource() : null; - if (resource != null) { - Presence presence = this.id.account.getRoster().getContact(jid).getPresences().get(resource); - ServiceDiscoveryResult result = presence != null ? presence.getServiceDiscoveryResult() : null; - return result == null ? Collections.emptyList() : result.getFeatures(); - } else { - return Collections.emptyList(); - } + final String resource = Strings.nullToEmpty(this.id.with.getResource()); + final Presence presence = this.id.account.getRoster().getContact(id.with).getPresences().get(resource); + final ServiceDiscoveryResult result = presence != null ? presence.getServiceDiscoveryResult() : null; + return result == null ? Collections.emptyList() : result.getFeatures(); } private void init(JinglePacket packet) { //should move to deliverPacket