diff --git a/src/main/java/im/conversations/android/database/dao/DiscoDao.java b/src/main/java/im/conversations/android/database/dao/DiscoDao.java index 1c17e6b05..9bc08b268 100644 --- a/src/main/java/im/conversations/android/database/dao/DiscoDao.java +++ b/src/main/java/im/conversations/android/database/dao/DiscoDao.java @@ -126,6 +126,12 @@ public abstract class DiscoDao { @Query("SELECT id FROM disco WHERE accountId=:accountId AND capsHash=:capsHash") protected abstract Long getDiscoIdByCapsHash(final long accountId, final byte[] capsHash); + @Query( + "SELECT EXISTS (SELECT disco_item.id FROM disco_item JOIN disco_feature on" + + " disco_item.discoId=disco_feature.discoId WHERE accountId=:account AND" + + " address=:entity AND feature=:feature)") + public abstract boolean hasFeature(final long account, final Jid entity, final String feature); + public static class DiscoItemWithParent { public long accountId; public Jid address; diff --git a/src/main/java/im/conversations/android/xmpp/XmppConnection.java b/src/main/java/im/conversations/android/xmpp/XmppConnection.java index 52add3b6e..79e2d58df 100644 --- a/src/main/java/im/conversations/android/xmpp/XmppConnection.java +++ b/src/main/java/im/conversations/android/xmpp/XmppConnection.java @@ -1986,7 +1986,7 @@ public class XmppConnection implements Runnable { private void enableAdvancedStreamFeatures() { if (getManager(DiscoManager.class) - .isFeature(connectionAddress.getDomain(), Namespace.CARBONS) + .hasFeature(connectionAddress.getDomain(), Namespace.CARBONS) && !this.carbonsEnabled) { sendEnableCarbons(); } diff --git a/src/main/java/im/conversations/android/xmpp/manager/DiscoManager.java b/src/main/java/im/conversations/android/xmpp/manager/DiscoManager.java index 43b4ab148..38cb1043d 100644 --- a/src/main/java/im/conversations/android/xmpp/manager/DiscoManager.java +++ b/src/main/java/im/conversations/android/xmpp/manager/DiscoManager.java @@ -102,7 +102,7 @@ public class DiscoManager extends AbstractManager { MoreExecutors.directExecutor()); } - public boolean isFeature(final Jid entity, final String feature) { - return true; + public boolean hasFeature(final Jid entity, final String feature) { + return getDatabase().discoDao().hasFeature(getAccount().id, entity, feature); } } diff --git a/src/main/java/im/conversations/android/xmpp/processor/BindProcessor.java b/src/main/java/im/conversations/android/xmpp/processor/BindProcessor.java index d719ee48f..89fd121f8 100644 --- a/src/main/java/im/conversations/android/xmpp/processor/BindProcessor.java +++ b/src/main/java/im/conversations/android/xmpp/processor/BindProcessor.java @@ -1,10 +1,12 @@ package im.conversations.android.xmpp.processor; import android.content.Context; +import eu.siacs.conversations.xml.Namespace; import eu.siacs.conversations.xmpp.Jid; import im.conversations.android.xmpp.XmppConnection; import im.conversations.android.xmpp.manager.BlockingManager; import im.conversations.android.xmpp.manager.BookmarkManager; +import im.conversations.android.xmpp.manager.DiscoManager; import im.conversations.android.xmpp.manager.RosterManager; import java.util.function.Consumer; @@ -31,8 +33,10 @@ public class BindProcessor extends XmppConnection.Delegate implements Consumer