From f7fcff139c617fff7a6fddec2cf98121638db9bd Mon Sep 17 00:00:00 2001 From: Fernando Ramirez Date: Tue, 27 Dec 2016 15:04:30 -0300 Subject: [PATCH] Add MAM methods to load previous page and to load most recent page --- .../jivesoftware/smackx/mam/MamManager.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java index 2f70553ed..ea7539e57 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java @@ -318,6 +318,27 @@ public final class MamManager extends Manager { return page(mamQueryResult.form, requestRsmSet); } + /** + * Returns the previous page of the archive. + * + * @param mamQueryResult + * is the previous query result + * @param count + * is the amount of messages that a page contains + * @return the MAM query result + * @throws NoResponseException + * @throws XMPPErrorException + * @throws NotConnectedException + * @throws InterruptedException + * @throws NotLoggedInException + */ + public MamQueryResult pagePrevious(MamQueryResult mamQueryResult, int count) throws NoResponseException, + XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException { + RSMSet previousResultRsmSet = mamQueryResult.mamFin.getRSMSet(); + RSMSet requestRsmSet = new RSMSet(count, previousResultRsmSet.getFirst(), RSMSet.PageDirection.before); + return page(mamQueryResult.form, requestRsmSet); + } + /** * Obtain page before the first message saved (specific chat). * @@ -360,6 +381,23 @@ public final class MamManager extends Manager { return page(dataForm, rsmSet); } + /** + * Obtain the most recent page of a chat. + * + * @param chatJid + * @param max + * @return the MAM query result + * @throws XMPPErrorException + * @throws NotLoggedInException + * @throws NotConnectedException + * @throws InterruptedException + * @throws NoResponseException + */ + public MamQueryResult mostRecentPage(Jid chatJid, int max) throws XMPPErrorException, NotLoggedInException, + NotConnectedException, InterruptedException, NoResponseException { + return pageBefore(chatJid, "", max); + } + /** * Get the form fields supported by the server. *