Search in sources :

Example 1 with MamManager

use of org.jivesoftware.smackx.mam.MamManager in project Smack by igniterealtime.

the class OmemoMamDecryptionTest method mamDecryptionTest.

@SmackIntegrationTest
public void mamDecryptionTest() throws XMPPException.XMPPErrorException, SmackException.NotLoggedInException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, CryptoFailedException, UndecidedOmemoIdentityException, IOException {
    // 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);
    XMPPConnection alicesConnection = alice.getConnection();
    MessageBuilder messageBuilder = alicesConnection.getStanzaFactory().buildMessageStanza();
    alicesConnection.sendStanza(encrypted.buildMessage(messageBuilder, 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());
}
Also used : MamManager(org.jivesoftware.smackx.mam.MamManager) MessageOrOmemoMessage(org.jivesoftware.smackx.omemo.util.MessageOrOmemoMessage) MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) MessageOrOmemoMessage(org.jivesoftware.smackx.omemo.util.MessageOrOmemoMessage) XMPPConnection(org.jivesoftware.smack.XMPPConnection) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 2 with MamManager

use of org.jivesoftware.smackx.mam.MamManager in project xabber-android by redsolution.

the class NextMamManager method updateIsSupported.

private void updateIsSupported(AccountItem accountItem) {
    MamManager mamManager = MamManager.getInstanceFor(accountItem.getConnection());
    boolean isSupported;
    try {
        isSupported = mamManager.isSupportedByServer();
    } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException | ClassCastException e) {
        LogManager.exception(this, e);
        isSupported = false;
    }
    supportedByAccount.put(accountItem.getAccount(), isSupported);
    AccountManager.getInstance().onAccountChanged(accountItem.getAccount());
}
Also used : MamManager(org.jivesoftware.smackx.mam.MamManager)

Example 3 with MamManager

use of org.jivesoftware.smackx.mam.MamManager in project xabber-android by redsolution.

the class NextMamManager method requestToMessageArchive.

/**
 * T extends MamManager.MamQueryResult or T extends MamManager.MamPrefsResult
 */
private <T> T requestToMessageArchive(AccountItem accountItem, MamRequest<T> request) {
    T result = null;
    XMPPTCPConnection connection = accountItem.getConnection();
    if (connection.isAuthenticated()) {
        MamManager mamManager = MamManager.getInstanceFor(connection);
        try {
            result = request.execute(mamManager);
        } catch (Exception e) {
            LogManager.exception(this, e);
        }
    }
    return result;
}
Also used : MamManager(org.jivesoftware.smackx.mam.MamManager) XMPPTCPConnection(com.xabber.xmpp.smack.XMPPTCPConnection) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) IOException(java.io.IOException)

Aggregations

MamManager (org.jivesoftware.smackx.mam.MamManager)3 XMPPTCPConnection (com.xabber.xmpp.smack.XMPPTCPConnection)1 IOException (java.io.IOException)1 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1 MessageBuilder (org.jivesoftware.smack.packet.MessageBuilder)1 MessageOrOmemoMessage (org.jivesoftware.smackx.omemo.util.MessageOrOmemoMessage)1