Search in sources :

Example 6 with RSMSet

use of org.jivesoftware.smackx.rsm.packet.RSMSet in project Smack by igniterealtime.

the class MamFinIQProvider method parse.

@Override
public MamFinIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
    String queryId = parser.getAttributeValue("", "queryid");
    boolean complete = ParserUtils.getBooleanAttribute(parser, "complete", false);
    boolean stable = ParserUtils.getBooleanAttribute(parser, "stable", true);
    RSMSet rsmSet = null;
    outerloop: while (true) {
        int eventType = parser.next();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                if (parser.getName().equals(RSMSet.ELEMENT)) {
                    rsmSet = RSMSetProvider.INSTANCE.parse(parser);
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return new MamFinIQ(queryId, rsmSet, complete, stable);
}
Also used : RSMSet(org.jivesoftware.smackx.rsm.packet.RSMSet) MamFinIQ(org.jivesoftware.smackx.mam.element.MamFinIQ)

Example 7 with RSMSet

use of org.jivesoftware.smackx.rsm.packet.RSMSet in project Smack by igniterealtime.

the class PagingTest method checkPageQueryStanza.

@Test
public void checkPageQueryStanza() throws Exception {
    DataForm dataForm = getNewMamForm();
    int max = 10;
    RSMSet rsmSet = new RSMSet(max);
    MamQueryIQ mamQueryIQ = new MamQueryIQ(queryId, dataForm);
    mamQueryIQ.setStanzaId("sarasa");
    mamQueryIQ.setType(IQ.Type.set);
    mamQueryIQ.addExtension(rsmSet);
    Assert.assertEquals(mamQueryIQ.getDataForm(), dataForm);
    Assert.assertEquals(mamQueryIQ.getDataForm().getFields().get(0).getValues().get(0), "urn:xmpp:mam:1");
    Assert.assertEquals(mamQueryIQ.toXML().toString(), pagingStanza);
}
Also used : RSMSet(org.jivesoftware.smackx.rsm.packet.RSMSet) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ) Test(org.junit.Test)

Example 8 with RSMSet

use of org.jivesoftware.smackx.rsm.packet.RSMSet in project Smack by igniterealtime.

the class RSMManager method continuePage.

Collection<ExtensionElement> continuePage(int max, Collection<ExtensionElement> returnedExtensions, Collection<ExtensionElement> additionalExtensions) {
    if (returnedExtensions == null) {
        throw new IllegalArgumentException("returnedExtensions must no be null");
    }
    if (additionalExtensions == null) {
        additionalExtensions = new LinkedList<ExtensionElement>();
    }
    RSMSet resultRsmSet = PacketUtil.extensionElementFrom(returnedExtensions, RSMSet.ELEMENT, RSMSet.NAMESPACE);
    if (resultRsmSet == null) {
        throw new IllegalArgumentException("returnedExtensions did not contain a RSMset");
    }
    RSMSet continePageRsmSet = new RSMSet(max, resultRsmSet.getLast(), PageDirection.after);
    additionalExtensions.add(continePageRsmSet);
    return additionalExtensions;
}
Also used : RSMSet(org.jivesoftware.smackx.rsm.packet.RSMSet) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 9 with RSMSet

use of org.jivesoftware.smackx.rsm.packet.RSMSet in project Smack by igniterealtime.

the class MamManager method pageAfter.

/**
     * Obtain page after the last message saved (specific chat).
     * <p>
     * Note that the messageUid is the XEP-0313 UID and <b>not</> the stanza ID of the message.
     * </p>
     *
     * @param chatJid
     * @param messageUid the UID of the message of which messages after should be received.
     * @param max
     * @return the MAM query result
     * @throws XMPPErrorException
     * @throws NotLoggedInException
     * @throws NotConnectedException
     * @throws InterruptedException
     * @throws NoResponseException
     */
public MamQueryResult pageAfter(Jid chatJid, String messageUid, int max) throws XMPPErrorException, NotLoggedInException, NotConnectedException, InterruptedException, NoResponseException {
    RSMSet rsmSet = new RSMSet(messageUid, null, -1, -1, null, max, null, -1);
    DataForm dataForm = getNewMamForm();
    addWithJid(chatJid, dataForm);
    return page(null, dataForm, rsmSet);
}
Also used : RSMSet(org.jivesoftware.smackx.rsm.packet.RSMSet) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm)

Example 10 with RSMSet

use of org.jivesoftware.smackx.rsm.packet.RSMSet in project Smack by igniterealtime.

the class MamManager method pageNext.

/**
     * Returns the next 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 pageNext(MamQueryResult mamQueryResult, int count) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException {
    RSMSet previousResultRsmSet = mamQueryResult.mamFin.getRSMSet();
    RSMSet requestRsmSet = new RSMSet(count, previousResultRsmSet.getLast(), RSMSet.PageDirection.after);
    return page(mamQueryResult, requestRsmSet);
}
Also used : RSMSet(org.jivesoftware.smackx.rsm.packet.RSMSet)

Aggregations

RSMSet (org.jivesoftware.smackx.rsm.packet.RSMSet)11 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)3 Test (org.junit.Test)3 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)2 MamFinIQ (org.jivesoftware.smackx.mam.element.MamFinIQ)2 LinkedList (java.util.LinkedList)1 IQ (org.jivesoftware.smack.packet.IQ)1 MamQueryIQ (org.jivesoftware.smackx.mam.element.MamQueryIQ)1 MamFinIQProvider (org.jivesoftware.smackx.mam.provider.MamFinIQProvider)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1