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());
}
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());
}
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;
}
Aggregations