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);
}
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);
}
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());
}
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));
}
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");
}
Aggregations