@Override public void connectionCreated(XMPPConnection connection) { getInstanceFor(connection); } });
public MamQuery queryArchive(MamQueryArgs mamQueryArgs) throws NoResponseException, XMPPErrorException, NotConnectedException, NotLoggedInException, InterruptedException { String queryId = UUID.randomUUID().toString(); String node = mamQueryArgs.node; DataForm dataForm = mamQueryArgs.getDataForm(); MamQueryIQ mamQueryIQ = new MamQueryIQ(queryId, node, dataForm); mamQueryIQ.setType(IQ.Type.set); mamQueryIQ.setTo(archiveAddress); mamQueryArgs.maybeAddRsmSet(mamQueryIQ); return queryArchive(mamQueryIQ); }
public MamPrefsResult enableMamForAllMessages() throws NoResponseException, XMPPErrorException, NotConnectedException, NotLoggedInException, InterruptedException { return setDefaultBehavior(DefaultBehavior.always); }
public MamIntegrationTest(SmackIntegrationTestEnvironment environment) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, TestNotPossibleException, NotLoggedInException { super(environment); mamManagerConTwo = MamManager.getInstanceFor(conTwo); if (!mamManagerConTwo.isSupported()) { throw new TestNotPossibleException("Message Archive Management (XEP-0313) is not supported by the server."); } // Make sure MAM is archiving messages. mamManagerConTwo.enableMamForAllMessages(); }
public OmemoMamDecryptionTest(SmackIntegrationTestEnvironment environment) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, TestNotPossibleException { super(environment); MamManager bobsMamManager = MamManager.getInstanceFor(conTwo); if (!bobsMamManager.isSupported()) { throw new TestNotPossibleException("Test is not possible, because MAM is not supported on the server."); } }
@SmackIntegrationTest public void mamDecryptionTest() throws XMPPException.XMPPErrorException, SmackException.NotLoggedInException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, CryptoFailedException, UndecidedOmemoIdentityException { // Make sure, Bobs server stores messages in the archive MamManager bobsMamManager = MamManager.getInstanceFor(bob.getConnection()); bobsMamManager.enableMamForAllMessages(); bobsMamManager.setDefaultBehavior(MamPrefsIQ.DefaultBehavior.always); // Prevent bob from automatically decrypting MAM messages. bob.stopStanzaAndPEPListeners(); String body = "This message will be stored in MAM!"; OmemoMessage.Sent encrypted = alice.encrypt(bob.getOwnJid(), body); alice.getConnection().sendStanza(encrypted.asMessage(bob.getOwnJid())); MamManager.MamQuery query = bobsMamManager.queryArchive(MamManager.MamQueryArgs.builder().limitResultsToJid(alice.getOwnJid()).build()); assertEquals(1, query.getMessageCount()); List<MessageOrOmemoMessage> decryptedMamQuery = bob.decryptMamQueryResult(query); assertEquals(1, decryptedMamQuery.size()); assertEquals(body, decryptedMamQuery.get(decryptedMamQuery.size() - 1).getOmemoMessage().getBody()); } }
/** * Update the preferences in the server. * * @param mamPrefs * @return the currently active preferences after the operation. * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException * @throws InterruptedException * @throws NotLoggedInException * @since 4.3.0 */ public MamPrefsResult updateArchivingPreferences(MamPrefs mamPrefs) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException { MamPrefsIQ mamPrefIQ = mamPrefs.constructMamPrefsIq(); return queryMamPrefs(mamPrefIQ); }
/** * The the XMPP address of this MAM archive. Note that this method may return {@code null} if this MamManager * handles the local entity's archive and if the connection has never been authenticated at least once. * * @return the XMPP address of this MAM archive or {@code null}. * @since 4.3.0 */ public Jid getArchiveAddress() { if (archiveAddress == null) { EntityFullJid localJid = connection().getUser(); if (localJid == null) { return null; } return localJid.asBareJid(); } return archiveAddress; }
final EntityBareJid userTwo = conTwo.getUser().asEntityBareJid(); final SimpleResultSyncPoint allMessagesReceived = new SimpleResultSyncPoint(); final String lastMessageArchiveUid = mamManagerConTwo.getMessageUidOfLatestMessage(); .build(); MamQuery mamQuery = mamManagerConTwo.queryArchive(mamQueryArgs);
private MamPrefsResult queryMamPrefs(MamPrefsIQ mamPrefsIQ) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException { final XMPPConnection connection = getAuthenticatedConnectionOrThrow(); MamPrefsIQ mamPrefsResultIQ = connection.createStanzaCollectorAndSend(mamPrefsIQ).nextResultOrThrow(); return new MamPrefsResult(mamPrefsResultIQ, DataForm.from(mamPrefsIQ)); }
private MamQuery queryArchive(MamQueryIQ mamQueryIq) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException { MamQueryPage mamQueryPage = queryArchivePage(mamQueryIq); return new MamQuery(mamQueryPage, mamQueryIq.getNode(), DataForm.from(mamQueryIq)); }
private static void addWithJid(Jid withJid, DataForm dataForm) { if (withJid == null) { return; } FormField formField = getWithFormField(withJid); dataForm.addField(formField); }
public static synchronized MamManager getInstanceFor(XMPPConnection connection, Jid archiveAddress) { Map<Jid, MamManager> managers = INSTANCES.get(connection); if (managers == null) { managers = new HashMap<>(); INSTANCES.put(connection, managers); } MamManager mamManager = managers.get(archiveAddress); if (mamManager == null) { mamManager = new MamManager(connection, archiveAddress); managers.put(archiveAddress, mamManager); } return mamManager; }
/** * Check if this MamManager's archive address supports MAM. * * @return true if MAM is supported, <code>false</code>otherwise. * * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException * @throws InterruptedException * @since 4.2.1 * @see <a href="https://xmpp.org/extensions/xep-0313.html#support">XEP-0313 § 7. Determining support</a> */ public boolean isSupported() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { // Note that this may return 'null' but SDM's supportsFeature() does the right thing™ then. Jid archiveAddress = getArchiveAddress(); return serviceDiscoveryManager.supportsFeature(archiveAddress, MamElements.NAMESPACE); }
/** * Get the preferences stored in the server. * * @return the MAM preferences result * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException * @throws InterruptedException * @throws NotLoggedInException */ public MamPrefsResult retrieveArchivingPreferences() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException { MamPrefsIQ mamPrefIQ = new MamPrefsIQ(); return queryMamPrefs(mamPrefIQ); }
/** * Get the form fields supported by the server. * * @param node The PubSub node name, can be null * @return the list of form fields. * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException * @throws InterruptedException * @throws NotLoggedInException */ public List<FormField> retrieveFormFields(String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException { String queryId = UUID.randomUUID().toString(); MamQueryIQ mamQueryIq = new MamQueryIQ(queryId, node, null); mamQueryIq.setTo(archiveAddress); MamQueryIQ mamResponseQueryIq = connection().createStanzaCollectorAndSend(mamQueryIq).nextResultOrThrow(); return mamResponseQueryIq.getDataForm().getFields(); }
private MamQueryPage queryArchivePage(MamQueryIQ mamQueryIq) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException { final XMPPConnection connection = getAuthenticatedConnectionOrThrow(); MamFinIQ mamFinIQ; StanzaCollector mamFinIQCollector = connection.createStanzaCollector(new IQReplyFilter(mamQueryIq, connection)); StanzaCollector.Configuration resultCollectorConfiguration = StanzaCollector.newConfiguration() .setStanzaFilter(new MamResultFilter(mamQueryIq)).setCollectorToReset(mamFinIQCollector); StanzaCollector resultCollector = connection.createStanzaCollector(resultCollectorConfiguration); try { connection.sendStanza(mamQueryIq); mamFinIQ = mamFinIQCollector.nextResultOrThrow(); } finally { mamFinIQCollector.cancel(); resultCollector.cancel(); } return new MamQueryPage(resultCollector, mamFinIQ); }
private MamQuery queryArchive(MamQueryIQ mamQueryIq) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException { MamQueryPage mamQueryPage = queryArchivePage(mamQueryIq); return new MamQuery(mamQueryPage, mamQueryIq.getNode(), DataForm.from(mamQueryIq)); }
private static void addWithJid(Jid withJid, DataForm dataForm) { if (withJid == null) { return; } FormField formField = getWithFormField(withJid); dataForm.addField(formField); }
public static synchronized MamManager getInstanceFor(XMPPConnection connection, Jid archiveAddress) { Map<Jid, MamManager> managers = INSTANCES.get(connection); if (managers == null) { managers = new HashMap<>(); INSTANCES.put(connection, managers); } MamManager mamManager = managers.get(archiveAddress); if (mamManager == null) { mamManager = new MamManager(connection, archiveAddress); managers.put(archiveAddress, mamManager); } return mamManager; }