@Override public void connectionCreated(XMPPConnection connection) { getInstanceFor(connection); } });
/** * Get a MamManager for the MAM archive of the local entity (the "user") of the given connection. * * @param connection the XMPP connection to get the archive for. * @return the instance of MamManager. */ public static MamManager getInstanceFor(XMPPConnection connection) { return getInstanceFor(connection, (Jid) null); }
/** * Get a MamManager for the MAM archive of the given {@code MultiUserChat}. Note that not all MUCs support MAM, * hence it is recommended to use {@link #isSupported()} to check if MAM is supported by the MUC. * * @param multiUserChat the MultiUserChat to retrieve the MamManager for. * @return the MamManager for the given MultiUserChat. * @since 4.3.0 */ public static MamManager getInstanceFor(MultiUserChat multiUserChat) { XMPPConnection connection = multiUserChat.getXmppConnection(); Jid archiveAddress = multiUserChat.getRoom(); return getInstanceFor(connection, archiveAddress); }
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."); } }
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(); }
@Before public void setup() { // mock connection connection = new DummyConnection(); // test query id queryId = "testid"; // MamManager instance mamManager = MamManager.getInstanceFor(connection); }
@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()); } }
@Override public void connectionCreated(XMPPConnection connection) { getInstanceFor(connection); } });
/** * Get a MamManager for the MAM archive of the local entity (the "user") of the given connection. * * @param connection the XMPP connection to get the archive for. * @return the instance of MamManager. */ public static MamManager getInstanceFor(XMPPConnection connection) { return getInstanceFor(connection, (Jid) null); }
/** * Get a MamManager for the MAM archive of the given {@code MultiUserChat}. Note that not all MUCs support MAM, * hence it is recommended to use {@link #isSupported()} to check if MAM is supported by the MUC. * * @param multiUserChat the MultiUserChat to retrieve the MamManager for. * @return the MamManager for the given MultiUserChat. * @since 4.3.0 */ public static MamManager getInstanceFor(MultiUserChat multiUserChat) { XMPPConnection connection = multiUserChat.getXmppConnection(); Jid archiveAddress = multiUserChat.getRoom(); return getInstanceFor(connection, archiveAddress); }