mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-14 06:51:08 +01:00
Use Jid (and subclasses) from jxmpp-jid
Fixes SMACK-634
This commit is contained in:
parent
0ee2d9ed1e
commit
5bb4727c57
180 changed files with 1510 additions and 1032 deletions
|
|
@ -18,6 +18,8 @@
|
|||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jivesoftware.smackx.muc.packet.MUCItem;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.parts.Resourcepart;
|
||||
|
||||
/**
|
||||
* Represents an affiliation of a user to a given room. The affiliate's information will always have
|
||||
|
|
@ -28,12 +30,12 @@ import org.jivesoftware.smackx.muc.packet.MUCItem;
|
|||
*/
|
||||
public class Affiliate {
|
||||
// Fields that must have a value
|
||||
private final String jid;
|
||||
private final Jid jid;
|
||||
private final MUCAffiliation affiliation;
|
||||
|
||||
// Fields that may have a value
|
||||
private final MUCRole role;
|
||||
private final String nick;
|
||||
private final Resourcepart nick;
|
||||
|
||||
Affiliate(MUCItem item) {
|
||||
this.jid = item.getJid();
|
||||
|
|
@ -47,7 +49,7 @@ public class Affiliate {
|
|||
*
|
||||
* @return the bare JID of the affiliated user.
|
||||
*/
|
||||
public String getJid() {
|
||||
public Jid getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +81,7 @@ public class Affiliate {
|
|||
* @return the current nickname of the affiliated user in the room or null if the user is not in
|
||||
* the room.
|
||||
*/
|
||||
public String getNick() {
|
||||
public Resourcepart getNick() {
|
||||
return nick;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@
|
|||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.parts.Resourcepart;
|
||||
|
||||
/**
|
||||
* Default implementation of the ParticipantStatusListener interface.<p>
|
||||
*
|
||||
|
|
@ -28,49 +32,49 @@ package org.jivesoftware.smackx.muc;
|
|||
*/
|
||||
public class DefaultParticipantStatusListener implements ParticipantStatusListener {
|
||||
|
||||
public void joined(String participant) {
|
||||
public void joined(FullJid participant) {
|
||||
}
|
||||
|
||||
public void left(String participant) {
|
||||
public void left(FullJid participant) {
|
||||
}
|
||||
|
||||
public void kicked(String participant, String actor, String reason) {
|
||||
public void kicked(FullJid participant, Jid actor, String reason) {
|
||||
}
|
||||
|
||||
public void voiceGranted(String participant) {
|
||||
public void voiceGranted(FullJid participant) {
|
||||
}
|
||||
|
||||
public void voiceRevoked(String participant) {
|
||||
public void voiceRevoked(FullJid participant) {
|
||||
}
|
||||
|
||||
public void banned(String participant, String actor, String reason) {
|
||||
public void banned(FullJid participant, Jid actor, String reason) {
|
||||
}
|
||||
|
||||
public void membershipGranted(String participant) {
|
||||
public void membershipGranted(FullJid participant) {
|
||||
}
|
||||
|
||||
public void membershipRevoked(String participant) {
|
||||
public void membershipRevoked(FullJid participant) {
|
||||
}
|
||||
|
||||
public void moderatorGranted(String participant) {
|
||||
public void moderatorGranted(FullJid participant) {
|
||||
}
|
||||
|
||||
public void moderatorRevoked(String participant) {
|
||||
public void moderatorRevoked(FullJid participant) {
|
||||
}
|
||||
|
||||
public void ownershipGranted(String participant) {
|
||||
public void ownershipGranted(FullJid participant) {
|
||||
}
|
||||
|
||||
public void ownershipRevoked(String participant) {
|
||||
public void ownershipRevoked(FullJid participant) {
|
||||
}
|
||||
|
||||
public void adminGranted(String participant) {
|
||||
public void adminGranted(FullJid participant) {
|
||||
}
|
||||
|
||||
public void adminRevoked(String participant) {
|
||||
public void adminRevoked(FullJid participant) {
|
||||
}
|
||||
|
||||
public void nicknameChanged(String participant, String newNickname) {
|
||||
public void nicknameChanged(FullJid participant, Resourcepart newNickname) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* Default implementation of the UserStatusListener interface.<p>
|
||||
*
|
||||
|
|
@ -28,7 +30,7 @@ package org.jivesoftware.smackx.muc;
|
|||
*/
|
||||
public class DefaultUserStatusListener implements UserStatusListener {
|
||||
|
||||
public void kicked(String actor, String reason) {
|
||||
public void kicked(Jid actor, String reason) {
|
||||
}
|
||||
|
||||
public void voiceGranted() {
|
||||
|
|
@ -37,7 +39,7 @@ public class DefaultUserStatusListener implements UserStatusListener {
|
|||
public void voiceRevoked() {
|
||||
}
|
||||
|
||||
public void banned(String actor, String reason) {
|
||||
public void banned(Jid actor, String reason) {
|
||||
}
|
||||
|
||||
public void membershipGranted() {
|
||||
|
|
|
|||
|
|
@ -17,21 +17,22 @@
|
|||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* Hosted rooms by a chat service may be discovered if they are configured to appear in the room
|
||||
* directory . The information that may be discovered is the XMPP address of the room and the room
|
||||
* name. The address of the room may be used for obtaining more detailed information
|
||||
* {@link org.jivesoftware.smackx.muc.MultiUserChatManager#getRoomInfo(String)}
|
||||
* {@link org.jivesoftware.smackx.muc.MultiUserChatManager#getRoomInfo(org.jxmpp.jid.BareJid)}
|
||||
* or could be used for joining the room
|
||||
* {@link org.jivesoftware.smackx.muc.MultiUserChatManager#getMultiUserChat(String)}
|
||||
* and {@link org.jivesoftware.smackx.muc.MultiUserChat#join(String)}.
|
||||
* {@link org.jivesoftware.smackx.muc.MultiUserChatManager#getMultiUserChat(org.jxmpp.jid.BareJid)}
|
||||
* and {@link org.jivesoftware.smackx.muc.MultiUserChat#join(org.jxmpp.jid.parts.Resourcepart)}.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class HostedRoom {
|
||||
|
||||
private final String jid;
|
||||
private final Jid jid;
|
||||
|
||||
private final String name;
|
||||
|
||||
|
|
@ -46,7 +47,7 @@ public class HostedRoom {
|
|||
*
|
||||
* @return the XMPP address of the hosted room by the chat service.
|
||||
*/
|
||||
public String getJid() {
|
||||
public Jid getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ package org.jivesoftware.smackx.muc;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
|
@ -69,9 +67,15 @@ import org.jivesoftware.smackx.muc.packet.MUCUser.Status;
|
|||
import org.jivesoftware.smackx.xdata.Form;
|
||||
import org.jivesoftware.smackx.xdata.FormField;
|
||||
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.JidWithLocalpart;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.jid.parts.Resourcepart;
|
||||
|
||||
/**
|
||||
* A MultiUserChat room (XEP-45), created with {@link MultiUserChatManager#getMultiUserChat(String)}.
|
||||
* A MultiUserChat room (XEP-45), created with {@link MultiUserChatManager#getMultiUserChat(BareJid)}.
|
||||
* <p>
|
||||
* A MultiUserChat is a conversation that takes place among many users in a virtual
|
||||
* room. A room could have many occupants with different affiliation and roles.
|
||||
|
|
@ -91,9 +95,9 @@ public class MultiUserChat {
|
|||
private static final Logger LOGGER = Logger.getLogger(MultiUserChat.class.getName());
|
||||
|
||||
private final XMPPConnection connection;
|
||||
private final String room;
|
||||
private final BareJid room;
|
||||
private final MultiUserChatManager multiUserChatManager;
|
||||
private final Map<String, Presence> occupantsMap = new ConcurrentHashMap<String, Presence>();
|
||||
private final Map<FullJid, Presence> occupantsMap = new ConcurrentHashMap<>();
|
||||
|
||||
private final Set<InvitationRejectionListener> invitationRejectionListeners = new CopyOnWriteArraySet<InvitationRejectionListener>();
|
||||
private final Set<SubjectUpdatedListener> subjectUpdatedListeners = new CopyOnWriteArraySet<SubjectUpdatedListener>();
|
||||
|
|
@ -122,13 +126,13 @@ public class MultiUserChat {
|
|||
private final PacketListener declinesListener;
|
||||
|
||||
private String subject;
|
||||
private String nickname = null;
|
||||
private Resourcepart nickname;
|
||||
private boolean joined = false;
|
||||
private PacketCollector messageCollector;
|
||||
|
||||
MultiUserChat(XMPPConnection connection, String room, MultiUserChatManager multiUserChatManager) {
|
||||
MultiUserChat(XMPPConnection connection, BareJid room, MultiUserChatManager multiUserChatManager) {
|
||||
this.connection = connection;
|
||||
this.room = room.toLowerCase(Locale.US);
|
||||
this.room = room;
|
||||
this.multiUserChatManager = multiUserChatManager;
|
||||
|
||||
fromRoomFilter = FromMatchesFilter.create(room);
|
||||
|
|
@ -148,11 +152,16 @@ public class MultiUserChat {
|
|||
subjectListener = new PacketListener() {
|
||||
public void processPacket(Stanza packet) {
|
||||
Message msg = (Message) packet;
|
||||
FullJid from = msg.getFrom().asFullJidIfPossible();
|
||||
if (from == null) {
|
||||
LOGGER.warning("Message subject not changed by a full JID: " + msg.getFrom());
|
||||
return;
|
||||
}
|
||||
// Update the room subject
|
||||
subject = msg.getSubject();
|
||||
// Fire event for subject updated listeners
|
||||
for (SubjectUpdatedListener listener : subjectUpdatedListeners) {
|
||||
listener.subjectUpdated(subject, msg.getFrom());
|
||||
listener.subjectUpdated(subject, from);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -161,7 +170,11 @@ public class MultiUserChat {
|
|||
presenceListener = new PacketListener() {
|
||||
public void processPacket(Stanza packet) {
|
||||
Presence presence = (Presence) packet;
|
||||
String from = presence.getFrom();
|
||||
final FullJid from = presence.getFrom().asFullJidIfPossible();
|
||||
if (from == null) {
|
||||
LOGGER.warning("Presence not from a full JID: " + presence.getFrom());
|
||||
return;
|
||||
}
|
||||
String myRoomJID = MultiUserChat.this.room + "/" + nickname;
|
||||
boolean isUserStatusModification = presence.getFrom().equals(myRoomJID);
|
||||
switch (presence.getType()) {
|
||||
|
|
@ -254,7 +267,7 @@ public class MultiUserChat {
|
|||
*
|
||||
* @return the multi user chat room name.
|
||||
*/
|
||||
public String getRoom() {
|
||||
public BareJid getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
|
|
@ -272,14 +285,15 @@ public class MultiUserChat {
|
|||
* @throws InterruptedException
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0045.html#enter">XEP-45 7.2 Entering a Room</a>
|
||||
*/
|
||||
private Presence enter(String nickname, String password, DiscussionHistory history,
|
||||
private Presence enter(Resourcepart nickname, String password, DiscussionHistory history,
|
||||
long timeout) throws NotConnectedException, NoResponseException,
|
||||
XMPPErrorException, InterruptedException {
|
||||
StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank.");
|
||||
// We enter a room by sending a presence packet where the "to"
|
||||
// field is in the form "roomName@service/nickname"
|
||||
Presence joinPresence = new Presence(Presence.Type.available);
|
||||
joinPresence.setTo(room + "/" + nickname);
|
||||
final FullJid jid = JidCreate.fullFrom(room, nickname);
|
||||
joinPresence.setTo(jid);
|
||||
|
||||
// Indicate the the client supports MUC
|
||||
MUCInitialPresence mucInitialPresence = new MUCInitialPresence();
|
||||
|
|
@ -292,8 +306,7 @@ public class MultiUserChat {
|
|||
joinPresence.addExtension(mucInitialPresence);
|
||||
|
||||
// Wait for a presence packet back from the server.
|
||||
PacketFilter responseFilter = new AndFilter(FromMatchesFilter.createFull(room + "/"
|
||||
+ nickname), new PacketTypeFilter(Presence.class));
|
||||
PacketFilter responseFilter = new AndFilter(FromMatchesFilter.createFull(jid), new PacketTypeFilter(Presence.class));
|
||||
|
||||
// Setup the messageListeners and presenceListeners *before* the join presence is send.
|
||||
connection.addSyncPacketListener(messageListener, fromRoomGroupchatFilter);
|
||||
|
|
@ -348,7 +361,7 @@ public class MultiUserChat {
|
|||
* server, e.g. because the room already existed.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public synchronized void create(String nickname) throws NoResponseException, XMPPErrorException, SmackException, InterruptedException {
|
||||
public synchronized void create(Resourcepart nickname) throws NoResponseException, XMPPErrorException, SmackException, InterruptedException {
|
||||
if (joined) {
|
||||
throw new IllegalStateException("Creation failed - User already joined the room.");
|
||||
}
|
||||
|
|
@ -363,7 +376,7 @@ public class MultiUserChat {
|
|||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #createOrJoin(String, String, DiscussionHistory, long)}, but without a password, specifying a
|
||||
* Same as {@link #createOrJoin(Resourcepart, String, DiscussionHistory, long)}, but without a password, specifying a
|
||||
* discussion history and using the connections default reply timeout.
|
||||
*
|
||||
* @param nickname
|
||||
|
|
@ -372,15 +385,15 @@ public class MultiUserChat {
|
|||
* @throws XMPPErrorException
|
||||
* @throws SmackException
|
||||
* @throws InterruptedException
|
||||
* @see #createOrJoin(String, String, DiscussionHistory, long)
|
||||
* @see #createOrJoin(Resourcepart, String, DiscussionHistory, long)
|
||||
*/
|
||||
public synchronized boolean createOrJoin(String nickname) throws NoResponseException, XMPPErrorException,
|
||||
public synchronized boolean createOrJoin(Resourcepart nickname) throws NoResponseException, XMPPErrorException,
|
||||
SmackException, InterruptedException {
|
||||
return createOrJoin(nickname, null, null, connection.getPacketReplyTimeout());
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link #create(String)}, but will return true if the room creation was acknowledged by
|
||||
* Like {@link #create(Resourcepart)}, but will return true if the room creation was acknowledged by
|
||||
* the service (with an 201 status code). It's up to the caller to decide, based on the return
|
||||
* value, if he needs to continue sending the room configuration. If false is returned, the room
|
||||
* already existed and the user is able to join right away, without sending a form.
|
||||
|
|
@ -395,7 +408,7 @@ public class MultiUserChat {
|
|||
* @throws NoResponseException if there was no response from the server.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public synchronized boolean createOrJoin(String nickname, String password, DiscussionHistory history, long timeout)
|
||||
public synchronized boolean createOrJoin(Resourcepart nickname, String password, DiscussionHistory history, long timeout)
|
||||
throws NoResponseException, XMPPErrorException, SmackException, InterruptedException {
|
||||
if (joined) {
|
||||
throw new IllegalStateException("Creation failed - User already joined the room.");
|
||||
|
|
@ -431,7 +444,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void join(String nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public void join(Resourcepart nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
join(nickname, null, null, connection.getPacketReplyTimeout());
|
||||
}
|
||||
|
||||
|
|
@ -456,7 +469,7 @@ public class MultiUserChat {
|
|||
* @throws SmackException if there was no response from the server.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void join(String nickname, String password) throws XMPPErrorException, SmackException, InterruptedException {
|
||||
public void join(Resourcepart nickname, String password) throws XMPPErrorException, SmackException, InterruptedException {
|
||||
join(nickname, password, null, connection.getPacketReplyTimeout());
|
||||
}
|
||||
|
||||
|
|
@ -489,7 +502,7 @@ public class MultiUserChat {
|
|||
* @throws InterruptedException
|
||||
*/
|
||||
public synchronized void join(
|
||||
String nickname,
|
||||
Resourcepart nickname,
|
||||
String password,
|
||||
DiscussionHistory history,
|
||||
long timeout)
|
||||
|
|
@ -504,7 +517,7 @@ public class MultiUserChat {
|
|||
|
||||
/**
|
||||
* Returns true if currently in the multi user chat (after calling the {@link
|
||||
* #join(String)} method).
|
||||
* #join(Resourcepart)} method).
|
||||
*
|
||||
* @return true if currently in the multi user chat room.
|
||||
*/
|
||||
|
|
@ -525,7 +538,7 @@ public class MultiUserChat {
|
|||
// We leave a room by sending a presence packet where the "to"
|
||||
// field is in the form "roomName@service/nickname"
|
||||
Presence leavePresence = new Presence(Presence.Type.unavailable);
|
||||
leavePresence.setTo(room + "/" + nickname);
|
||||
leavePresence.setTo(JidCreate.fullFrom(room, nickname));
|
||||
connection.sendPacket(leavePresence);
|
||||
// Reset occupant information.
|
||||
occupantsMap.clear();
|
||||
|
|
@ -841,7 +854,7 @@ public class MultiUserChat {
|
|||
*
|
||||
* @return the nickname currently being used.
|
||||
*/
|
||||
public String getNickname() {
|
||||
public Resourcepart getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
|
|
@ -858,23 +871,24 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void changeNickname(String nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public void changeNickname(Resourcepart nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank.");
|
||||
// Check that we already have joined the room before attempting to change the
|
||||
// nickname.
|
||||
if (!joined) {
|
||||
throw new IllegalStateException("Must be logged into the room to change nickname.");
|
||||
}
|
||||
final FullJid jid = JidCreate.fullFrom(room, nickname);
|
||||
// We change the nickname by sending a presence packet where the "to"
|
||||
// field is in the form "roomName@service/nickname"
|
||||
// We don't have to signal the MUC support again
|
||||
Presence joinPresence = new Presence(Presence.Type.available);
|
||||
joinPresence.setTo(room + "/" + nickname);
|
||||
joinPresence.setTo(jid);
|
||||
|
||||
// Wait for a presence packet back from the server.
|
||||
PacketFilter responseFilter =
|
||||
new AndFilter(
|
||||
FromMatchesFilter.createFull(room + "/" + nickname),
|
||||
FromMatchesFilter.createFull(jid),
|
||||
new PacketTypeFilter(Presence.class));
|
||||
PacketCollector response = connection.createPacketCollectorAndSend(responseFilter, joinPresence);
|
||||
// Wait up to a certain number of seconds for a reply. If there is a negative reply, an
|
||||
|
|
@ -907,7 +921,7 @@ public class MultiUserChat {
|
|||
Presence joinPresence = new Presence(Presence.Type.available);
|
||||
joinPresence.setStatus(status);
|
||||
joinPresence.setMode(mode);
|
||||
joinPresence.setTo(room + "/" + nickname);
|
||||
joinPresence.setTo(JidCreate.fullFrom(room, nickname));
|
||||
|
||||
// Send join packet.
|
||||
connection.sendPacket(joinPresence);
|
||||
|
|
@ -934,7 +948,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void kickParticipant(String nickname, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void kickParticipant(Resourcepart nickname, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeRole(nickname, MUCRole.none, reason);
|
||||
}
|
||||
|
||||
|
|
@ -976,7 +990,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void grantVoice(Collection<String> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantVoice(Collection<Resourcepart> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeRole(nicknames, MUCRole.participant);
|
||||
}
|
||||
|
||||
|
|
@ -994,7 +1008,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void grantVoice(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantVoice(Resourcepart nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeRole(nickname, MUCRole.participant, null);
|
||||
}
|
||||
|
||||
|
|
@ -1012,7 +1026,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void revokeVoice(Collection<String> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeVoice(Collection<Resourcepart> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeRole(nicknames, MUCRole.visitor);
|
||||
}
|
||||
|
||||
|
|
@ -1030,7 +1044,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void revokeVoice(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeVoice(Resourcepart nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeRole(nickname, MUCRole.visitor, null);
|
||||
}
|
||||
|
||||
|
|
@ -1049,7 +1063,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void banUsers(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void banUsers(Collection<? extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.outcast);
|
||||
}
|
||||
|
||||
|
|
@ -1069,7 +1083,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void banUser(String jid, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void banUser(Jid jid, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.outcast, reason);
|
||||
}
|
||||
|
||||
|
|
@ -1084,7 +1098,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void grantMembership(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantMembership(Collection<? extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.member);
|
||||
}
|
||||
|
||||
|
|
@ -1099,7 +1113,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void grantMembership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantMembership(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.member, null);
|
||||
}
|
||||
|
||||
|
|
@ -1115,7 +1129,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void revokeMembership(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeMembership(Collection<? extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.none);
|
||||
}
|
||||
|
||||
|
|
@ -1131,7 +1145,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void revokeMembership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeMembership(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.none, null);
|
||||
}
|
||||
|
||||
|
|
@ -1146,7 +1160,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void grantModerator(Collection<String> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantModerator(Collection<Resourcepart> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeRole(nicknames, MUCRole.moderator);
|
||||
}
|
||||
|
||||
|
|
@ -1161,7 +1175,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void grantModerator(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantModerator(Resourcepart nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeRole(nickname, MUCRole.moderator, null);
|
||||
}
|
||||
|
||||
|
|
@ -1177,7 +1191,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void revokeModerator(Collection<String> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeModerator(Collection<Resourcepart> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeRole(nicknames, MUCRole.participant);
|
||||
}
|
||||
|
||||
|
|
@ -1193,7 +1207,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void revokeModerator(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeModerator(Resourcepart nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeRole(nickname, MUCRole.participant, null);
|
||||
}
|
||||
|
||||
|
|
@ -1209,7 +1223,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void grantOwnership(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantOwnership(Collection<? extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.owner);
|
||||
}
|
||||
|
||||
|
|
@ -1225,7 +1239,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void grantOwnership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantOwnership(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.owner, null);
|
||||
}
|
||||
|
||||
|
|
@ -1240,7 +1254,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void revokeOwnership(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeOwnership(Collection<? extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.admin);
|
||||
}
|
||||
|
||||
|
|
@ -1255,7 +1269,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void revokeOwnership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeOwnership(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.admin, null);
|
||||
}
|
||||
|
||||
|
|
@ -1270,7 +1284,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void grantAdmin(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantAdmin(Collection<? extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.admin);
|
||||
}
|
||||
|
||||
|
|
@ -1286,7 +1300,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void grantAdmin(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantAdmin(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.admin);
|
||||
}
|
||||
|
||||
|
|
@ -1301,7 +1315,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void revokeAdmin(Collection<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeAdmin(Collection<? extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jids, MUCAffiliation.admin);
|
||||
}
|
||||
|
||||
|
|
@ -1317,7 +1331,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void revokeAdmin(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeAdmin(JidWithLocalpart jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jid, MUCAffiliation.member);
|
||||
}
|
||||
|
||||
|
|
@ -1331,7 +1345,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
private void changeAffiliationByAdmin(String jid, MUCAffiliation affiliation)
|
||||
private void changeAffiliationByAdmin(Jid jid, MUCAffiliation affiliation)
|
||||
throws NoResponseException, XMPPErrorException,
|
||||
NotConnectedException, InterruptedException {
|
||||
changeAffiliationByAdmin(jid, affiliation, null);
|
||||
|
|
@ -1348,7 +1362,7 @@ public class MultiUserChat {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
private void changeAffiliationByAdmin(String jid, MUCAffiliation affiliation, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
|
||||
private void changeAffiliationByAdmin(Jid jid, MUCAffiliation affiliation, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
|
||||
{
|
||||
MUCAdmin iq = new MUCAdmin();
|
||||
iq.setTo(room);
|
||||
|
|
@ -1360,12 +1374,12 @@ public class MultiUserChat {
|
|||
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||
}
|
||||
|
||||
private void changeAffiliationByAdmin(Collection<String> jids, MUCAffiliation affiliation)
|
||||
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 (String jid : jids) {
|
||||
for (Jid jid : jids) {
|
||||
// Set the new affiliation.
|
||||
MUCItem item = new MUCItem(affiliation, jid);
|
||||
iq.addItem(item);
|
||||
|
|
@ -1374,7 +1388,7 @@ public class MultiUserChat {
|
|||
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||
}
|
||||
|
||||
private void changeRole(String nickname, MUCRole role, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
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);
|
||||
|
|
@ -1385,11 +1399,11 @@ public class MultiUserChat {
|
|||
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||
}
|
||||
|
||||
private void changeRole(Collection<String> nicknames, MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
private void changeRole(Collection<Resourcepart> nicknames, MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
MUCAdmin iq = new MUCAdmin();
|
||||
iq.setTo(room);
|
||||
iq.setType(IQ.Type.set);
|
||||
for (String nickname : nicknames) {
|
||||
for (Resourcepart nickname : nicknames) {
|
||||
// Set the new role.
|
||||
MUCItem item = new MUCItem(role, nickname);
|
||||
iq.addItem(item);
|
||||
|
|
@ -1413,7 +1427,7 @@ public class MultiUserChat {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an Iterator (of Strings) for the list of fully qualified occupants
|
||||
* Returns an List for the list of fully qualified occupants
|
||||
* in the group chat. For example, "conference@chat.jivesoftware.com/SomeUser".
|
||||
* Typically, a client would only display the nickname of the occupant. To
|
||||
* get the nickname from the fully qualified name, use the
|
||||
|
|
@ -1423,8 +1437,8 @@ public class MultiUserChat {
|
|||
*
|
||||
* @return a List of the occupants in the group chat.
|
||||
*/
|
||||
public List<String> getOccupants() {
|
||||
return Collections.unmodifiableList(new ArrayList<String>(occupantsMap.keySet()));
|
||||
public List<FullJid> getOccupants() {
|
||||
return new ArrayList<>(occupantsMap.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1642,7 +1656,7 @@ public class MultiUserChat {
|
|||
* created chat.
|
||||
* @return new Chat for sending private messages to a given room occupant.
|
||||
*/
|
||||
public Chat createPrivateChat(String occupant, ChatMessageListener listener) {
|
||||
public Chat createPrivateChat(FullJid occupant, ChatMessageListener listener) {
|
||||
return ChatManager.getInstanceFor(connection).createChat(occupant, listener);
|
||||
}
|
||||
|
||||
|
|
@ -1884,7 +1898,7 @@ public class MultiUserChat {
|
|||
MUCRole oldRole,
|
||||
MUCRole newRole,
|
||||
boolean isUserModification,
|
||||
String from) {
|
||||
FullJid from) {
|
||||
// Voice was granted to a visitor
|
||||
if (("visitor".equals(oldRole) || "none".equals(oldRole))
|
||||
&& "participant".equals(newRole)) {
|
||||
|
|
@ -2010,7 +2024,7 @@ public class MultiUserChat {
|
|||
MUCAffiliation oldAffiliation,
|
||||
MUCAffiliation newAffiliation,
|
||||
boolean isUserModification,
|
||||
String from) {
|
||||
FullJid from) {
|
||||
// First check for revoked affiliation and then for granted affiliations. The idea is to
|
||||
// first fire the "revoke" events and then fire the "grant" events.
|
||||
|
||||
|
|
@ -2107,7 +2121,7 @@ public class MultiUserChat {
|
|||
Set<Status> statusCodes,
|
||||
boolean isUserModification,
|
||||
MUCUser mucUser,
|
||||
String from) {
|
||||
FullJid from) {
|
||||
// Check if an occupant was kicked from the room
|
||||
if (statusCodes.contains(Status.KICKED_307)) {
|
||||
// Check if this occupant was kicked
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
|
|
@ -49,10 +50,16 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
|||
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
|
||||
import org.jivesoftware.smackx.muc.packet.MUCInitialPresence;
|
||||
import org.jivesoftware.smackx.muc.packet.MUCUser;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.DomainBareJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.JidWithLocalpart;
|
||||
|
||||
public class MultiUserChatManager extends Manager {
|
||||
private final static String DISCO_NODE = MUCInitialPresence.NAMESPACE + "#rooms";
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(MultiUserChatManager.class.getName());
|
||||
|
||||
static {
|
||||
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||
public void connectionCreated(final XMPPConnection connection) {
|
||||
|
|
@ -71,9 +78,9 @@ public class MultiUserChatManager extends Manager {
|
|||
XMPPConnection connection = weakRefConnection.get();
|
||||
if (connection == null)
|
||||
return Collections.emptyList();
|
||||
Set<String> joinedRooms = MultiUserChatManager.getInstanceFor(connection).getJoinedRooms();
|
||||
Set<BareJid> joinedRooms = MultiUserChatManager.getInstanceFor(connection).getJoinedRooms();
|
||||
List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>();
|
||||
for (String room : joinedRooms) {
|
||||
for (BareJid room : joinedRooms) {
|
||||
answer.add(new DiscoverItems.Item(room));
|
||||
}
|
||||
return answer;
|
||||
|
|
@ -104,14 +111,14 @@ public class MultiUserChatManager extends Manager {
|
|||
new NotFilter(MessageTypeFilter.ERROR));
|
||||
|
||||
private final Set<InvitationListener> invitationsListeners = new CopyOnWriteArraySet<InvitationListener>();
|
||||
private final Set<String> joinedRooms = new HashSet<String>();
|
||||
private final Set<BareJid> joinedRooms = new HashSet<>();
|
||||
|
||||
/**
|
||||
* A Map of MUC JIDs to {@link MultiUserChat} instances. We use weak references for the values in order to allow
|
||||
* those instances to get garbage collected. Note that MultiUserChat instances can not get garbage collected while
|
||||
* the user is joined, because then the MUC will have PacketListeners added to the XMPPConnection.
|
||||
*/
|
||||
private final Map<String, WeakReference<MultiUserChat>> multiUserChats = new HashMap<String, WeakReference<MultiUserChat>>();
|
||||
private final Map<BareJid, WeakReference<MultiUserChat>> multiUserChats = new HashMap<>();
|
||||
|
||||
private MultiUserChatManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
|
|
@ -124,8 +131,13 @@ public class MultiUserChatManager extends Manager {
|
|||
final MUCUser mucUser = MUCUser.from(message);
|
||||
// Check if the MUCUser extension includes an invitation
|
||||
if (mucUser.getInvite() != null) {
|
||||
BareJid mucJid = message.getFrom().asBareJidIfPossible();
|
||||
if (mucJid == null) {
|
||||
LOGGER.warning("Invite to non bare JID: '" + message.toXML() + "'");
|
||||
return;
|
||||
}
|
||||
// Fire event for invitation listeners
|
||||
final MultiUserChat muc = getMultiUserChat(packet.getFrom());
|
||||
final MultiUserChat muc = getMultiUserChat(mucJid);
|
||||
for (final InvitationListener listener : invitationsListeners) {
|
||||
listener.invitationReceived(connection(), muc, mucUser.getInvite().getFrom(),
|
||||
mucUser.getInvite().getReason(), mucUser.getPassword(), message);
|
||||
|
|
@ -138,7 +150,7 @@ public class MultiUserChatManager extends Manager {
|
|||
|
||||
/**
|
||||
* Creates a multi user chat. Note: no information is sent to or received from the server until you attempt to
|
||||
* {@link MultiUserChat#join(String) join} the chat room. On some server implementations, the room will not be
|
||||
* {@link MultiUserChat#join(org.jxmpp.jid.parts.Resourcepart) join} the chat room. On some server implementations, the room will not be
|
||||
* created until the first person joins it.
|
||||
* <p>
|
||||
* Most XMPP servers use a sub-domain for the chat service (eg chat.example.com for the XMPP server example.com).
|
||||
|
|
@ -148,7 +160,7 @@ public class MultiUserChatManager extends Manager {
|
|||
* @param jid the name of the room in the form "roomName@service", where "service" is the hostname at which the
|
||||
* multi-user chat service is running. Make sure to provide a valid JID.
|
||||
*/
|
||||
public synchronized MultiUserChat getMultiUserChat(String jid) {
|
||||
public synchronized MultiUserChat getMultiUserChat(BareJid jid) {
|
||||
WeakReference<MultiUserChat> weakRefMultiUserChat = multiUserChats.get(jid);
|
||||
if (weakRefMultiUserChat == null) {
|
||||
return createNewMucAndAddToMap(jid);
|
||||
|
|
@ -160,7 +172,7 @@ public class MultiUserChatManager extends Manager {
|
|||
return multiUserChat;
|
||||
}
|
||||
|
||||
private MultiUserChat createNewMucAndAddToMap(String jid) {
|
||||
private MultiUserChat createNewMucAndAddToMap(BareJid jid) {
|
||||
MultiUserChat multiUserChat = new MultiUserChat(connection(), jid, this);
|
||||
multiUserChats.put(jid, new WeakReference<MultiUserChat>(multiUserChat));
|
||||
return multiUserChat;
|
||||
|
|
@ -176,7 +188,7 @@ public class MultiUserChatManager extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public boolean isServiceEnabled(String user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public boolean isServiceEnabled(Jid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(user, MUCInitialPresence.NAMESPACE);
|
||||
}
|
||||
|
||||
|
|
@ -186,7 +198,7 @@ public class MultiUserChatManager extends Manager {
|
|||
*
|
||||
* @return a List of the rooms where the user has joined using a given connection.
|
||||
*/
|
||||
public Set<String> getJoinedRooms() {
|
||||
public Set<BareJid> getJoinedRooms() {
|
||||
return Collections.unmodifiableSet(joinedRooms);
|
||||
}
|
||||
|
||||
|
|
@ -201,15 +213,20 @@ public class MultiUserChatManager extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public List<String> getJoinedRooms(String user) throws NoResponseException, XMPPErrorException,
|
||||
public List<BareJid> getJoinedRooms(JidWithLocalpart user) throws NoResponseException, XMPPErrorException,
|
||||
NotConnectedException, InterruptedException {
|
||||
// Send the disco packet to the user
|
||||
DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(user, DISCO_NODE);
|
||||
List<DiscoverItems.Item> items = result.getItems();
|
||||
List<String> answer = new ArrayList<String>(items.size());
|
||||
List<BareJid> answer = new ArrayList<>(items.size());
|
||||
// Collect the entityID for each returned item
|
||||
for (DiscoverItems.Item item : items) {
|
||||
answer.add(item.getEntityID());
|
||||
BareJid muc = item.getEntityID().asBareJidIfPossible();
|
||||
if (muc == null) {
|
||||
LOGGER.warning("Not a bare JID: " + item.getEntityID());
|
||||
continue;
|
||||
}
|
||||
answer.add(muc);
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
|
@ -225,7 +242,7 @@ public class MultiUserChatManager extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public RoomInfo getRoomInfo(String room) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public RoomInfo getRoomInfo(BareJid room) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection()).discoverInfo(room);
|
||||
return new RoomInfo(info);
|
||||
}
|
||||
|
|
@ -239,7 +256,7 @@ public class MultiUserChatManager extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public List<String> getServiceNames() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public List<DomainBareJid> getServiceNames() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection());
|
||||
return sdm.findServices(MUCInitialPresence.NAMESPACE, false, false);
|
||||
}
|
||||
|
|
@ -256,7 +273,7 @@ public class MultiUserChatManager extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public List<HostedRoom> getHostedRooms(String serviceName) throws NoResponseException, XMPPErrorException,
|
||||
public List<HostedRoom> getHostedRooms(DomainBareJid serviceName) throws NoResponseException, XMPPErrorException,
|
||||
NotConnectedException, InterruptedException {
|
||||
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection());
|
||||
DiscoverItems discoverItems = discoManager.discoverItems(serviceName);
|
||||
|
|
@ -278,7 +295,7 @@ public class MultiUserChatManager extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void decline(String room, String inviter, String reason) throws NotConnectedException, InterruptedException {
|
||||
public void decline(BareJid room, String inviter, String reason) throws NotConnectedException, InterruptedException {
|
||||
Message message = new Message(room);
|
||||
|
||||
// Create the MUCUser packet that will include the rejection
|
||||
|
|
@ -311,11 +328,11 @@ public class MultiUserChatManager extends Manager {
|
|||
invitationsListeners.remove(listener);
|
||||
}
|
||||
|
||||
void addJoinedRoom(String room) {
|
||||
void addJoinedRoom(BareJid room) {
|
||||
joinedRooms.add(room);
|
||||
}
|
||||
|
||||
void removeJoinedRoom(String room) {
|
||||
void removeJoinedRoom(BareJid room) {
|
||||
joinedRooms.remove(room);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,14 @@
|
|||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smackx.muc.packet.MUCItem;
|
||||
import org.jivesoftware.smackx.muc.packet.MUCUser;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jxmpp.util.XmppStringUtils;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.parts.Resourcepart;
|
||||
|
||||
/**
|
||||
* Represents the information about an occupant in a given room. The information will always have
|
||||
|
|
@ -29,12 +33,15 @@ import org.jxmpp.util.XmppStringUtils;
|
|||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class Occupant {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(Occupant.class.getName());
|
||||
|
||||
// Fields that must have a value
|
||||
private final MUCAffiliation affiliation;
|
||||
private final MUCRole role;
|
||||
// Fields that may have a value
|
||||
private final String jid;
|
||||
private final String nick;
|
||||
private final Jid jid;
|
||||
private final Resourcepart nick;
|
||||
|
||||
Occupant(MUCItem item) {
|
||||
this.jid = item.getJid();
|
||||
|
|
@ -51,7 +58,13 @@ public class Occupant {
|
|||
this.affiliation = item.getAffiliation();
|
||||
this.role = item.getRole();
|
||||
// Get the nickname from the FROM attribute of the presence
|
||||
this.nick = XmppStringUtils.parseResource(presence.getFrom());
|
||||
FullJid from = presence.getFrom().asFullJidIfPossible();
|
||||
if (from == null) {
|
||||
LOGGER.warning("Occupant presence without resource: " + presence.getFrom());
|
||||
this.nick = null;
|
||||
} else {
|
||||
this.nick = from.getResourcepart();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,7 +75,7 @@ public class Occupant {
|
|||
*
|
||||
* @return the full JID of the occupant.
|
||||
*/
|
||||
public String getJid() {
|
||||
public Jid getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +106,7 @@ public class Occupant {
|
|||
* @return the current nickname of the occupant in the room or null if this information was
|
||||
* obtained from a presence.
|
||||
*/
|
||||
public String getNick() {
|
||||
public Resourcepart getNick() {
|
||||
return nick;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@
|
|||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.parts.Resourcepart;
|
||||
|
||||
/**
|
||||
* A listener that is fired anytime a participant's status in a room is changed, such as the
|
||||
* user being kicked, banned, or granted admin permissions.
|
||||
|
|
@ -33,7 +37,7 @@ public interface ParticipantStatusListener {
|
|||
* @param participant the participant that has just joined the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void joined(String participant);
|
||||
public abstract void joined(FullJid participant);
|
||||
|
||||
/**
|
||||
* Called when a room occupant has left the room on its own. This means that the occupant was
|
||||
|
|
@ -42,7 +46,7 @@ public interface ParticipantStatusListener {
|
|||
* @param participant the participant that has left the room on its own.
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void left(String participant);
|
||||
public abstract void left(FullJid participant);
|
||||
|
||||
/**
|
||||
* Called when a room participant has been kicked from the room. This means that the kicked
|
||||
|
|
@ -53,7 +57,7 @@ public interface ParticipantStatusListener {
|
|||
* @param actor the moderator that kicked the occupant from the room (e.g. user@host.org).
|
||||
* @param reason the reason provided by the actor to kick the occupant from the room.
|
||||
*/
|
||||
public abstract void kicked(String participant, String actor, String reason);
|
||||
public abstract void kicked(FullJid participant, Jid actor, String reason);
|
||||
|
||||
/**
|
||||
* Called when a moderator grants voice to a visitor. This means that the visitor
|
||||
|
|
@ -62,7 +66,7 @@ public interface ParticipantStatusListener {
|
|||
* @param participant the participant that was granted voice in the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void voiceGranted(String participant);
|
||||
public abstract void voiceGranted(FullJid participant);
|
||||
|
||||
/**
|
||||
* Called when a moderator revokes voice from a participant. This means that the participant
|
||||
|
|
@ -72,7 +76,7 @@ public interface ParticipantStatusListener {
|
|||
* @param participant the participant that was revoked voice from the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void voiceRevoked(String participant);
|
||||
public abstract void voiceRevoked(FullJid participant);
|
||||
|
||||
/**
|
||||
* Called when an administrator or owner banned a participant from the room. This means that
|
||||
|
|
@ -83,7 +87,7 @@ public interface ParticipantStatusListener {
|
|||
* @param actor the administrator that banned the occupant (e.g. user@host.org).
|
||||
* @param reason the reason provided by the administrator to ban the occupant.
|
||||
*/
|
||||
public abstract void banned(String participant, String actor, String reason);
|
||||
public abstract void banned(FullJid participant, Jid actor, String reason);
|
||||
|
||||
/**
|
||||
* Called when an administrator grants a user membership to the room. This means that the user
|
||||
|
|
@ -92,7 +96,7 @@ public interface ParticipantStatusListener {
|
|||
* @param participant the participant that was granted membership in the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void membershipGranted(String participant);
|
||||
public abstract void membershipGranted(FullJid participant);
|
||||
|
||||
/**
|
||||
* Called when an administrator revokes a user membership to the room. This means that the
|
||||
|
|
@ -101,7 +105,7 @@ public interface ParticipantStatusListener {
|
|||
* @param participant the participant that was revoked membership from the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void membershipRevoked(String participant);
|
||||
public abstract void membershipRevoked(FullJid participant);
|
||||
|
||||
/**
|
||||
* Called when an administrator grants moderator privileges to a user. This means that the user
|
||||
|
|
@ -111,7 +115,7 @@ public interface ParticipantStatusListener {
|
|||
* @param participant the participant that was granted moderator privileges in the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void moderatorGranted(String participant);
|
||||
public abstract void moderatorGranted(FullJid participant);
|
||||
|
||||
/**
|
||||
* Called when an administrator revokes moderator privileges from a user. This means that the
|
||||
|
|
@ -121,7 +125,7 @@ public interface ParticipantStatusListener {
|
|||
* @param participant the participant that was revoked moderator privileges in the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void moderatorRevoked(String participant);
|
||||
public abstract void moderatorRevoked(FullJid participant);
|
||||
|
||||
/**
|
||||
* Called when an owner grants a user ownership on the room. This means that the user
|
||||
|
|
@ -131,7 +135,7 @@ public interface ParticipantStatusListener {
|
|||
* @param participant the participant that was granted ownership on the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void ownershipGranted(String participant);
|
||||
public abstract void ownershipGranted(FullJid participant);
|
||||
|
||||
/**
|
||||
* Called when an owner revokes a user ownership on the room. This means that the user
|
||||
|
|
@ -141,7 +145,7 @@ public interface ParticipantStatusListener {
|
|||
* @param participant the participant that was revoked ownership on the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void ownershipRevoked(String participant);
|
||||
public abstract void ownershipRevoked(FullJid participant);
|
||||
|
||||
/**
|
||||
* Called when an owner grants administrator privileges to a user. This means that the user
|
||||
|
|
@ -151,7 +155,7 @@ public interface ParticipantStatusListener {
|
|||
* @param participant the participant that was granted administrator privileges
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void adminGranted(String participant);
|
||||
public abstract void adminGranted(FullJid participant);
|
||||
|
||||
/**
|
||||
* Called when an owner revokes administrator privileges from a user. This means that the user
|
||||
|
|
@ -161,7 +165,7 @@ public interface ParticipantStatusListener {
|
|||
* @param participant the participant that was revoked administrator privileges
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void adminRevoked(String participant);
|
||||
public abstract void adminRevoked(FullJid participant);
|
||||
|
||||
/**
|
||||
* Called when a participant changed his/her nickname in the room. The new participant's
|
||||
|
|
@ -171,6 +175,6 @@ public interface ParticipantStatusListener {
|
|||
* (e.g. room@conference.jabber.org/nick).
|
||||
* @param newNickname the new nickname that the participant decided to use.
|
||||
*/
|
||||
public abstract void nicknameChanged(String participant, String newNickname);
|
||||
public abstract void nicknameChanged(FullJid participant, Resourcepart newNickname);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ import java.util.logging.Logger;
|
|||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.xdata.Form;
|
||||
import org.jivesoftware.smackx.xdata.FormField;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* Represents the room information that was discovered using Service Discovery. It's possible to
|
||||
|
|
@ -39,9 +41,9 @@ public class RoomInfo {
|
|||
private static final Logger LOGGER = Logger.getLogger(RoomInfo.class.getName());
|
||||
|
||||
/**
|
||||
* JID of the room. The node of the JID is commonly used as the ID of the room or name.
|
||||
* JID of the room. The localpart of the JID is commonly used as the ID of the room or name.
|
||||
*/
|
||||
private final String room;
|
||||
private final BareJid room;
|
||||
/**
|
||||
* Description of the room.
|
||||
*/
|
||||
|
|
@ -128,7 +130,12 @@ public class RoomInfo {
|
|||
private final Form form;
|
||||
|
||||
RoomInfo(DiscoverInfo info) {
|
||||
this.room = info.getFrom();
|
||||
final Jid from = info.getFrom();
|
||||
if (from != null) {
|
||||
this.room = info.getFrom().asBareJidIfPossible();
|
||||
} else {
|
||||
this.room = null;
|
||||
}
|
||||
// Get the information based on the discovered features
|
||||
this.membersOnly = info.containsFeature("muc_membersonly");
|
||||
this.moderated = info.containsFeature("muc_moderated");
|
||||
|
|
@ -233,7 +240,7 @@ public class RoomInfo {
|
|||
*
|
||||
* @return the JID of the room whose information was discovered.
|
||||
*/
|
||||
public String getRoom() {
|
||||
public BareJid getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
/**
|
||||
* A listener that is fired anytime a MUC room changes its subject.
|
||||
*
|
||||
|
|
@ -30,6 +32,6 @@ public interface SubjectUpdatedListener {
|
|||
* @param subject the new room's subject.
|
||||
* @param from the user that changed the room's subject (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void subjectUpdated(String subject, String from);
|
||||
public abstract void subjectUpdated(String subject, FullJid from);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* A listener that is fired anytime your participant's status in a room is changed, such as the
|
||||
* user being kicked, banned, or granted admin permissions.
|
||||
|
|
@ -32,7 +34,7 @@ public interface UserStatusListener {
|
|||
* @param actor the moderator that kicked your user from the room (e.g. user@host.org).
|
||||
* @param reason the reason provided by the actor to kick you from the room.
|
||||
*/
|
||||
public abstract void kicked(String actor, String reason);
|
||||
public abstract void kicked(Jid actor, String reason);
|
||||
|
||||
/**
|
||||
* Called when a moderator grants voice to your user. This means that you were a visitor in
|
||||
|
|
@ -57,7 +59,7 @@ public interface UserStatusListener {
|
|||
* @param actor the administrator that banned your user (e.g. user@host.org).
|
||||
* @param reason the reason provided by the administrator to banned you.
|
||||
*/
|
||||
public abstract void banned(String actor, String reason);
|
||||
public abstract void banned(Jid actor, String reason);
|
||||
|
||||
/**
|
||||
* Called when an administrator grants your user membership to the room. This means that you
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ import org.jivesoftware.smack.packet.NamedElement;
|
|||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smackx.muc.MUCAffiliation;
|
||||
import org.jivesoftware.smackx.muc.MUCRole;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.parts.Resourcepart;
|
||||
|
||||
/**
|
||||
* Item child that holds information about roles, affiliation, jids and nicks.
|
||||
|
|
@ -32,10 +34,10 @@ public class MUCItem implements NamedElement {
|
|||
|
||||
private final MUCAffiliation affiliation;
|
||||
private final MUCRole role;
|
||||
private final String actor;
|
||||
private final Jid actor;
|
||||
private final String reason;
|
||||
private final String jid;
|
||||
private final String nick;
|
||||
private final Jid jid;
|
||||
private final Resourcepart nick;
|
||||
|
||||
public MUCItem(MUCAffiliation affiliation) {
|
||||
this(affiliation, null, null, null, null, null);
|
||||
|
|
@ -45,19 +47,19 @@ public class MUCItem implements NamedElement {
|
|||
this(null, role, null, null, null, null);
|
||||
}
|
||||
|
||||
public MUCItem(MUCRole role, String nick) {
|
||||
public MUCItem(MUCRole role, Resourcepart nick) {
|
||||
this(null, role, null, null, null, nick);
|
||||
}
|
||||
|
||||
public MUCItem(MUCAffiliation affiliation, String jid, String reason) {
|
||||
public MUCItem(MUCAffiliation affiliation, Jid jid, String reason) {
|
||||
this(affiliation, null, null, reason, jid, null);
|
||||
}
|
||||
|
||||
public MUCItem(MUCAffiliation affiliation, String jid) {
|
||||
public MUCItem(MUCAffiliation affiliation, Jid jid) {
|
||||
this(affiliation, null, null, null, jid, null);
|
||||
}
|
||||
|
||||
public MUCItem(MUCRole role, String nick, String reason) {
|
||||
public MUCItem(MUCRole role, Resourcepart nick, String reason) {
|
||||
this(null, role, null, reason, null, nick);
|
||||
}
|
||||
|
||||
|
|
@ -71,8 +73,8 @@ public class MUCItem implements NamedElement {
|
|||
* @param jid
|
||||
* @param nick
|
||||
*/
|
||||
public MUCItem(MUCAffiliation affiliation, MUCRole role, String actor,
|
||||
String reason, String jid, String nick) {
|
||||
public MUCItem(MUCAffiliation affiliation, MUCRole role, Jid actor,
|
||||
String reason, Jid jid, Resourcepart nick) {
|
||||
this.affiliation = affiliation;
|
||||
this.role = role;
|
||||
this.actor = actor;
|
||||
|
|
@ -86,7 +88,7 @@ public class MUCItem implements NamedElement {
|
|||
*
|
||||
* @return the JID of an occupant in the room that was kicked or banned.
|
||||
*/
|
||||
public String getActor() {
|
||||
public Jid getActor() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +120,7 @@ public class MUCItem implements NamedElement {
|
|||
*
|
||||
* @return the room JID by which an occupant is identified within the room.
|
||||
*/
|
||||
public String getJid() {
|
||||
public Jid getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +130,7 @@ public class MUCItem implements NamedElement {
|
|||
*
|
||||
* @return the new nickname of an occupant that is changing his/her nickname.
|
||||
*/
|
||||
public String getNick() {
|
||||
public Resourcepart getNick() {
|
||||
return nick;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,10 +18,13 @@ package org.jivesoftware.smackx.muc.provider;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
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.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.parts.Resourcepart;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
|
@ -29,10 +32,10 @@ public class MUCParserUtils {
|
|||
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");
|
||||
Resourcepart nick = ParserUtils.getResourcepartAttribute(parser, "nick");
|
||||
MUCRole role = MUCRole.fromString(parser.getAttributeValue("", "role"));
|
||||
String jid = parser.getAttributeValue("", "jid");
|
||||
String actor = null;
|
||||
Jid jid = ParserUtils.getJidAttribute(parser);
|
||||
Jid actor = null;
|
||||
String reason = null;
|
||||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
|
|
@ -41,7 +44,7 @@ public class MUCParserUtils {
|
|||
String name = parser.getName();
|
||||
switch (name) {
|
||||
case "actor":
|
||||
actor = parser.getAttributeValue("", "jid");
|
||||
actor = ParserUtils.getJidAttribute(parser);
|
||||
break;
|
||||
case "reason":
|
||||
reason = parser.nextText();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue