use of org.jivesoftware.smackx.mam.element.MamFinIQ in project Smack by igniterealtime.
the class MamFinProviderTest method checkMamFinProvider.
@Test
public void checkMamFinProvider() throws Exception {
XmlPullParser parser = PacketParserUtils.getParserFor(exmapleMamFinXml);
MamFinIQ mamFinIQ = new MamFinIQProvider().parse(parser);
Assert.assertFalse(mamFinIQ.isComplete());
Assert.assertTrue(mamFinIQ.isStable());
Assert.assertNull(mamFinIQ.getQueryId());
RSMSet rsmSet = mamFinIQ.getRSMSet();
Assert.assertEquals(rsmSet.getAfter(), "09af3-cc343-b409f");
Assert.assertEquals(rsmSet.getMax(), 10);
}
use of org.jivesoftware.smackx.mam.element.MamFinIQ 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);
}
use of org.jivesoftware.smackx.mam.element.MamFinIQ in project Smack by igniterealtime.
the class MamFinProviderTest method checkQueryLimitedResults.
@Test
public void checkQueryLimitedResults() throws Exception {
// @formatter:off
final String IQ_LIMITED_RESULTS_EXAMPLE = "<iq type='result' id='u29303'>" + "<fin xmlns='urn:xmpp:mam:1' complete='true'>" + "<set xmlns='http://jabber.org/protocol/rsm'>" + "<first index='0'>23452-4534-1</first>" + "<last>390-2342-22</last>" + "<count>16</count>" + "</set>" + "</fin>" + "</iq>";
// @formatter:on
IQ iq = (IQ) PacketParserUtils.parseStanza(IQ_LIMITED_RESULTS_EXAMPLE);
MamFinIQ mamFinIQ = (MamFinIQ) iq;
Assert.assertEquals(mamFinIQ.getType(), Type.result);
Assert.assertTrue(mamFinIQ.isComplete());
Assert.assertEquals(mamFinIQ.getRSMSet().getCount(), 16);
Assert.assertEquals(mamFinIQ.getRSMSet().getFirst(), "23452-4534-1");
Assert.assertEquals(mamFinIQ.getRSMSet().getFirstIndex(), 0);
Assert.assertEquals(mamFinIQ.getRSMSet().getLast(), "390-2342-22");
}
use of org.jivesoftware.smackx.mam.element.MamFinIQ in project Smack by igniterealtime.
the class MamManager method queryArchive.
private MamQueryResult queryArchive(MamQueryIQ mamQueryIq) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException {
final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
MamFinIQ mamFinIQ = null;
StanzaCollector mamFinIQCollector = connection.createStanzaCollector(new IQReplyFilter(mamQueryIq, connection));
StanzaCollector.Configuration resultCollectorConfiguration = StanzaCollector.newConfiguration().setStanzaFilter(new MamResultFilter(mamQueryIq)).setCollectorToReset(mamFinIQCollector);
StanzaCollector resultCollector = connection.createStanzaCollector(resultCollectorConfiguration);
try {
connection.sendStanza(mamQueryIq);
mamFinIQ = mamFinIQCollector.nextResultOrThrow();
} finally {
mamFinIQCollector.cancel();
resultCollector.cancel();
}
List<Forwarded> forwardedMessages = new ArrayList<>(resultCollector.getCollectedCount());
for (Message resultMessage = resultCollector.pollResult(); resultMessage != null; resultMessage = resultCollector.pollResult()) {
MamElements.MamResultExtension mamResultExtension = MamElements.MamResultExtension.from(resultMessage);
forwardedMessages.add(mamResultExtension.getForwarded());
}
return new MamQueryResult(forwardedMessages, mamFinIQ, mamQueryIq.getNode(), DataForm.from(mamQueryIq));
}
Aggregations