.setResultPageSize(messagesPerPage) .limitResultsToJid(userOne) .afterUid(lastMessageArchiveUid) .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 Builder setResultPageSize(Integer max) { if (max == null) { maxResults = -1; return this; } return setResultPageSizeTo(max.intValue()); }
NotLoggedInException { MamQueryArgs mamQueryArgs = MamQueryArgs.builder() .queryNode(node) .setResultPageSize(max) .limitResultsSince(start) .limitResultsBefore(end) .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 static Builder builder() { return new Builder(); }
/** * Only return the count of messages the query yields, not the actual messages. Note that not all services * return a correct count, some return an approximate count. * * @return an reference to this builder. * @see <a href="https://xmpp.org/extensions/xep-0059.html#count">XEP-0059 § 2.7</a> */ public Builder onlyReturnMessageCount() { return setResultPageSizeTo(0); }
public Builder setResultPageSize(Integer max) { if (max == null) { maxResults = -1; return this; } return setResultPageSizeTo(max.intValue()); }
public Builder withAdditionalFormFields(List<FormField> additionalFields) { for (FormField formField : additionalFields) { withAdditionalFormField(formField); } return this; }
/** * Query from the last, i.e. most recent, page of the archive. This will return the very last page of the * archive holding the most recent matching messages. You usually would page backwards from there on. * * @return a reference to this builder. * @see <a href="https://xmpp.org/extensions/xep-0059.html#last">XEP-0059 § 2.5. Requesting the Last Page in * a Result Set</a> */ public Builder queryLastPage() { return beforeUid(""); }
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); }
.setResultPageSizeTo(1) .limitResultsToJid(userOne) .queryLastPage() .build(); MamQuery mamQuery = mamManagerConTwo.queryArchive(mamQueryArgs);
@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()); } }
public static Builder builder() { return new Builder(); }
@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); }
/** * Only return the count of messages the query yields, not the actual messages. Note that not all services * return a correct count, some return an approximate count. * * @return an reference to this builder. * @see <a href="https://xmpp.org/extensions/xep-0059.html#count">XEP-0059 § 2.7</a> */ public Builder onlyReturnMessageCount() { return setResultPageSizeTo(0); }
/** * Query from the last, i.e. most recent, page of the archive. This will return the very last page of the * archive holding the most recent matching messages. You usually would page backwards from there on. * * @return a reference to this builder. * @see <a href="https://xmpp.org/extensions/xep-0059.html#last">XEP-0059 § 2.5. Requesting the Last Page in * a Result Set</a> */ public Builder queryLastPage() { return beforeUid(""); }
@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()); }
@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()); }
@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()); }