introduce 'PepManager' to unify what pubsub service we talk to
This commit is contained in:
parent
e2ea1f9437
commit
870393df8e
|
@ -11,6 +11,7 @@ import im.conversations.android.xmpp.manager.BookmarkManager;
|
|||
import im.conversations.android.xmpp.manager.CarbonsManager;
|
||||
import im.conversations.android.xmpp.manager.DiscoManager;
|
||||
import im.conversations.android.xmpp.manager.NickManager;
|
||||
import im.conversations.android.xmpp.manager.PepManager;
|
||||
import im.conversations.android.xmpp.manager.PresenceManager;
|
||||
import im.conversations.android.xmpp.manager.PubSubManager;
|
||||
import im.conversations.android.xmpp.manager.RosterManager;
|
||||
|
@ -29,6 +30,7 @@ public final class Managers {
|
|||
.put(CarbonsManager.class, new CarbonsManager(context, connection))
|
||||
.put(DiscoManager.class, new DiscoManager(context, connection))
|
||||
.put(NickManager.class, new NickManager(context, connection))
|
||||
.put(PepManager.class, new PepManager(context, connection))
|
||||
.put(PresenceManager.class, new PresenceManager(context, connection))
|
||||
.put(PubSubManager.class, new PubSubManager(context, connection))
|
||||
.put(RosterManager.class, new RosterManager(context, connection))
|
||||
|
|
|
@ -2298,6 +2298,10 @@ public class XmppConnection implements Runnable {
|
|||
return this.streamFeatures != null && this.streamFeatures.clientStateIndication();
|
||||
}
|
||||
|
||||
public Jid getBoundAddress() {
|
||||
return this.connectionAddress;
|
||||
}
|
||||
|
||||
private static class MyKeyManager implements X509KeyManager {
|
||||
|
||||
private final Context context;
|
||||
|
|
|
@ -194,7 +194,13 @@ public class AxolotlManager extends AbstractManager {
|
|||
}
|
||||
|
||||
private ListenableFuture<Void> publishDeviceId() {
|
||||
final var currentDeviceIdsFuture = fetchDeviceIds(getAccount().address);
|
||||
final var currentDeviceIdsFuture =
|
||||
Futures.transform(
|
||||
getManager(PepManager.class)
|
||||
.fetchMostRecentItem(
|
||||
Namespace.AXOLOTL_DEVICE_LIST, DeviceList.class),
|
||||
DeviceList::getDeviceIds,
|
||||
MoreExecutors.directExecutor());
|
||||
final ListenableFuture<Set<Integer>> currentDeviceIdsWithFallback =
|
||||
Futures.catching(
|
||||
currentDeviceIdsFuture,
|
||||
|
@ -226,12 +232,9 @@ public class AxolotlManager extends AbstractManager {
|
|||
private ListenableFuture<Void> publishDeviceIds(final Collection<Integer> deviceIds) {
|
||||
final var deviceList = new DeviceList();
|
||||
deviceList.setDeviceIds(deviceIds);
|
||||
return getManager(PubSubManager.class)
|
||||
return getManager(PepManager.class)
|
||||
.publishSingleton(
|
||||
getAccount().address,
|
||||
deviceList,
|
||||
Namespace.AXOLOTL_DEVICE_LIST,
|
||||
NodeConfiguration.OPEN);
|
||||
deviceList, Namespace.AXOLOTL_DEVICE_LIST, NodeConfiguration.OPEN);
|
||||
}
|
||||
|
||||
private ListenableFuture<Void> publishBundle() {
|
||||
|
@ -246,9 +249,8 @@ public class AxolotlManager extends AbstractManager {
|
|||
"%s:%d",
|
||||
Namespace.AXOLOTL_BUNDLES,
|
||||
signalProtocolStore.getLocalRegistrationId());
|
||||
return getManager(PubSubManager.class)
|
||||
.publishSingleton(
|
||||
getAccount().address, bundle, node, NodeConfiguration.OPEN);
|
||||
return getManager(PepManager.class)
|
||||
.publishSingleton(bundle, node, NodeConfiguration.OPEN);
|
||||
},
|
||||
MoreExecutors.directExecutor());
|
||||
}
|
||||
|
|
|
@ -30,8 +30,7 @@ public class BookmarkManager extends AbstractManager {
|
|||
}
|
||||
|
||||
public void fetch() {
|
||||
final var future =
|
||||
getManager(PubSubManager.class).fetchItems(getAccount().address, Conference.class);
|
||||
final var future = getManager(PepManager.class).fetchItems(Conference.class);
|
||||
Futures.addCallback(
|
||||
future,
|
||||
new FutureCallback<>() {
|
||||
|
@ -79,12 +78,8 @@ public class BookmarkManager extends AbstractManager {
|
|||
final var itemId = address.toEscapedString();
|
||||
final var conference = new Conference();
|
||||
return Futures.transform(
|
||||
getManager(PubSubManager.class)
|
||||
.publish(
|
||||
getAccount().address,
|
||||
conference,
|
||||
itemId,
|
||||
NodeConfiguration.WHITELIST_MAX_ITEMS),
|
||||
getManager(PepManager.class)
|
||||
.publish(conference, itemId, NodeConfiguration.WHITELIST_MAX_ITEMS),
|
||||
result -> null,
|
||||
MoreExecutors.directExecutor());
|
||||
}
|
||||
|
@ -92,8 +87,7 @@ public class BookmarkManager extends AbstractManager {
|
|||
public ListenableFuture<Void> retractBookmark(final Jid address) {
|
||||
final var itemId = address.toEscapedString();
|
||||
return Futures.transform(
|
||||
getManager(PubSubManager.class)
|
||||
.retract(getAccount().address, itemId, Namespace.BOOKMARKS2),
|
||||
getManager(PepManager.class).retract(itemId, Namespace.BOOKMARKS2),
|
||||
result -> null,
|
||||
MoreExecutors.directExecutor());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package im.conversations.android.xmpp.manager;
|
||||
|
||||
import android.content.Context;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import eu.siacs.conversations.xmpp.Jid;
|
||||
import im.conversations.android.xmpp.NodeConfiguration;
|
||||
import im.conversations.android.xmpp.XmppConnection;
|
||||
import im.conversations.android.xmpp.model.Extension;
|
||||
import im.conversations.android.xmpp.model.stanza.Iq;
|
||||
import java.util.Map;
|
||||
|
||||
public class PepManager extends AbstractManager {
|
||||
|
||||
public PepManager(Context context, XmppConnection connection) {
|
||||
super(context, connection);
|
||||
}
|
||||
|
||||
public <T extends Extension> ListenableFuture<Map<String, T>> fetchItems(final Class<T> clazz) {
|
||||
return pubSubManager().fetchItems(pepService(), clazz);
|
||||
}
|
||||
|
||||
public <T extends Extension> ListenableFuture<T> fetchMostRecentItem(
|
||||
final String node, final Class<T> clazz) {
|
||||
return pubSubManager().fetchMostRecentItem(pepService(), node, clazz);
|
||||
}
|
||||
|
||||
public ListenableFuture<Void> publish(
|
||||
Extension item, final String itemId, final NodeConfiguration nodeConfiguration) {
|
||||
return pubSubManager().publish(pepService(), item, itemId, nodeConfiguration);
|
||||
}
|
||||
|
||||
public ListenableFuture<Void> publishSingleton(
|
||||
Extension item, final String node, final NodeConfiguration nodeConfiguration) {
|
||||
return pubSubManager().publishSingleton(pepService(), item, node, nodeConfiguration);
|
||||
}
|
||||
|
||||
public ListenableFuture<Iq> retract(final String itemId, final String node) {
|
||||
return pubSubManager().retract(pepService(), itemId, node);
|
||||
}
|
||||
|
||||
private PubSubManager pubSubManager() {
|
||||
return getManager(PubSubManager.class);
|
||||
}
|
||||
|
||||
private Jid pepService() {
|
||||
return connection.getBoundAddress().asBareJid();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue