/** * 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 */ private List<Affiliate> getAffiliatesByAdmin(MUCAffiliation affiliation) throws NoResponseException, XMPPErrorException, NotConnectedException { 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.createPacketCollectorAndSend(iq).nextResultOrThrow(); // 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; }
/** * Returns a list of <code>Occupant</code> that have the specified room role. * * @param role the role of the occupant in the room. * @return a list of <code>Occupant</code> that have the specified room role. * @throws XMPPErrorException if an error occured while performing the request to the server or you * don't have enough privileges to get this information. * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException */ private List<Occupant> getOccupants(MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException { MUCAdmin iq = new MUCAdmin(); iq.setTo(room); iq.setType(IQ.Type.get); // Set the specified role. This may request the list of moderators/participants. MUCItem item = new MUCItem(role); iq.addItem(item); MUCAdmin answer = (MUCAdmin) connection.createPacketCollectorAndSend(iq).nextResultOrThrow(); // Get the list of participants from the server's answer List<Occupant> participants = new ArrayList<Occupant>(); for (MUCItem mucadminItem : answer.getItems()) { participants.add(new Occupant(mucadminItem)); } return participants; }
Occupant(Presence presence) { MUCUser mucUser = (MUCUser) presence.getExtension("x", "http://jabber.org/protocol/muc#user"); MUCItem item = mucUser.getItem(); this.jid = item.getJid(); this.affiliation = item.getAffiliation(); this.role = item.getRole(); // Get the nickname from the FROM attribute of the presence this.nick = XmppStringUtils.parseResource(presence.getFrom()); }
/** * Tries to change the affiliation with an 'muc#admin' namespace * * @param jid * @param affiliation * @param reason the reason for the affiliation change (optional) * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException */ private void changeAffiliationByAdmin(String jid, MUCAffiliation affiliation, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException { 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.createPacketCollectorAndSend(iq).nextResultOrThrow(); }
private void changeAffiliationByAdmin(Collection<String> jids, MUCAffiliation affiliation) throws NoResponseException, XMPPErrorException, NotConnectedException { MUCAdmin iq = new MUCAdmin(); iq.setTo(room); iq.setType(IQ.Type.set); for (String jid : jids) { // Set the new affiliation. MUCItem item = new MUCItem(affiliation, jid); iq.addItem(item); } connection.createPacketCollectorAndSend(iq).nextResultOrThrow(); }
private void changeRole(String nickname, MUCRole role, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException { 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.createPacketCollectorAndSend(iq).nextResultOrThrow(); }
private void changeRole(Collection<String> nicknames, MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException { MUCAdmin iq = new MUCAdmin(); iq.setTo(room); iq.setType(IQ.Type.set); for (String nickname : nicknames) { // Set the new role. MUCItem item = new MUCItem(role, nickname); iq.addItem(item); } connection.createPacketCollectorAndSend(iq).nextResultOrThrow(); }
public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException { int initialDepth = parser.getDepth(); MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation")); String nick = parser.getAttributeValue("", "nick"); MUCRole role = MUCRole.fromString(parser.getAttributeValue("", "role")); String jid = parser.getAttributeValue("", "jid"); String actor = null; String reason = null; outerloop: while (true) { int eventType = parser.next(); switch (eventType) { case XmlPullParser.START_TAG: String name = parser.getName(); switch (name) { case "actor": actor = parser.getAttributeValue("", "jid"); break; case "reason": reason = parser.nextText(); break; } break; case XmlPullParser.END_TAG: if (parser.getDepth() == initialDepth) { break outerloop; } break; } } return new MUCItem(affiliation, role, actor, reason, jid, nick); }
Occupant(MUCItem item) { this.jid = item.getJid(); this.affiliation = item.getAffiliation(); this.role = item.getRole(); this.nick = item.getNick(); }
Affiliate(MUCItem item) { this.jid = item.getJid(); this.affiliation = item.getAffiliation(); this.role = item.getRole(); this.nick = item.getNick(); }