fix feature discovery in jingle file transfer for empty resources

This commit is contained in:
Daniel Gultsch 2020-06-13 22:53:24 +02:00
parent fda9e7b51c
commit 400c8461fc
3 changed files with 18 additions and 23 deletions

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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<String> 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