.limitResultsToJid(userOne) .afterUid(lastMessageArchiveUid) .build();
@Test public void checkEndDateFilter() throws Exception { Date date = new Date(); MamQueryArgs mamQueryArgs = MamQueryArgs.builder().limitResultsBefore(date).build(); DataForm dataForm = mamQueryArgs.getDataForm(); List<String> fields = new ArrayList<>(); fields.add("end"); List<String> values = new ArrayList<>(); values.add(XmppDateTime.formatXEP0082Date(date)); assertEquals(getMamXMemberWith(fields, values), dataForm.toXML(null).toString()); }
@Test public void checkStartDateFilter() throws Exception { Date date = new Date(); MamQueryArgs mamQueryArgs = MamQueryArgs.builder().limitResultsSince(date).build(); DataForm dataForm = mamQueryArgs.getDataForm(); List<String> fields = new ArrayList<>(); fields.add("start"); List<String> values = new ArrayList<>(); values.add(XmppDateTime.formatXEP0082Date(date)); assertEquals(getMamXMemberWith(fields, values), dataForm.toXML(null).toString()); }
.limitResultsToJid(withJid) .withAdditionalFormFields(additionalFields) .build();
/** * Lookup the archive's message ID of the latest message in the archive. Returns {@code null} if the archive is * empty. * * @return the ID of the lastest message or {@code null}. * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException * @throws NotLoggedInException * @throws InterruptedException * @since 4.3.0 */ public String getMessageUidOfLatestMessage() throws NoResponseException, XMPPErrorException, NotConnectedException, NotLoggedInException, InterruptedException { MamQueryArgs mamQueryArgs = MamQueryArgs.builder() .setResultPageSize(1) .queryLastPage() .build(); MamQuery mamQuery = queryArchive(mamQueryArgs); if (mamQuery.getMessages().isEmpty()) { return null; } return mamQuery.getMamResultExtensions().get(0).getId(); }
public MamQuery queryMostRecentPage(Jid jid, int max) throws NoResponseException, XMPPErrorException, NotConnectedException, NotLoggedInException, InterruptedException { MamQueryArgs mamQueryArgs = MamQueryArgs.builder() // Produces an empty <before/> element for XEP-0059 § 2.5 .queryLastPage() .limitResultsToJid(jid) .setResultPageSize(max) .build(); return queryArchive(mamQueryArgs); }
.limitResultsToJid(userOne) .queryLastPage() .build(); MamQuery mamQuery = mamManagerConTwo.queryArchive(mamQueryArgs);
/** * Lookup the archive's message ID of the latest message in the archive. Returns {@code null} if the archive is * empty. * * @return the ID of the lastest message or {@code null}. * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException * @throws NotLoggedInException * @throws InterruptedException * @since 4.3.0 */ public String getMessageUidOfLatestMessage() throws NoResponseException, XMPPErrorException, NotConnectedException, NotLoggedInException, InterruptedException { MamQueryArgs mamQueryArgs = MamQueryArgs.builder() .setResultPageSize(1) .queryLastPage() .build(); MamQuery mamQuery = queryArchive(mamQueryArgs); if (mamQuery.getMessages().isEmpty()) { return null; } return mamQuery.getMamResultExtensions().get(0).getId(); }
@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()); } }
@Test public void checkAddAdditionalFieldsStanza() throws Exception { FormField field1 = new FormField("urn:example:xmpp:free-text-search"); field1.setType(FormField.Type.text_single); field1.addValue("Hi"); FormField field2 = new FormField("urn:example:xmpp:stanza-content"); field2.setType(FormField.Type.jid_single); field2.addValue("Hi2"); MamQueryArgs mamQueryArgs = MamQueryArgs.builder() .withAdditionalFormField(field1) .withAdditionalFormField(field2) .build(); DataForm dataForm = mamQueryArgs.getDataForm(); String dataFormResult = dataForm.toXML(null).toString(); assertXmlSimilar(additionalFieldsStanza, dataFormResult); }
@Test public void checkWithJidFilter() throws Exception { Jid jid = JidTestUtil.BARE_JID_1; MamQueryArgs mamQueryArgs = MamQueryArgs.builder().limitResultsToJid(jid).build(); DataForm dataForm = mamQueryArgs.getDataForm(); List<String> fields = new ArrayList<>(); fields.add("with"); List<CharSequence> values = new ArrayList<>(); values.add(jid); assertEquals(getMamXMemberWith(fields, values), dataForm.toXML(null).toString()); }
public MamQuery queryMostRecentPage(Jid jid, int max) throws NoResponseException, XMPPErrorException, NotConnectedException, NotLoggedInException, InterruptedException { MamQueryArgs mamQueryArgs = MamQueryArgs.builder() // Produces an empty <before/> element for XEP-0059 § 2.5 .queryLastPage() .limitResultsToJid(jid) .setResultPageSize(max) .build(); return queryArchive(mamQueryArgs); }
@Test public void checkResultsLimit() throws Exception { DataForm dataForm = getNewMamForm(); MamQueryIQ mamQueryIQ = new MamQueryIQ(queryId, dataForm); mamQueryIQ.setType(IQ.Type.set); mamQueryIQ.setStanzaId("sarasa"); MamQueryArgs mamQueryArgs = MamQueryArgs.builder().setResultPageSize(10).build(); mamQueryArgs.maybeAddRsmSet(mamQueryIQ); Assert.assertEquals(mamQueryIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString(), resultsLimitStanza); }