use of org.jivesoftware.smackx.muc.packet.MUCItem in project Smack by igniterealtime.
the class MultiUserChat method getAffiliatesByAdmin.
/**
* Returns a collection of <code>Affiliate</code> that have the specified room affiliation
* sending a request in the admin namespace.
*
* @param affiliation the affiliation of the users in the room.
* @return a collection of <code>Affiliate</code> that have the specified room affiliation.
* @throws XMPPErrorException if you don't have enough privileges to get this information.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
private List<Affiliate> getAffiliatesByAdmin(MUCAffiliation affiliation) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCAdmin iq = new MUCAdmin();
iq.setTo(room);
iq.setType(IQ.Type.get);
// Set the specified affiliation. This may request the list of owners/admins/members/outcasts.
MUCItem item = new MUCItem(affiliation);
iq.addItem(item);
MUCAdmin answer = (MUCAdmin) connection.sendIqRequestAndWaitForResponse(iq);
// Get the list of affiliates from the server's answer
List<Affiliate> affiliates = new ArrayList<Affiliate>();
for (MUCItem mucadminItem : answer.getItems()) {
affiliates.add(new Affiliate(mucadminItem));
}
return affiliates;
}
use of org.jivesoftware.smackx.muc.packet.MUCItem in project Smack by igniterealtime.
the class MultiUserChat method changeAffiliationByAdmin.
private void changeAffiliationByAdmin(Collection<? extends Jid> jids, MUCAffiliation affiliation) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCAdmin iq = new MUCAdmin();
iq.setTo(room);
iq.setType(IQ.Type.set);
for (Jid jid : jids) {
// Set the new affiliation.
MUCItem item = new MUCItem(affiliation, jid);
iq.addItem(item);
}
connection.sendIqRequestAndWaitForResponse(iq);
}
use of org.jivesoftware.smackx.muc.packet.MUCItem in project Smack by igniterealtime.
the class MultiUserChat method changeAffiliationByAdmin.
/**
* Tries to change the affiliation with an 'muc#admin' namespace
*
* @param jid TODO javadoc me please
* @param affiliation TODO javadoc me please
* @param reason the reason for the affiliation change (optional)
* @throws XMPPErrorException if there was an XMPP error returned.
* @throws NoResponseException if there was no response from the remote entity.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
private void changeAffiliationByAdmin(Jid jid, MUCAffiliation affiliation, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCAdmin iq = new MUCAdmin();
iq.setTo(room);
iq.setType(IQ.Type.set);
// Set the new affiliation.
MUCItem item = new MUCItem(affiliation, jid, reason);
iq.addItem(item);
connection.sendIqRequestAndWaitForResponse(iq);
}
use of org.jivesoftware.smackx.muc.packet.MUCItem in project Smack by igniterealtime.
the class MultiUserChat method changeRole.
private void changeRole(Resourcepart nickname, MUCRole role, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCAdmin iq = new MUCAdmin();
iq.setTo(room);
iq.setType(IQ.Type.set);
// Set the new role.
MUCItem item = new MUCItem(role, nickname, reason);
iq.addItem(item);
connection.sendIqRequestAndWaitForResponse(iq);
}
use of org.jivesoftware.smackx.muc.packet.MUCItem in project Smack by igniterealtime.
the class MUCParserUtils method parseItem.
public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
int initialDepth = parser.getDepth();
MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation"));
Resourcepart nick = ParserUtils.getResourcepartAttribute(parser, "nick");
MUCRole role = MUCRole.fromString(parser.getAttributeValue("", "role"));
Jid jid = ParserUtils.getJidAttribute(parser);
Jid actor = null;
Resourcepart actorNick = null;
String reason = null;
outerloop: while (true) {
XmlPullParser.Event eventType = parser.next();
switch(eventType) {
case START_ELEMENT:
String name = parser.getName();
switch(name) {
case "actor":
actor = ParserUtils.getJidAttribute(parser);
// TODO change to
// actorNick = Resourcepart.from(parser.getAttributeValue("", "nick"));
// once a newer version of JXMPP is used that supports from(null).
String actorNickString = parser.getAttributeValue("", "nick");
if (actorNickString != null) {
actorNick = Resourcepart.from(actorNickString);
}
break;
case "reason":
reason = parser.nextText();
break;
}
break;
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
}
}
return new MUCItem(affiliation, role, actor, reason, jid, nick, actorNick);
}
Aggregations