Search in sources :

Example 1 with MamPrefsIQ

use of org.jivesoftware.smackx.mam.element.MamPrefsIQ in project Smack by igniterealtime.

the class MamManager method updateArchivingPreferences.

/**
     * Update the preferences in the server.
     * 
     * @param alwaysJids
     *            is the list of JIDs that should always have messages to/from
     *            archived in the user's store
     * @param neverJids
     *            is the list of JIDs that should never have messages to/from
     *            archived in the user's store
     * @param defaultBehavior
     *            can be "roster", "always", "never" (see XEP-0313)
     * @return the MAM preferences result
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException
     * @throws NotLoggedInException
     */
public MamPrefsResult updateArchivingPreferences(List<Jid> alwaysJids, List<Jid> neverJids, DefaultBehavior defaultBehavior) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException {
    Objects.requireNonNull(defaultBehavior, "Default behavior must be set");
    MamPrefsIQ mamPrefIQ = new MamPrefsIQ(alwaysJids, neverJids, defaultBehavior);
    return queryMamPrefs(mamPrefIQ);
}
Also used : MamPrefsIQ(org.jivesoftware.smackx.mam.element.MamPrefsIQ)

Example 2 with MamPrefsIQ

use of org.jivesoftware.smackx.mam.element.MamPrefsIQ in project Smack by igniterealtime.

the class MamPrefsIQProvider method parse.

@Override
public MamPrefsIQ parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
    String iqType = parser.getAttributeValue("", "type");
    String defaultBehaviorString = parser.getAttributeValue("", "default");
    DefaultBehavior defaultBehavior = null;
    if (defaultBehaviorString != null) {
        defaultBehavior = DefaultBehavior.valueOf(defaultBehaviorString);
    }
    if (iqType == null) {
        iqType = "result";
    }
    List<Jid> alwaysJids = null;
    List<Jid> neverJids = null;
    outerloop: while (true) {
        final int eventType = parser.next();
        final String name = parser.getName();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                switch(name) {
                    case "always":
                        alwaysJids = iterateJids(parser);
                        break;
                    case "never":
                        neverJids = iterateJids(parser);
                        break;
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return new MamPrefsIQ(alwaysJids, neverJids, defaultBehavior);
}
Also used : MamPrefsIQ(org.jivesoftware.smackx.mam.element.MamPrefsIQ) Jid(org.jxmpp.jid.Jid) DefaultBehavior(org.jivesoftware.smackx.mam.element.MamPrefsIQ.DefaultBehavior)

Example 3 with MamPrefsIQ

use of org.jivesoftware.smackx.mam.element.MamPrefsIQ in project Smack by igniterealtime.

the class MamPrefIQProviderTest method checkMamPrefsIQProvider.

@Test
public void checkMamPrefsIQProvider() throws Exception {
    XmlPullParser parser1 = PacketParserUtils.getParserFor(exampleMamPrefsIQ1);
    MamPrefsIQ mamPrefIQ1 = new MamPrefsIQProvider().parse(parser1);
    Assert.assertEquals(IQ.Type.set, mamPrefIQ1.getType());
    Assert.assertEquals(mamPrefIQ1.getAlwaysJids().get(0), "romeo@montague.lit");
    Assert.assertEquals(mamPrefIQ1.getNeverJids().get(0), "montague@montague.lit");
    XmlPullParser parser2 = PacketParserUtils.getParserFor(exampleMamPrefsIQ2);
    MamPrefsIQ mamPrefIQ2 = new MamPrefsIQProvider().parse(parser2);
    Assert.assertEquals(IQ.Type.set, mamPrefIQ2.getType());
    Assert.assertEquals(mamPrefIQ2.getAlwaysJids().get(0), "romeo@montague.lit");
    Assert.assertEquals(mamPrefIQ2.getAlwaysJids().get(1), "montague@montague.lit");
    Assert.assertTrue(mamPrefIQ2.getNeverJids().isEmpty());
    XmlPullParser parser3 = PacketParserUtils.getParserFor(exampleMamPrefsIQ3);
    MamPrefsIQ mamPrefIQ3 = new MamPrefsIQProvider().parse(parser3);
    Assert.assertEquals(IQ.Type.set, mamPrefIQ3.getType());
}
Also used : MamPrefsIQ(org.jivesoftware.smackx.mam.element.MamPrefsIQ) XmlPullParser(org.xmlpull.v1.XmlPullParser) MamPrefsIQProvider(org.jivesoftware.smackx.mam.provider.MamPrefsIQProvider) Test(org.junit.Test)

Example 4 with MamPrefsIQ

use of org.jivesoftware.smackx.mam.element.MamPrefsIQ in project Smack by igniterealtime.

the class MamManager method queryMamPrefs.

private MamPrefsResult queryMamPrefs(MamPrefsIQ mamPrefsIQ) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
    MamPrefsIQ mamPrefsResultIQ = connection.sendIqRequestAndWaitForResponse(mamPrefsIQ);
    return new MamPrefsResult(mamPrefsResultIQ, DataForm.from(mamPrefsIQ));
}
Also used : MamPrefsIQ(org.jivesoftware.smackx.mam.element.MamPrefsIQ) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 5 with MamPrefsIQ

use of org.jivesoftware.smackx.mam.element.MamPrefsIQ in project Smack by igniterealtime.

the class MamPrefIQProviderTest method checkMamPrefResult.

@Test
public void checkMamPrefResult() throws Exception {
    IQ iq = PacketParserUtils.parseStanza(exampleMamPrefsResultIQ);
    MamPrefsIQ mamPrefsIQ = (MamPrefsIQ) iq;
    List<Jid> alwaysJids = mamPrefsIQ.getAlwaysJids();
    List<Jid> neverJids = mamPrefsIQ.getNeverJids();
    assertEquals(alwaysJids.size(), 1);
    assertEquals(neverJids.size(), 2);
    assertEquals(alwaysJids.get(0).toString(), "romeo@montague.lit");
    assertEquals(neverJids.get(1).toString(), "montague@montague.lit");
}
Also used : MamPrefsIQ(org.jivesoftware.smackx.mam.element.MamPrefsIQ) Jid(org.jxmpp.jid.Jid) MamPrefsIQ(org.jivesoftware.smackx.mam.element.MamPrefsIQ) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MamPrefsIQ (org.jivesoftware.smackx.mam.element.MamPrefsIQ)8 Test (org.junit.jupiter.api.Test)3 Jid (org.jxmpp.jid.Jid)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ArrayList (java.util.ArrayList)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 IQ (org.jivesoftware.smack.packet.IQ)1 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)1 DefaultBehavior (org.jivesoftware.smackx.mam.element.MamPrefsIQ.DefaultBehavior)1 MamPrefsIQProvider (org.jivesoftware.smackx.mam.provider.MamPrefsIQProvider)1 Test (org.junit.Test)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1