Search in sources :

Example 1 with MamResultFilter

use of org.jivesoftware.smackx.mam.filter.MamResultFilter in project Smack by igniterealtime.

the class MamManager method queryArchivePage.

private MamQueryPage queryArchivePage(MamQueryIQ mamQueryIq) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
    MamFinIQ mamFinIQ;
    StanzaCollector mamFinIQCollector = connection.createStanzaCollector(new IQReplyFilter(mamQueryIq, connection));
    StanzaCollector.Configuration resultCollectorConfiguration = StanzaCollector.newConfiguration().setStanzaFilter(new MamResultFilter(mamQueryIq)).setCollectorToReset(mamFinIQCollector);
    StanzaCollector cancelledResultCollector;
    try (StanzaCollector resultCollector = connection.createStanzaCollector(resultCollectorConfiguration)) {
        connection.sendStanza(mamQueryIq);
        mamFinIQ = mamFinIQCollector.nextResultOrThrow();
        cancelledResultCollector = resultCollector;
    }
    return new MamQueryPage(cancelledResultCollector, mamFinIQ);
}
Also used : IQReplyFilter(org.jivesoftware.smack.filter.IQReplyFilter) MamFinIQ(org.jivesoftware.smackx.mam.element.MamFinIQ) MamResultFilter(org.jivesoftware.smackx.mam.filter.MamResultFilter) XMPPConnection(org.jivesoftware.smack.XMPPConnection) StanzaCollector(org.jivesoftware.smack.StanzaCollector)

Example 2 with MamResultFilter

use of org.jivesoftware.smackx.mam.filter.MamResultFilter 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));
}
Also used : Message(org.jivesoftware.smack.packet.Message) IQReplyFilter(org.jivesoftware.smack.filter.IQReplyFilter) ArrayList(java.util.ArrayList) XMPPConnection(org.jivesoftware.smack.XMPPConnection) MamElements(org.jivesoftware.smackx.mam.element.MamElements) MamFinIQ(org.jivesoftware.smackx.mam.element.MamFinIQ) Forwarded(org.jivesoftware.smackx.forward.packet.Forwarded) MamResultFilter(org.jivesoftware.smackx.mam.filter.MamResultFilter) StanzaCollector(org.jivesoftware.smack.StanzaCollector)

Aggregations

StanzaCollector (org.jivesoftware.smack.StanzaCollector)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 IQReplyFilter (org.jivesoftware.smack.filter.IQReplyFilter)2 MamFinIQ (org.jivesoftware.smackx.mam.element.MamFinIQ)2 MamResultFilter (org.jivesoftware.smackx.mam.filter.MamResultFilter)2 ArrayList (java.util.ArrayList)1 Message (org.jivesoftware.smack.packet.Message)1 Forwarded (org.jivesoftware.smackx.forward.packet.Forwarded)1 MamElements (org.jivesoftware.smackx.mam.element.MamElements)1