mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
Add a PEP PubSubManager to PEPManager
This commit is contained in:
parent
5569782113
commit
4b3f757ed9
7 changed files with 72 additions and 39 deletions
|
@ -89,6 +89,8 @@ public final class PEPManager extends Manager {
|
|||
|
||||
private final AsyncButOrdered<EntityBareJid> asyncButOrdered = new AsyncButOrdered<>();
|
||||
|
||||
private final PubSubManager pepPubSubManager;
|
||||
|
||||
/**
|
||||
* Creates a new PEP exchange manager.
|
||||
*
|
||||
|
@ -116,6 +118,12 @@ public final class PEPManager extends Manager {
|
|||
};
|
||||
// TODO Add filter to check if from supports PubSub as per xep163 2 2.4
|
||||
connection.addSyncStanzaListener(packetListener, FROM_BARE_JID_WITH_EVENT_EXTENSION_FILTER);
|
||||
|
||||
pepPubSubManager = PubSubManager.getInstance(connection, null);
|
||||
}
|
||||
|
||||
public PubSubManager getPepPubSubManager() {
|
||||
return pepPubSubManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -114,23 +114,36 @@ public final class PubSubManager extends Manager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the PubSub manager for the given connection and PubSub service.
|
||||
* Get the PubSub manager for the given connection and PubSub service. Use <code>null</code> as argument for
|
||||
* pubSubService to retrieve a PubSubManager for the users PEP service.
|
||||
*
|
||||
* @param connection the XMPP connection.
|
||||
* @param pubSubService the PubSub service.
|
||||
* @param pubSubService the PubSub service, may be <code>null</code>.
|
||||
* @return a PubSub manager for the connection and service.
|
||||
*/
|
||||
public static synchronized PubSubManager getInstance(XMPPConnection connection, BareJid pubSubService) {
|
||||
Map<BareJid, PubSubManager> managers = INSTANCES.get(connection);
|
||||
if (managers == null) {
|
||||
managers = new HashMap<>();
|
||||
INSTANCES.put(connection, managers);
|
||||
public static PubSubManager getInstance(XMPPConnection connection, BareJid pubSubService) {
|
||||
if (pubSubService != null && connection.isAuthenticated() && connection.getUser().asBareJid().equals(pubSubService)) {
|
||||
// PEP service.
|
||||
pubSubService = null;
|
||||
}
|
||||
PubSubManager pubSubManager = managers.get(pubSubService);
|
||||
if (pubSubManager == null) {
|
||||
pubSubManager = new PubSubManager(connection, pubSubService);
|
||||
managers.put(pubSubService, pubSubManager);
|
||||
|
||||
PubSubManager pubSubManager;
|
||||
Map<BareJid, PubSubManager> managers;
|
||||
synchronized (INSTANCES) {
|
||||
managers = INSTANCES.get(connection);
|
||||
if (managers == null) {
|
||||
managers = new HashMap<>();
|
||||
INSTANCES.put(connection, managers);
|
||||
}
|
||||
}
|
||||
synchronized (managers) {
|
||||
pubSubManager = managers.get(pubSubService);
|
||||
if (pubSubManager == null) {
|
||||
pubSubManager = new PubSubManager(connection, pubSubService);
|
||||
managers.put(pubSubService, pubSubManager);
|
||||
}
|
||||
}
|
||||
|
||||
return pubSubManager;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue