mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 10:37:59 +01:00
Introduce MUCRole and MUCAffiliation enums
Also rework MUCItem and parseItem to follow current coding guidelines.
This commit is contained in:
parent
754bdada18
commit
e19cfa4d83
7 changed files with 215 additions and 156 deletions
|
@ -28,15 +28,14 @@ import org.jivesoftware.smackx.muc.packet.MUCItem;
|
|||
*/
|
||||
public class Affiliate {
|
||||
// Fields that must have a value
|
||||
private String jid;
|
||||
private String affiliation;
|
||||
private final String jid;
|
||||
private final MUCAffiliation affiliation;
|
||||
|
||||
// Fields that may have a value
|
||||
private String role;
|
||||
private String nick;
|
||||
private final MUCRole role;
|
||||
private final String nick;
|
||||
|
||||
Affiliate(MUCItem item) {
|
||||
super();
|
||||
this.jid = item.getJid();
|
||||
this.affiliation = item.getAffiliation();
|
||||
this.role = item.getRole();
|
||||
|
@ -58,18 +57,18 @@ public class Affiliate {
|
|||
*
|
||||
* @return the affiliation of the afffiliated user.
|
||||
*/
|
||||
public String getAffiliation() {
|
||||
public MUCAffiliation getAffiliation() {
|
||||
return affiliation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current role of the affiliated user if the user is currently in the room.
|
||||
* If the user is not present in the room then the answer will be null.
|
||||
* If the user is not present in the room then the answer will be 'none'.
|
||||
*
|
||||
* @return the current role of the affiliated user in the room or null if the user is not in
|
||||
* the room.
|
||||
*/
|
||||
public String getRole() {
|
||||
public MUCRole getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2014 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* XEP-0045: Multi-User-Chat - 5.2 Affiliations
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0045.html#affil">XEP-0045: Multi-User-Chat - 5.2 Affiliations</a>
|
||||
*/
|
||||
public enum MUCAffiliation {
|
||||
|
||||
owner,
|
||||
admin,
|
||||
member,
|
||||
outcast,
|
||||
none;
|
||||
|
||||
public static MUCAffiliation fromString(String string) {
|
||||
if (string == null) {
|
||||
return null;
|
||||
}
|
||||
return MUCAffiliation.valueOf(string.toLowerCase(Locale.US));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2014 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* XEP-0045: Multi User Chat - 5.1 Roles
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0045.html#roles">XEP-0045: Multi-User-Chat - 5.1 Roles</a>
|
||||
*/
|
||||
public enum MUCRole {
|
||||
|
||||
moderator,
|
||||
none,
|
||||
participant,
|
||||
visitor;
|
||||
|
||||
public static MUCRole fromString(String string) {
|
||||
if (string == null) {
|
||||
return null;
|
||||
}
|
||||
return MUCRole.valueOf(string.toLowerCase(Locale.US));
|
||||
}
|
||||
}
|
|
@ -1018,7 +1018,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void kickParticipant(String nickname, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeRole(nickname, "none", reason);
|
||||
changeRole(nickname, MUCRole.none, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1035,7 +1035,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void grantVoice(Collection<String> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeRole(nicknames, "participant");
|
||||
changeRole(nicknames, MUCRole.participant);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1052,7 +1052,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void grantVoice(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeRole(nickname, "participant", null);
|
||||
changeRole(nickname, MUCRole.participant, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1069,7 +1069,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void revokeVoice(Collection<String> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeRole(nicknames, "visitor");
|
||||
changeRole(nicknames, MUCRole.visitor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1086,7 +1086,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void revokeVoice(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeRole(nickname, "visitor", null);
|
||||
changeRole(nickname, MUCRole.visitor, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1104,7 +1104,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void banUsers(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jids, "outcast");
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.outcast);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1123,7 +1123,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void banUser(String jid, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jid, "outcast", reason);
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.outcast, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1137,7 +1137,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void grantMembership(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jids, "member");
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.member);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1151,7 +1151,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void grantMembership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jid, "member", null);
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.member, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1166,7 +1166,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void revokeMembership(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jids, "none");
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.none);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1181,7 +1181,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void revokeMembership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jid, "none", null);
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.none, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1195,7 +1195,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void grantModerator(Collection<String> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeRole(nicknames, "moderator");
|
||||
changeRole(nicknames, MUCRole.moderator);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1209,7 +1209,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void grantModerator(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeRole(nickname, "moderator", null);
|
||||
changeRole(nickname, MUCRole.moderator, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1224,7 +1224,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void revokeModerator(Collection<String> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeRole(nicknames, "participant");
|
||||
changeRole(nicknames, MUCRole.participant);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1239,7 +1239,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void revokeModerator(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeRole(nickname, "participant", null);
|
||||
changeRole(nickname, MUCRole.participant, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1254,7 +1254,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void grantOwnership(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jids, "owner");
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.owner);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1269,7 +1269,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void grantOwnership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jid, "owner", null);
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.owner, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1283,7 +1283,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void revokeOwnership(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jids, "admin");
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.admin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1297,7 +1297,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void revokeOwnership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jid, "admin", null);
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.admin, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1311,7 +1311,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void grantAdmin(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jids, "admin");
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.admin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1326,7 +1326,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void grantAdmin(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jid, "admin");
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.admin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1340,7 +1340,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void revokeAdmin(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jids, "member");
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.admin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1355,7 +1355,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public void revokeAdmin(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException {
|
||||
changeAffiliationByAdmin(jid, "member");
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.member);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1367,7 +1367,7 @@ public class MultiUserChat {
|
|||
* @throws NoResponseException
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
private void changeAffiliationByAdmin(String jid, String affiliation)
|
||||
private void changeAffiliationByAdmin(String jid, MUCAffiliation affiliation)
|
||||
throws NoResponseException, XMPPErrorException,
|
||||
NotConnectedException {
|
||||
changeAffiliationByAdmin(jid, affiliation, null);
|
||||
|
@ -1383,56 +1383,50 @@ public class MultiUserChat {
|
|||
* @throws NoResponseException
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
private void changeAffiliationByAdmin(String jid, String affiliation, String reason) throws NoResponseException, XMPPErrorException, 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, null);
|
||||
item.setJid(jid);
|
||||
item.setReason(reason);
|
||||
MUCItem item = new MUCItem(affiliation, jid, reason);
|
||||
iq.addItem(item);
|
||||
|
||||
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||
}
|
||||
|
||||
private void changeAffiliationByAdmin(Collection<String> jids, String affiliation)
|
||||
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, null);
|
||||
item.setJid(jid);
|
||||
MUCItem item = new MUCItem(affiliation, jid);
|
||||
iq.addItem(item);
|
||||
}
|
||||
|
||||
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||
}
|
||||
|
||||
private void changeRole(String nickname, String role, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
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(null, role);
|
||||
item.setNick(nickname);
|
||||
item.setReason(reason);
|
||||
MUCItem item = new MUCItem(role, nickname, reason);
|
||||
iq.addItem(item);
|
||||
|
||||
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||
}
|
||||
|
||||
private void changeRole(Collection<String> nicknames, String role) throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
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(null, role);
|
||||
item.setNick(nickname);
|
||||
MUCItem item = new MUCItem(role, nickname);
|
||||
iq.addItem(item);
|
||||
}
|
||||
|
||||
|
@ -1532,7 +1526,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public Collection<Affiliate> getOwners() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
return getAffiliatesByAdmin("owner");
|
||||
return getAffiliatesByAdmin(MUCAffiliation.owner);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1544,7 +1538,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public Collection<Affiliate> getAdmins() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
return getAffiliatesByAdmin("admin");
|
||||
return getAffiliatesByAdmin(MUCAffiliation.admin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1556,7 +1550,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public Collection<Affiliate> getMembers() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
return getAffiliatesByAdmin("member");
|
||||
return getAffiliatesByAdmin(MUCAffiliation.member);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1568,7 +1562,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public Collection<Affiliate> getOutcasts() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
return getAffiliatesByAdmin("outcast");
|
||||
return getAffiliatesByAdmin(MUCAffiliation.outcast);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1581,12 +1575,12 @@ public class MultiUserChat {
|
|||
* @throws NoResponseException if there was no response from the server.
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
private Collection<Affiliate> getAffiliatesByAdmin(String affiliation) throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
private Collection<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, null);
|
||||
MUCItem item = new MUCItem(affiliation);
|
||||
iq.addItem(item);
|
||||
|
||||
MUCAdmin answer = (MUCAdmin) connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||
|
@ -1608,7 +1602,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public Collection<Occupant> getModerators() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
return getOccupants("moderator");
|
||||
return getOccupants(MUCRole.moderator);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1620,7 +1614,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public Collection<Occupant> getParticipants() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
return getOccupants("participant");
|
||||
return getOccupants(MUCRole.participant);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1633,12 +1627,12 @@ public class MultiUserChat {
|
|||
* @throws NoResponseException if there was no response from the server.
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
private Collection<Occupant> getOccupants(String role) throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
private Collection<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(null, role);
|
||||
MUCItem item = new MUCItem(role);
|
||||
iq.addItem(item);
|
||||
|
||||
MUCAdmin answer = (MUCAdmin) connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||
|
@ -1945,12 +1939,12 @@ public class MultiUserChat {
|
|||
if (oldPresence != null) {
|
||||
// Get the previous occupant's affiliation & role
|
||||
MUCUser mucExtension = MUCUser.getFrom(packet);
|
||||
String oldAffiliation = mucExtension.getItem().getAffiliation();
|
||||
String oldRole = mucExtension.getItem().getRole();
|
||||
MUCAffiliation oldAffiliation = mucExtension.getItem().getAffiliation();
|
||||
MUCRole oldRole = mucExtension.getItem().getRole();
|
||||
// Get the new occupant's affiliation & role
|
||||
mucExtension = MUCUser.getFrom(packet);
|
||||
String newAffiliation = mucExtension.getItem().getAffiliation();
|
||||
String newRole = mucExtension.getItem().getRole();
|
||||
MUCAffiliation newAffiliation = mucExtension.getItem().getAffiliation();
|
||||
MUCRole newRole = mucExtension.getItem().getRole();
|
||||
// Fire role modification events
|
||||
checkRoleModifications(oldRole, newRole, isUserStatusModification, from);
|
||||
// Fire affiliation modification events
|
||||
|
@ -2054,8 +2048,8 @@ public class MultiUserChat {
|
|||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
private void checkRoleModifications(
|
||||
String oldRole,
|
||||
String newRole,
|
||||
MUCRole oldRole,
|
||||
MUCRole newRole,
|
||||
boolean isUserModification,
|
||||
String from) {
|
||||
// Voice was granted to a visitor
|
||||
|
@ -2168,8 +2162,8 @@ public class MultiUserChat {
|
|||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
private void checkAffiliationModifications(
|
||||
String oldAffiliation,
|
||||
String newAffiliation,
|
||||
MUCAffiliation oldAffiliation,
|
||||
MUCAffiliation newAffiliation,
|
||||
boolean isUserModification,
|
||||
String from) {
|
||||
// First check for revoked affiliation and then for granted affiliations. The idea is to
|
||||
|
|
|
@ -30,11 +30,11 @@ import org.jxmpp.util.XmppStringUtils;
|
|||
*/
|
||||
public class Occupant {
|
||||
// Fields that must have a value
|
||||
private String affiliation;
|
||||
private String role;
|
||||
private final MUCAffiliation affiliation;
|
||||
private final MUCRole role;
|
||||
// Fields that may have a value
|
||||
private String jid;
|
||||
private String nick;
|
||||
private final String jid;
|
||||
private final String nick;
|
||||
|
||||
Occupant(MUCItem item) {
|
||||
this.jid = item.getJid();
|
||||
|
@ -72,7 +72,7 @@ public class Occupant {
|
|||
*
|
||||
* @return the affiliation of the occupant.
|
||||
*/
|
||||
public String getAffiliation() {
|
||||
public MUCAffiliation getAffiliation() {
|
||||
return affiliation;
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class Occupant {
|
|||
*
|
||||
* @return the current role of the occupant in the room.
|
||||
*/
|
||||
public String getRole() {
|
||||
public MUCRole getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.jivesoftware.smackx.muc.packet;
|
|||
import org.jivesoftware.smack.packet.Element;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smackx.muc.MUCAffiliation;
|
||||
import org.jivesoftware.smackx.muc.MUCRole;
|
||||
|
||||
/**
|
||||
* Item child that holds information about roles, affiliation, jids and nicks.
|
||||
|
@ -28,20 +30,35 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
|||
public class MUCItem implements Element {
|
||||
public static final String ELEMENT = IQ.ITEM;
|
||||
|
||||
private final String affiliation;
|
||||
private String role;
|
||||
private String actor;
|
||||
private String reason;
|
||||
private String jid;
|
||||
private String nick;
|
||||
private final MUCAffiliation affiliation;
|
||||
private final MUCRole role;
|
||||
private final String actor;
|
||||
private final String reason;
|
||||
private final String jid;
|
||||
private final String nick;
|
||||
|
||||
/**
|
||||
* Creates a new item child.
|
||||
*
|
||||
* @param affiliation the actor's affiliation to the room
|
||||
*/
|
||||
public MUCItem(String affiliation) {
|
||||
this.affiliation = affiliation;
|
||||
public MUCItem(MUCAffiliation affiliation) {
|
||||
this(affiliation, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public MUCItem(MUCRole role) {
|
||||
this(null, role, null, null, null, null);
|
||||
}
|
||||
|
||||
public MUCItem(MUCRole role, String nick) {
|
||||
this(null, role, null, null, null, nick);
|
||||
}
|
||||
|
||||
public MUCItem(MUCAffiliation affiliation, String jid, String reason) {
|
||||
this(affiliation, null, null, reason, jid, null);
|
||||
}
|
||||
|
||||
public MUCItem(MUCAffiliation affiliation, String jid) {
|
||||
this(affiliation, null, null, null, jid, null);
|
||||
}
|
||||
|
||||
public MUCItem(MUCRole role, String nick, String reason) {
|
||||
this(null, role, null, reason, null, nick);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,10 +66,19 @@ public class MUCItem implements Element {
|
|||
*
|
||||
* @param affiliation the actor's affiliation to the room
|
||||
* @param role the privilege level of an occupant within a room.
|
||||
* @param actor
|
||||
* @param reason
|
||||
* @param jid
|
||||
* @param nick
|
||||
*/
|
||||
public MUCItem(String affiliation, String role) {
|
||||
this(affiliation);
|
||||
public MUCItem(MUCAffiliation affiliation, MUCRole role, String actor,
|
||||
String reason, String jid, String nick) {
|
||||
this.affiliation = affiliation;
|
||||
this.role = role;
|
||||
this.actor = actor;
|
||||
this.reason = reason;
|
||||
this.jid = jid;
|
||||
this.nick = nick;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +108,7 @@ public class MUCItem implements Element {
|
|||
*
|
||||
* @return the actor's affiliation to the room
|
||||
*/
|
||||
public String getAffiliation() {
|
||||
public MUCAffiliation getAffiliation() {
|
||||
return affiliation;
|
||||
}
|
||||
|
||||
|
@ -108,71 +134,23 @@ public class MUCItem implements Element {
|
|||
|
||||
/**
|
||||
* Returns the temporary position or privilege level of an occupant within a room. The possible
|
||||
* roles are "moderator", "participant", and "visitor" (it is also possible to have no defined
|
||||
* roles are "moderator", "participant", "visitor" and "none" (it is also possible to have no defined
|
||||
* role). A role lasts only for the duration of an occupant's visit to a room.
|
||||
*
|
||||
* @return the privilege level of an occupant within a room.
|
||||
*/
|
||||
public String getRole() {
|
||||
public MUCRole getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the actor (JID of an occupant in the room) that was kicked or banned.
|
||||
*
|
||||
* @param actor the actor (JID of an occupant in the room) that was kicked or banned.
|
||||
*/
|
||||
public void setActor(String actor) {
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the reason for the item child. The reason is optional and could be used to explain the
|
||||
* reason why a user (occupant) was kicked or banned.
|
||||
*
|
||||
* @param reason the reason why a user (occupant) was kicked or banned.
|
||||
*/
|
||||
public void setReason(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the <room@service/nick> by which an occupant is identified within the context of a room.
|
||||
* If the room is non-anonymous, the JID will be included in the item.
|
||||
*
|
||||
* @param jid the JID by which an occupant is identified within a room.
|
||||
*/
|
||||
public void setJid(String jid) {
|
||||
this.jid = jid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new nickname of an occupant that is changing his/her nickname. The new nickname is
|
||||
* sent as part of the unavailable presence.
|
||||
*
|
||||
* @param nick the new nickname of an occupant that is changing his/her nickname.
|
||||
*/
|
||||
public void setNick(String nick) {
|
||||
this.nick = nick;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temporary position or privilege level of an occupant within a room. The possible
|
||||
* roles are "moderator", "participant", and "visitor" (it is also possible to have no defined
|
||||
* role). A role lasts only for the duration of an occupant's visit to a room.
|
||||
*
|
||||
* @param role the new privilege level of an occupant within a room.
|
||||
*/
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public XmlStringBuilder toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
xml.optAttribute("affiliation", getAffiliation());
|
||||
xml.optAttribute("jid", getJid());
|
||||
xml.optAttribute("nick", getNick());
|
||||
xml.optAttribute("role", getRole());
|
||||
if (role != MUCRole.none) {
|
||||
xml.attribute("role", getRole());
|
||||
}
|
||||
xml.rightAngleBracket();
|
||||
xml.optElement("reason", getReason());
|
||||
if (getActor() != null) {
|
||||
|
|
|
@ -16,34 +16,42 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.muc.provider;
|
||||
|
||||
import org.jivesoftware.smackx.muc.MUCAffiliation;
|
||||
import org.jivesoftware.smackx.muc.MUCRole;
|
||||
import org.jivesoftware.smackx.muc.packet.Destroy;
|
||||
import org.jivesoftware.smackx.muc.packet.MUCItem;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class MUCParserUtils {
|
||||
public static MUCItem parseItem(XmlPullParser parser) throws Exception {
|
||||
boolean done = false;
|
||||
MUCItem item = new MUCItem(parser.getAttributeValue("", "affiliation"));
|
||||
item.setNick(parser.getAttributeValue("", "nick"));
|
||||
item.setRole(parser.getAttributeValue("", "role"));
|
||||
item.setJid(parser.getAttributeValue("", "jid"));
|
||||
while (!done) {
|
||||
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();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (parser.getName().equals("actor")) {
|
||||
item.setActor(parser.getAttributeValue("", "jid"));
|
||||
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;
|
||||
}
|
||||
if (parser.getName().equals("reason")) {
|
||||
item.setReason(parser.nextText());
|
||||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals("item")) {
|
||||
done = true;
|
||||
case XmlPullParser.END_TAG:
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return item;
|
||||
return new MUCItem(affiliation, role, actor, reason, jid, nick);
|
||||
}
|
||||
|
||||
public static Destroy parseDestroy(XmlPullParser parser) throws Exception {
|
||||
|
|
Loading…
Reference in a new issue