Search in sources :

Example 6 with Forwarded

use of org.jivesoftware.smackx.forward.packet.Forwarded in project Smack by igniterealtime.

the class QueryArchiveTest method checkMamQueryResults.

@Test
public void checkMamQueryResults() throws Exception {
    Message message = new Message();
    message.setStanzaId("iasd207");
    message.setFrom(JidCreate.from("coven@chat.shakespeare.lit"));
    message.setTo(JidCreate.from("hag66@shakespeare.lit/pda"));
    GregorianCalendar calendar = new GregorianCalendar(2002, 10 - 1, 13, 23, 58, 37);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = calendar.getTime();
    DelayInformation delay = new DelayInformation(date);
    Message forwardedMessage = new Message();
    forwardedMessage.setFrom(JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
    forwardedMessage.setStanzaId("162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
    forwardedMessage.setType(Type.chat);
    forwardedMessage.setBody("Thrice the brinded cat hath mew.");
    Forwarded forwarded = new Forwarded(delay, forwardedMessage);
    message.addExtension(new MamResultExtension("g27", "34482-21985-73620", forwarded));
    Assert.assertEquals(message.toXML().toString(), mamQueryResultExample);
    MamResultExtension mamResultExtension = MamResultExtension.from(message);
    Assert.assertEquals(mamResultExtension.getId(), "34482-21985-73620");
    Assert.assertEquals(mamResultExtension.getForwarded().getDelayInformation().getStamp(), date);
    Message resultMessage = (Message) mamResultExtension.getForwarded().getForwardedStanza();
    Assert.assertEquals(resultMessage.getFrom(), JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
    Assert.assertEquals(resultMessage.getStanzaId(), "162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
    Assert.assertEquals(resultMessage.getType(), Type.chat);
    Assert.assertEquals(resultMessage.getBody(), "Thrice the brinded cat hath mew.");
}
Also used : Message(org.jivesoftware.smack.packet.Message) DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) GregorianCalendar(java.util.GregorianCalendar) Forwarded(org.jivesoftware.smackx.forward.packet.Forwarded) MamResultExtension(org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension) Date(java.util.Date) Test(org.junit.Test)

Example 7 with Forwarded

use of org.jivesoftware.smackx.forward.packet.Forwarded in project Smack by igniterealtime.

the class MamResultProvider method parse.

@Override
public MamResultExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
    Forwarded forwarded = null;
    String queryId = parser.getAttributeValue("", "queryid");
    String id = parser.getAttributeValue("", "id");
    outerloop: while (true) {
        final int eventType = parser.next();
        final String name = parser.getName();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                switch(name) {
                    case Forwarded.ELEMENT:
                        forwarded = ForwardedProvider.INSTANCE.parse(parser);
                        break;
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return new MamResultExtension(queryId, id, forwarded);
}
Also used : Forwarded(org.jivesoftware.smackx.forward.packet.Forwarded) MamResultExtension(org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension)

Example 8 with Forwarded

use of org.jivesoftware.smackx.forward.packet.Forwarded 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)

Example 9 with Forwarded

use of org.jivesoftware.smackx.forward.packet.Forwarded in project Smack by igniterealtime.

the class CarbonTest method carbonSentTest.

@Test
public void carbonSentTest() throws Exception {
    XmlPullParser parser;
    String control;
    CarbonExtension cc;
    Forwarded fwd;
    control = XMLBuilder.create("sent").e("forwarded").a("xmlns", "urn:xmpp:forwarded:0").e("message").a("from", "romeo@montague.com").asString(outputProperties);
    parser = PacketParserUtils.getParserFor(control);
    cc = new CarbonManagerProvider().parse(parser);
    fwd = cc.getForwarded();
    // meta
    assertEquals(CarbonExtension.Direction.sent, cc.getDirection());
    // no delay in packet
    assertEquals(null, fwd.getDelayInformation());
    // check message
    assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedStanza().getFrom()));
    // check end of tag
    assertEquals(XmlPullParser.END_TAG, parser.getEventType());
    assertEquals("sent", parser.getName());
}
Also used : CarbonManagerProvider(org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider) CarbonExtension(org.jivesoftware.smackx.carbons.packet.CarbonExtension) XmlPullParser(org.xmlpull.v1.XmlPullParser) Forwarded(org.jivesoftware.smackx.forward.packet.Forwarded) ExperimentalInitializerTest(org.jivesoftware.smackx.ExperimentalInitializerTest) Test(org.junit.Test)

Example 10 with Forwarded

use of org.jivesoftware.smackx.forward.packet.Forwarded in project Smack by igniterealtime.

the class ForwardedTest method forwardedTest.

@Test
public void forwardedTest() throws Exception {
    XmlPullParser parser;
    String control;
    Forwarded fwd;
    control = XMLBuilder.create("forwarded").a("xmlns", "urn:xmpp:forwarded:0").e("message").a("from", "romeo@montague.com").asString(outputProperties);
    parser = PacketParserUtils.getParserFor(control);
    fwd = new ForwardedProvider().parse(parser);
    // no delay in packet
    assertEquals(null, fwd.getDelayInformation());
    // check message
    assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedStanza().getFrom()));
    // check end of tag
    assertEquals(XmlPullParser.END_TAG, parser.getEventType());
    assertEquals("forwarded", parser.getName());
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) Forwarded(org.jivesoftware.smackx.forward.packet.Forwarded) ForwardedProvider(org.jivesoftware.smackx.forward.provider.ForwardedProvider) Test(org.junit.Test)

Aggregations

Forwarded (org.jivesoftware.smackx.forward.packet.Forwarded)11 Test (org.junit.Test)6 Message (org.jivesoftware.smack.packet.Message)5 MamResultExtension (org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension)4 XmlPullParser (org.xmlpull.v1.XmlPullParser)4 Date (java.util.Date)3 GregorianCalendar (java.util.GregorianCalendar)3 DelayInformation (org.jivesoftware.smackx.delay.packet.DelayInformation)3 SmackException (org.jivesoftware.smack.SmackException)2 CarbonExtension (org.jivesoftware.smackx.carbons.packet.CarbonExtension)2 ForwardedProvider (org.jivesoftware.smackx.forward.provider.ForwardedProvider)2 ArrayList (java.util.ArrayList)1 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)1 SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)1 StanzaCollector (org.jivesoftware.smack.StanzaCollector)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 IQReplyFilter (org.jivesoftware.smack.filter.IQReplyFilter)1 Stanza (org.jivesoftware.smack.packet.Stanza)1 ExperimentalInitializerTest (org.jivesoftware.smackx.ExperimentalInitializerTest)1 Direction (org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction)1