check disco feature on entity

This commit is contained in:
Daniel Gultsch 2023-01-18 12:47:11 +01:00
parent 873644f528
commit 26bff8028a
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
4 changed files with 15 additions and 5 deletions

View file

@ -126,6 +126,12 @@ public abstract class DiscoDao {
@Query("SELECT id FROM disco WHERE accountId=:accountId AND capsHash=:capsHash") @Query("SELECT id FROM disco WHERE accountId=:accountId AND capsHash=:capsHash")
protected abstract Long getDiscoIdByCapsHash(final long accountId, final byte[] 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 static class DiscoItemWithParent {
public long accountId; public long accountId;
public Jid address; public Jid address;

View file

@ -1986,7 +1986,7 @@ public class XmppConnection implements Runnable {
private void enableAdvancedStreamFeatures() { private void enableAdvancedStreamFeatures() {
if (getManager(DiscoManager.class) if (getManager(DiscoManager.class)
.isFeature(connectionAddress.getDomain(), Namespace.CARBONS) .hasFeature(connectionAddress.getDomain(), Namespace.CARBONS)
&& !this.carbonsEnabled) { && !this.carbonsEnabled) {
sendEnableCarbons(); sendEnableCarbons();
} }

View file

@ -102,7 +102,7 @@ public class DiscoManager extends AbstractManager {
MoreExecutors.directExecutor()); MoreExecutors.directExecutor());
} }
public boolean isFeature(final Jid entity, final String feature) { public boolean hasFeature(final Jid entity, final String feature) {
return true; return getDatabase().discoDao().hasFeature(getAccount().id, entity, feature);
} }
} }

View file

@ -1,10 +1,12 @@
package im.conversations.android.xmpp.processor; package im.conversations.android.xmpp.processor;
import android.content.Context; import android.content.Context;
import eu.siacs.conversations.xml.Namespace;
import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.Jid;
import im.conversations.android.xmpp.XmppConnection; import im.conversations.android.xmpp.XmppConnection;
import im.conversations.android.xmpp.manager.BlockingManager; import im.conversations.android.xmpp.manager.BlockingManager;
import im.conversations.android.xmpp.manager.BookmarkManager; import im.conversations.android.xmpp.manager.BookmarkManager;
import im.conversations.android.xmpp.manager.DiscoManager;
import im.conversations.android.xmpp.manager.RosterManager; import im.conversations.android.xmpp.manager.RosterManager;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -31,8 +33,10 @@ public class BindProcessor extends XmppConnection.Delegate implements Consumer<J
getManager(RosterManager.class).fetch(); getManager(RosterManager.class).fetch();
// TODO check feature before fetching if (getManager(DiscoManager.class)
getManager(BlockingManager.class).fetch(); .hasFeature(account.address.getDomain(), Namespace.BLOCKING)) {
getManager(BlockingManager.class).fetch();
}
getManager(BookmarkManager.class).fetch(); getManager(BookmarkManager.class).fetch();