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")
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;

View file

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

View file

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

View file

@ -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<J
getManager(RosterManager.class).fetch();
// TODO check feature before fetching
if (getManager(DiscoManager.class)
.hasFeature(account.address.getDomain(), Namespace.BLOCKING)) {
getManager(BlockingManager.class).fetch();
}
getManager(BookmarkManager.class).fetch();