fix feature discovery in jingle file transfer for empty resources
This commit is contained in:
		
							parent
							
								
									fda9e7b51c
								
							
						
					
					
						commit
						400c8461fc
					
				@ -6,6 +6,8 @@ import android.graphics.Color;
 | 
				
			|||||||
import android.text.SpannableStringBuilder;
 | 
					import android.text.SpannableStringBuilder;
 | 
				
			||||||
import android.util.Log;
 | 
					import android.util.Log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.common.base.Strings;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.json.JSONException;
 | 
					import org.json.JSONException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.lang.ref.WeakReference;
 | 
					import java.lang.ref.WeakReference;
 | 
				
			||||||
@ -21,6 +23,7 @@ import java.util.Set;
 | 
				
			|||||||
import eu.siacs.conversations.Config;
 | 
					import eu.siacs.conversations.Config;
 | 
				
			||||||
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
 | 
					import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
 | 
				
			||||||
import eu.siacs.conversations.services.AvatarService;
 | 
					import eu.siacs.conversations.services.AvatarService;
 | 
				
			||||||
 | 
					import eu.siacs.conversations.ui.util.PresenceSelector;
 | 
				
			||||||
import eu.siacs.conversations.utils.CryptoHelper;
 | 
					import eu.siacs.conversations.utils.CryptoHelper;
 | 
				
			||||||
import eu.siacs.conversations.utils.Emoticons;
 | 
					import eu.siacs.conversations.utils.Emoticons;
 | 
				
			||||||
import eu.siacs.conversations.utils.GeoHelper;
 | 
					import eu.siacs.conversations.utils.GeoHelper;
 | 
				
			||||||
@ -745,19 +748,12 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public boolean fixCounterpart() {
 | 
						public boolean fixCounterpart() {
 | 
				
			||||||
		Presences presences = conversation.getContact().getPresences();
 | 
							final Presences presences = conversation.getContact().getPresences();
 | 
				
			||||||
		if (counterpart != null && presences.has(counterpart.getResource())) {
 | 
							if (counterpart != null && presences.has(Strings.nullToEmpty(counterpart.getResource()))) {
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
		} else if (presences.size() >= 1) {
 | 
							} else if (presences.size() >= 1) {
 | 
				
			||||||
			try {
 | 
								counterpart = PresenceSelector.getNextCounterpart(getContact(),presences.toResourceArray()[0]);
 | 
				
			||||||
				counterpart = Jid.of(conversation.getJid().getLocal(),
 | 
					 | 
				
			||||||
						conversation.getJid().getDomain(),
 | 
					 | 
				
			||||||
						presences.toResourceArray()[0]);
 | 
					 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
			} catch (IllegalArgumentException e) {
 | 
					 | 
				
			||||||
				counterpart = null;
 | 
					 | 
				
			||||||
				return false;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			counterpart = null;
 | 
								counterpart = null;
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
 | 
				
			|||||||
@ -112,12 +112,15 @@ public class PresenceSelector {
 | 
				
			|||||||
        builder.create().show();
 | 
					        builder.create().show();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static Jid getNextCounterpart(final Contact contact, final String resource) {
 | 
					    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()) {
 | 
					        if (resource.isEmpty()) {
 | 
				
			||||||
            return contact.getJid().asBareJid();
 | 
					            return jid.asBareJid();
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            return contact.getJid().withResource(resource);
 | 
					            return jid.withResource(resource);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@ import android.util.Base64;
 | 
				
			|||||||
import android.util.Log;
 | 
					import android.util.Log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.common.base.Preconditions;
 | 
					import com.google.common.base.Preconditions;
 | 
				
			||||||
 | 
					import com.google.common.base.Strings;
 | 
				
			||||||
import com.google.common.collect.Collections2;
 | 
					import com.google.common.collect.Collections2;
 | 
				
			||||||
import com.google.common.collect.FluentIterable;
 | 
					import com.google.common.collect.FluentIterable;
 | 
				
			||||||
import com.google.common.collect.Iterables;
 | 
					import com.google.common.collect.Iterables;
 | 
				
			||||||
@ -416,15 +417,10 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private List<String> getRemoteFeatures() {
 | 
					    private List<String> getRemoteFeatures() {
 | 
				
			||||||
        final Jid jid = this.id.with;
 | 
					        final String resource = Strings.nullToEmpty(this.id.with.getResource());
 | 
				
			||||||
        String resource = jid != null ? jid.getResource() : null;
 | 
					        final Presence presence = this.id.account.getRoster().getContact(id.with).getPresences().get(resource);
 | 
				
			||||||
        if (resource != null) {
 | 
					        final ServiceDiscoveryResult result = presence != null ? presence.getServiceDiscoveryResult() : 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();
 | 
					        return result == null ? Collections.emptyList() : result.getFeatures();
 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            return Collections.emptyList();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void init(JinglePacket packet) { //should move to deliverPacket
 | 
					    private void init(JinglePacket packet) { //should move to deliverPacket
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user