2004-07-06 05:05:37 +02:00
|
|
|
/**
|
|
|
|
* $RCSfile$
|
|
|
|
* $Revision$
|
|
|
|
* $Date$
|
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2004-07-06 05:05:37 +02:00
|
|
|
*
|
2004-11-03 00:37:00 +01:00
|
|
|
* All rights reserved. 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
|
2004-07-06 05:05:37 +02:00
|
|
|
*
|
2004-11-03 00:37:00 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2004-07-06 05:05:37 +02:00
|
|
|
*
|
2004-11-03 00:37:00 +01:00
|
|
|
* 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.
|
2004-07-06 05:05:37 +02:00
|
|
|
*/
|
2004-11-03 00:37:00 +01:00
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
package org.jivesoftware.smackx.muc;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.*;
|
|
|
|
import org.jivesoftware.smack.filter.*;
|
|
|
|
import org.jivesoftware.smack.packet.*;
|
|
|
|
import org.jivesoftware.smackx.Form;
|
|
|
|
import org.jivesoftware.smackx.NodeInformationProvider;
|
|
|
|
import org.jivesoftware.smackx.ServiceDiscoveryManager;
|
|
|
|
import org.jivesoftware.smackx.packet.*;
|
|
|
|
|
2006-02-27 22:59:50 +01:00
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.*;
|
2006-07-18 07:14:33 +02:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2006-02-27 22:59:50 +01:00
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
2005-11-01 19:31:52 +01:00
|
|
|
* Possible affiliatons are "owner", "admin", "member", and "outcast". Possible roles
|
2004-07-06 05:05:37 +02:00
|
|
|
* are "moderator", "participant", and "visitor". Each role and affiliation guarantees
|
|
|
|
* different privileges (e.g. Send messages to all occupants, Kick participants and visitors,
|
2005-11-01 19:31:52 +01:00
|
|
|
* Grant voice, Edit member list, etc.).
|
2004-07-06 05:05:37 +02:00
|
|
|
*
|
2006-07-18 07:14:33 +02:00
|
|
|
* @author Gaston Dombiak, Larry Kirschner
|
2004-07-06 05:05:37 +02:00
|
|
|
*/
|
|
|
|
public class MultiUserChat {
|
|
|
|
|
|
|
|
private final static String discoNamespace = "http://jabber.org/protocol/muc";
|
|
|
|
private final static String discoNode = "http://jabber.org/protocol/muc#rooms";
|
|
|
|
|
2006-07-18 07:14:33 +02:00
|
|
|
private static Map<XMPPConnection, List<String>> joinedRooms =
|
|
|
|
new WeakHashMap<XMPPConnection, List<String>>();
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
private XMPPConnection connection;
|
|
|
|
private String room;
|
|
|
|
private String subject;
|
|
|
|
private String nickname = null;
|
|
|
|
private boolean joined = false;
|
2006-07-18 07:14:33 +02:00
|
|
|
private Map<String, Presence> occupantsMap = new ConcurrentHashMap<String, Presence>();
|
2004-07-06 05:05:37 +02:00
|
|
|
|
2006-07-18 07:14:33 +02:00
|
|
|
private final List<InvitationRejectionListener> invitationRejectionListeners =
|
|
|
|
new ArrayList<InvitationRejectionListener>();
|
|
|
|
private final List<SubjectUpdatedListener> subjectUpdatedListeners =
|
|
|
|
new ArrayList<SubjectUpdatedListener>();
|
|
|
|
private final List<UserStatusListener> userStatusListeners =
|
|
|
|
new ArrayList<UserStatusListener>();
|
|
|
|
private final List<ParticipantStatusListener> participantStatusListeners =
|
|
|
|
new ArrayList<ParticipantStatusListener>();
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
private PacketFilter presenceFilter;
|
2006-07-18 07:14:33 +02:00
|
|
|
private List<PacketInterceptor> presenceInterceptors = new ArrayList<PacketInterceptor>();
|
2004-07-06 05:05:37 +02:00
|
|
|
private PacketFilter messageFilter;
|
2006-07-18 07:14:33 +02:00
|
|
|
private RoomListenerMultiplexor roomListenerMultiplexor;
|
|
|
|
private ConnectionDetachedPacketCollector messageCollector;
|
|
|
|
private List<PacketListener> connectionListeners = new ArrayList<PacketListener>();
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
static {
|
2006-09-16 01:05:01 +02:00
|
|
|
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
|
|
|
|
public void connectionCreated(final XMPPConnection connection) {
|
2005-11-01 19:31:52 +01:00
|
|
|
// Set on every established connection that this client supports the Multi-User
|
|
|
|
// Chat protocol. This information will be used when another client tries to
|
2004-07-06 05:05:37 +02:00
|
|
|
// discover whether this client supports MUC or not.
|
|
|
|
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(discoNamespace);
|
|
|
|
// Set the NodeInformationProvider that will provide information about the
|
2005-11-01 19:31:52 +01:00
|
|
|
// joined rooms whenever a disco request is received
|
2004-07-06 05:05:37 +02:00
|
|
|
ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(
|
|
|
|
discoNode,
|
|
|
|
new NodeInformationProvider() {
|
2006-10-16 19:56:48 +02:00
|
|
|
public List<DiscoverItems.Item> getNodeItems() {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>();
|
|
|
|
Iterator<String> rooms=MultiUserChat.getJoinedRooms(connection);
|
2004-07-06 05:05:37 +02:00
|
|
|
while (rooms.hasNext()) {
|
2006-07-18 07:14:33 +02:00
|
|
|
answer.add(new DiscoverItems.Item(rooms.next()));
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
2006-10-16 19:56:48 +02:00
|
|
|
return answer;
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
2006-07-10 18:56:14 +02:00
|
|
|
|
2006-10-16 19:56:48 +02:00
|
|
|
public List<String> getNodeFeatures() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<DiscoverInfo.Identity> getNodeIdentities() {
|
2006-07-10 18:56:14 +02:00
|
|
|
return null;
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new multi user chat with the specified connection and room name. Note: no
|
|
|
|
* information is sent to or received from the server until you attempt to
|
|
|
|
* {@link #join(String) 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). You must ensure that the room address you're
|
|
|
|
* trying to connect to includes the proper chat sub-domain.
|
|
|
|
*
|
|
|
|
* @param connection the XMPP connection.
|
|
|
|
* @param room the name of the room in the form "roomName@service", where
|
|
|
|
* "service" is the hostname at which the multi-user chat
|
2005-05-06 22:39:43 +02:00
|
|
|
* service is running. Make sure to provide a valid JID.
|
2004-07-06 05:05:37 +02:00
|
|
|
*/
|
|
|
|
public MultiUserChat(XMPPConnection connection, String room) {
|
|
|
|
this.connection = connection;
|
2005-05-06 22:39:43 +02:00
|
|
|
this.room = room.toLowerCase();
|
2004-07-06 05:05:37 +02:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the specified user supports the Multi-User Chat protocol.
|
|
|
|
*
|
|
|
|
* @param connection the connection to use to perform the service discovery.
|
|
|
|
* @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
|
|
|
|
* @return a boolean indicating whether the specified user supports the MUC protocol.
|
|
|
|
*/
|
|
|
|
public static boolean isServiceEnabled(XMPPConnection connection, String user) {
|
|
|
|
try {
|
|
|
|
DiscoverInfo result =
|
|
|
|
ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(user);
|
|
|
|
return result.containsFeature(discoNamespace);
|
|
|
|
}
|
|
|
|
catch (XMPPException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an Iterator on the rooms where the user has joined using a given connection.
|
2005-11-01 19:31:52 +01:00
|
|
|
* The Iterator will contain Strings where each String represents a room
|
2004-07-06 05:05:37 +02:00
|
|
|
* (e.g. room@muc.jabber.org).
|
2005-11-01 19:31:52 +01:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param connection the connection used to join the rooms.
|
|
|
|
* @return an Iterator on the rooms where the user has joined using a given connection.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
private static Iterator<String> getJoinedRooms(XMPPConnection connection) {
|
|
|
|
List<String> rooms = joinedRooms.get(connection);
|
2004-07-06 05:05:37 +02:00
|
|
|
if (rooms != null) {
|
|
|
|
return rooms.iterator();
|
|
|
|
}
|
2005-11-01 19:31:52 +01:00
|
|
|
// Return an iterator on an empty collection (i.e. the user never joined a room)
|
2006-07-18 07:14:33 +02:00
|
|
|
return new ArrayList<String>().iterator();
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
2005-11-01 19:31:52 +01:00
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
/**
|
2005-11-01 19:31:52 +01:00
|
|
|
* Returns an Iterator on the rooms where the requested user has joined. The Iterator will
|
2004-07-06 05:05:37 +02:00
|
|
|
* contain Strings where each String represents a room (e.g. room@muc.jabber.org).
|
2005-11-01 19:31:52 +01:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param connection the connection to use to perform the service discovery.
|
|
|
|
* @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
|
|
|
|
* @return an Iterator on the rooms where the requested user has joined.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public static Iterator<String> getJoinedRooms(XMPPConnection connection, String user) {
|
2004-07-06 05:05:37 +02:00
|
|
|
try {
|
2006-07-18 07:14:33 +02:00
|
|
|
ArrayList<String> answer = new ArrayList<String>();
|
2004-07-06 05:05:37 +02:00
|
|
|
// Send the disco packet to the user
|
|
|
|
DiscoverItems result =
|
|
|
|
ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(user, discoNode);
|
|
|
|
// Collect the entityID for each returned item
|
2006-07-18 07:14:33 +02:00
|
|
|
for (Iterator<DiscoverItems.Item> items=result.getItems(); items.hasNext();) {
|
|
|
|
answer.add(items.next().getEntityID());
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
return answer.iterator();
|
|
|
|
}
|
|
|
|
catch (XMPPException e) {
|
|
|
|
e.printStackTrace();
|
2005-11-01 19:31:52 +01:00
|
|
|
// Return an iterator on an empty collection
|
2006-07-18 07:14:33 +02:00
|
|
|
return new ArrayList<String>().iterator();
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-15 02:40:01 +01:00
|
|
|
/**
|
2005-09-29 17:58:11 +02:00
|
|
|
* Returns the discovered information of a given room without actually having to join the room.
|
2004-12-15 02:40:01 +01:00
|
|
|
* The server will provide information only for rooms that are public.
|
|
|
|
*
|
|
|
|
* @param connection the XMPP connection to use for discovering information about the room.
|
|
|
|
* @param room the name of the room in the form "roomName@service" of which we want to discover
|
|
|
|
* its information.
|
2005-09-29 17:58:11 +02:00
|
|
|
* @return the discovered information of a given room without actually having to join the room.
|
2004-12-15 02:40:01 +01:00
|
|
|
* @throws XMPPException if an error occured while trying to discover information of a room.
|
|
|
|
*/
|
|
|
|
public static RoomInfo getRoomInfo(XMPPConnection connection, String room)
|
|
|
|
throws XMPPException {
|
|
|
|
DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(room);
|
|
|
|
return new RoomInfo(info);
|
|
|
|
}
|
|
|
|
|
2005-01-03 03:08:23 +01:00
|
|
|
/**
|
|
|
|
* Returns a collection with the XMPP addresses of the Multi-User Chat services.
|
|
|
|
*
|
|
|
|
* @param connection the XMPP connection to use for discovering Multi-User Chat services.
|
|
|
|
* @return a collection with the XMPP addresses of the Multi-User Chat services.
|
|
|
|
* @throws XMPPException if an error occured while trying to discover MUC services.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public static Collection<String> getServiceNames(XMPPConnection connection) throws XMPPException {
|
|
|
|
final List<String> answer = new ArrayList<String>();
|
2005-01-03 03:08:23 +01:00
|
|
|
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
|
2005-08-27 04:24:38 +02:00
|
|
|
DiscoverItems items = discoManager.discoverItems(connection.getServiceName());
|
2006-07-18 07:14:33 +02:00
|
|
|
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) {
|
|
|
|
DiscoverItems.Item item = it.next();
|
2005-11-01 16:16:48 +01:00
|
|
|
try {
|
|
|
|
DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
|
|
|
|
if (info.containsFeature("http://jabber.org/protocol/muc")) {
|
|
|
|
answer.add(item.getEntityID());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (XMPPException e) {
|
|
|
|
// Trouble finding info in some cases. This is a workaround for
|
|
|
|
// discovering info on remote servers.
|
2005-01-03 03:08:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return answer;
|
|
|
|
}
|
|
|
|
|
2005-02-06 17:36:23 +01:00
|
|
|
/**
|
|
|
|
* Returns a collection of HostedRooms where each HostedRoom has the XMPP address of the room
|
|
|
|
* and the room's name. Once discovered the rooms hosted by a chat service it is possible to
|
|
|
|
* discover more detailed room information or join the room.
|
|
|
|
*
|
|
|
|
* @param connection the XMPP connection to use for discovering hosted rooms by the MUC service.
|
|
|
|
* @param serviceName the service that is hosting the rooms to discover.
|
|
|
|
* @return a collection of HostedRooms.
|
|
|
|
* @throws XMPPException if an error occured while trying to discover the information.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public static Collection<HostedRoom> getHostedRooms(XMPPConnection connection, String serviceName)
|
2005-02-06 17:36:23 +01:00
|
|
|
throws XMPPException {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<HostedRoom> answer = new ArrayList<HostedRoom>();
|
2005-02-06 17:36:23 +01:00
|
|
|
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
|
|
|
|
DiscoverItems items = discoManager.discoverItems(serviceName);
|
2006-07-18 07:14:33 +02:00
|
|
|
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) {
|
|
|
|
answer.add(new HostedRoom(it.next()));
|
2005-02-06 17:36:23 +01:00
|
|
|
}
|
|
|
|
return answer;
|
|
|
|
}
|
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
/**
|
|
|
|
* Returns the name of the room this MultiUserChat object represents.
|
|
|
|
*
|
|
|
|
* @return the multi user chat room name.
|
|
|
|
*/
|
|
|
|
public String getRoom() {
|
|
|
|
return room;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Creates the room according to some default configuration, assign the requesting user
|
|
|
|
* as the room owner, and add the owner to the room but not allow anyone else to enter
|
2004-07-06 05:05:37 +02:00
|
|
|
* the room (effectively "locking" the room). The requesting user will join the room
|
|
|
|
* under the specified nickname as soon as the room has been created.<p>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
|
|
|
* To create an "Instant Room", that means a room with some default configuration that is
|
|
|
|
* available for immediate access, the room's owner should send an empty form after creating
|
2004-07-06 05:05:37 +02:00
|
|
|
* the room. {@link #sendConfigurationForm(Form)}<p>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
|
|
|
* To create a "Reserved Room", that means a room manually configured by the room creator
|
|
|
|
* before anyone is allowed to enter, the room's owner should complete and send a form after
|
|
|
|
* creating the room. Once the completed configutation form is sent to the server, the server
|
2004-07-06 05:05:37 +02:00
|
|
|
* will unlock the room. {@link #sendConfigurationForm(Form)}
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param nickname the nickname to use.
|
|
|
|
* @throws XMPPException if the room couldn't be created for some reason
|
|
|
|
* (e.g. room already exists; user already joined to an existant room or
|
2006-07-18 07:14:33 +02:00
|
|
|
* 405 error if the user is not allowed to create the room)
|
2004-07-06 05:05:37 +02:00
|
|
|
*/
|
|
|
|
public synchronized void create(String nickname) throws XMPPException {
|
|
|
|
if (nickname == null || nickname.equals("")) {
|
|
|
|
throw new IllegalArgumentException("Nickname must not be null or blank.");
|
|
|
|
}
|
|
|
|
// If we've already joined the room, leave it before joining under a new
|
|
|
|
// nickname.
|
|
|
|
if (joined) {
|
|
|
|
throw new IllegalStateException("Creation failed - User already joined the room.");
|
|
|
|
}
|
|
|
|
// We create a room by sending a presence packet to room@service/nick
|
|
|
|
// and signal support for MUC. The owner will be automatically logged into the room.
|
2006-07-17 10:39:08 +02:00
|
|
|
Presence joinPresence = new Presence(Presence.Type.available);
|
2004-07-06 05:05:37 +02:00
|
|
|
joinPresence.setTo(room + "/" + nickname);
|
2006-07-18 07:14:33 +02:00
|
|
|
// Indicate the the client supports MUC
|
2004-07-06 05:05:37 +02:00
|
|
|
joinPresence.addExtension(new MUCInitialPresence());
|
2006-02-27 22:59:50 +01:00
|
|
|
// Invoke presence interceptors so that extra information can be dynamically added
|
2006-07-18 07:14:33 +02:00
|
|
|
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
|
2006-02-27 22:59:50 +01:00
|
|
|
packetInterceptor.interceptPacket(joinPresence);
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
// Wait for a presence packet back from the server.
|
|
|
|
PacketFilter responseFilter =
|
|
|
|
new AndFilter(
|
2005-08-10 06:50:50 +02:00
|
|
|
new FromMatchesFilter(room + "/" + nickname),
|
2004-07-06 05:05:37 +02:00
|
|
|
new PacketTypeFilter(Presence.class));
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
|
|
// Send create & join packet.
|
|
|
|
connection.sendPacket(joinPresence);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
Presence presence =
|
|
|
|
(Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (presence == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (presence.getError() != null) {
|
|
|
|
throw new XMPPException(presence.getError());
|
|
|
|
}
|
|
|
|
// Whether the room existed before or was created, the user has joined the room
|
|
|
|
this.nickname = nickname;
|
|
|
|
joined = true;
|
|
|
|
userHasJoined();
|
|
|
|
|
|
|
|
// Look for confirmation of room creation from the server
|
|
|
|
MUCUser mucUser = getMUCUserExtension(presence);
|
|
|
|
if (mucUser != null && mucUser.getStatus() != null) {
|
|
|
|
if ("201".equals(mucUser.getStatus().getCode())) {
|
|
|
|
// Room was created and the user has joined the room
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// We need to leave the room since it seems that the room already existed
|
|
|
|
leave();
|
|
|
|
throw new XMPPException("Creation failed - Missing acknowledge of room creation.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Joins the chat room using the specified nickname. If already joined
|
|
|
|
* using another nickname, this method will first leave the room and then
|
|
|
|
* re-join using the new nickname. The default timeout of Smack for a reply
|
|
|
|
* from the group chat server that the join succeeded will be used. After
|
2006-07-18 07:14:33 +02:00
|
|
|
* joining the room, the room will decide the amount of history to send.
|
2004-07-06 05:05:37 +02:00
|
|
|
*
|
|
|
|
* @param nickname the nickname to use.
|
2006-07-18 07:14:33 +02:00
|
|
|
* @throws XMPPException if an error occurs joining the room. In particular, a
|
|
|
|
* 401 error can occur if no password was provided and one is required; or a
|
|
|
|
* 403 error can occur if the user is banned; or a
|
|
|
|
* 404 error can occur if the room does not exist or is locked; or a
|
|
|
|
* 407 error can occur if user is not on the member list; or a
|
2004-07-06 05:05:37 +02:00
|
|
|
* 409 error can occur if someone is already in the group chat with the same nickname.
|
|
|
|
*/
|
|
|
|
public void join(String nickname) throws XMPPException {
|
|
|
|
join(nickname, null, null, SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Joins the chat room using the specified nickname and password. If already joined
|
|
|
|
* using another nickname, this method will first leave the room and then
|
|
|
|
* re-join using the new nickname. The default timeout of Smack for a reply
|
|
|
|
* from the group chat server that the join succeeded will be used. After
|
2006-07-18 07:14:33 +02:00
|
|
|
* joining the room, the room will decide the amount of history to send.<p>
|
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* A password is required when joining password protected rooms. If the room does
|
|
|
|
* not require a password there is no need to provide one.
|
|
|
|
*
|
|
|
|
* @param nickname the nickname to use.
|
|
|
|
* @param password the password to use.
|
2006-07-18 07:14:33 +02:00
|
|
|
* @throws XMPPException if an error occurs joining the room. In particular, a
|
|
|
|
* 401 error can occur if no password was provided and one is required; or a
|
|
|
|
* 403 error can occur if the user is banned; or a
|
|
|
|
* 404 error can occur if the room does not exist or is locked; or a
|
|
|
|
* 407 error can occur if user is not on the member list; or a
|
2004-07-06 05:05:37 +02:00
|
|
|
* 409 error can occur if someone is already in the group chat with the same nickname.
|
|
|
|
*/
|
|
|
|
public void join(String nickname, String password) throws XMPPException {
|
|
|
|
join(nickname, password, null, SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Joins the chat room using the specified nickname and password. If already joined
|
|
|
|
* using another nickname, this method will first leave the room and then
|
|
|
|
* re-join using the new nickname.<p>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* To control the amount of history to receive while joining a room you will need to provide
|
|
|
|
* a configured DiscussionHistory object.<p>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* A password is required when joining password protected rooms. If the room does
|
|
|
|
* not require a password there is no need to provide one.<p>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* If the room does not already exist when the user seeks to enter it, the server will
|
2006-07-18 07:14:33 +02:00
|
|
|
* decide to create a new room or not.
|
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param nickname the nickname to use.
|
|
|
|
* @param password the password to use.
|
|
|
|
* @param history the amount of discussion history to receive while joining a room.
|
|
|
|
* @param timeout the amount of time to wait for a reply from the MUC service(in milleseconds).
|
2006-07-18 07:14:33 +02:00
|
|
|
* @throws XMPPException if an error occurs joining the room. In particular, a
|
|
|
|
* 401 error can occur if no password was provided and one is required; or a
|
|
|
|
* 403 error can occur if the user is banned; or a
|
|
|
|
* 404 error can occur if the room does not exist or is locked; or a
|
|
|
|
* 407 error can occur if user is not on the member list; or a
|
2004-07-06 05:05:37 +02:00
|
|
|
* 409 error can occur if someone is already in the group chat with the same nickname.
|
|
|
|
*/
|
|
|
|
public synchronized void join(
|
|
|
|
String nickname,
|
|
|
|
String password,
|
|
|
|
DiscussionHistory history,
|
|
|
|
long timeout)
|
|
|
|
throws XMPPException {
|
|
|
|
if (nickname == null || nickname.equals("")) {
|
|
|
|
throw new IllegalArgumentException("Nickname must not be null or blank.");
|
|
|
|
}
|
|
|
|
// If we've already joined the room, leave it before joining under a new
|
|
|
|
// nickname.
|
|
|
|
if (joined) {
|
|
|
|
leave();
|
|
|
|
}
|
|
|
|
// We join a room by sending a presence packet where the "to"
|
|
|
|
// field is in the form "roomName@service/nickname"
|
2006-07-17 10:39:08 +02:00
|
|
|
Presence joinPresence = new Presence(Presence.Type.available);
|
2004-07-06 05:05:37 +02:00
|
|
|
joinPresence.setTo(room + "/" + nickname);
|
|
|
|
|
2006-07-18 07:14:33 +02:00
|
|
|
// Indicate the the client supports MUC
|
2004-07-06 05:05:37 +02:00
|
|
|
MUCInitialPresence mucInitialPresence = new MUCInitialPresence();
|
|
|
|
if (password != null) {
|
|
|
|
mucInitialPresence.setPassword(password);
|
|
|
|
}
|
|
|
|
if (history != null) {
|
|
|
|
mucInitialPresence.setHistory(history.getMUCHistory());
|
|
|
|
}
|
|
|
|
joinPresence.addExtension(mucInitialPresence);
|
2006-02-27 22:59:50 +01:00
|
|
|
// Invoke presence interceptors so that extra information can be dynamically added
|
2006-07-18 07:14:33 +02:00
|
|
|
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
|
2006-02-27 22:59:50 +01:00
|
|
|
packetInterceptor.interceptPacket(joinPresence);
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
// Wait for a presence packet back from the server.
|
|
|
|
PacketFilter responseFilter =
|
2006-11-21 00:09:11 +01:00
|
|
|
new AndFilter(
|
|
|
|
new FromMatchesFilter(room + "/" + nickname),
|
|
|
|
new PacketTypeFilter(Presence.class));
|
|
|
|
PacketCollector response = null;
|
|
|
|
Presence presence;
|
|
|
|
try {
|
|
|
|
response = connection.createPacketCollector(responseFilter);
|
|
|
|
// Send join packet.
|
|
|
|
connection.sendPacket(joinPresence);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
presence = (Presence) response.nextResult(timeout);
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
// Stop queuing results
|
|
|
|
if (response != null) {
|
|
|
|
response.cancel();
|
|
|
|
}
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
if (presence == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (presence.getError() != null) {
|
|
|
|
throw new XMPPException(presence.getError());
|
|
|
|
}
|
|
|
|
this.nickname = nickname;
|
|
|
|
joined = true;
|
|
|
|
userHasJoined();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if currently in the multi user chat (after calling the {@link
|
|
|
|
* #join(String)} method).
|
|
|
|
*
|
|
|
|
* @return true if currently in the multi user chat room.
|
|
|
|
*/
|
|
|
|
public boolean isJoined() {
|
|
|
|
return joined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Leave the chat room.
|
|
|
|
*/
|
|
|
|
public synchronized void leave() {
|
|
|
|
// If not joined already, do nothing.
|
|
|
|
if (!joined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// We leave a room by sending a presence packet where the "to"
|
|
|
|
// field is in the form "roomName@service/nickname"
|
2006-07-17 10:39:08 +02:00
|
|
|
Presence leavePresence = new Presence(Presence.Type.unavailable);
|
2004-07-06 05:05:37 +02:00
|
|
|
leavePresence.setTo(room + "/" + nickname);
|
2006-02-27 22:59:50 +01:00
|
|
|
// Invoke presence interceptors so that extra information can be dynamically added
|
2006-07-18 07:14:33 +02:00
|
|
|
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
|
2006-02-27 22:59:50 +01:00
|
|
|
packetInterceptor.interceptPacket(leavePresence);
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
connection.sendPacket(leavePresence);
|
2004-12-15 20:03:37 +01:00
|
|
|
// Reset occupant information.
|
2006-07-18 07:14:33 +02:00
|
|
|
occupantsMap.clear();
|
2004-07-06 05:05:37 +02:00
|
|
|
nickname = null;
|
|
|
|
joined = false;
|
|
|
|
userHasLeft();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Returns the room's configuration form that the room's owner can use or <tt>null</tt> if
|
|
|
|
* no configuration is possible. The configuration form allows to set the room's language,
|
|
|
|
* enable logging, specify room's type, etc..
|
|
|
|
*
|
|
|
|
* @return the Form that contains the fields to complete together with the instrucions or
|
2004-07-06 05:05:37 +02:00
|
|
|
* <tt>null</tt> if no configuration is possible.
|
|
|
|
* @throws XMPPException if an error occurs asking the configuration form for the room.
|
|
|
|
*/
|
|
|
|
public Form getConfigurationForm() throws XMPPException {
|
|
|
|
MUCOwner iq = new MUCOwner();
|
|
|
|
iq.setTo(room);
|
|
|
|
iq.setType(IQ.Type.GET);
|
|
|
|
|
|
|
|
// Filter packets looking for an answer from the server.
|
|
|
|
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
|
|
// Request the configuration form to the server.
|
|
|
|
connection.sendPacket(iq);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
|
|
|
return Form.getFormFrom(answer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends the completed configuration form to the server. The room will be configured
|
|
|
|
* with the new settings defined in the form. If the form is empty then the server
|
|
|
|
* will create an instant room (will use default configuration).
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param form the form with the new settings.
|
|
|
|
* @throws XMPPException if an error occurs setting the new rooms' configuration.
|
|
|
|
*/
|
|
|
|
public void sendConfigurationForm(Form form) throws XMPPException {
|
|
|
|
MUCOwner iq = new MUCOwner();
|
|
|
|
iq.setTo(room);
|
|
|
|
iq.setType(IQ.Type.SET);
|
|
|
|
iq.addExtension(form.getDataFormToSend());
|
|
|
|
|
|
|
|
// Filter packets looking for an answer from the server.
|
|
|
|
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
|
|
// Send the completed configuration form to the server.
|
|
|
|
connection.sendPacket(iq);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Returns the room's registration form that an unaffiliated user, can use to become a member
|
|
|
|
* of the room or <tt>null</tt> if no registration is possible. Some rooms may restrict the
|
2004-07-06 05:05:37 +02:00
|
|
|
* privilege to register members and allow only room admins to add new members.<p>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
|
|
|
* If the user requesting registration requirements is not allowed to register with the room
|
|
|
|
* (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
|
2004-07-06 05:05:37 +02:00
|
|
|
* error to the user (error code 405).
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
|
|
|
* @return the registration Form that contains the fields to complete together with the
|
2004-07-06 05:05:37 +02:00
|
|
|
* instrucions or <tt>null</tt> if no registration is possible.
|
2006-07-18 07:14:33 +02:00
|
|
|
* @throws XMPPException if an error occurs asking the registration form for the room or a
|
2004-07-06 05:05:37 +02:00
|
|
|
* 405 error if the user is not allowed to register with the room.
|
|
|
|
*/
|
|
|
|
public Form getRegistrationForm() throws XMPPException {
|
|
|
|
Registration reg = new Registration();
|
|
|
|
reg.setType(IQ.Type.GET);
|
|
|
|
reg.setTo(room);
|
|
|
|
|
|
|
|
PacketFilter filter =
|
|
|
|
new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
|
|
|
|
PacketCollector collector = connection.createPacketCollector(filter);
|
|
|
|
connection.sendPacket(reg);
|
|
|
|
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
collector.cancel();
|
|
|
|
if (result == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (result.getType() == IQ.Type.ERROR) {
|
|
|
|
throw new XMPPException(result.getError());
|
|
|
|
}
|
|
|
|
return Form.getFormFrom(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Sends the completed registration form to the server. After the user successfully submits
|
|
|
|
* the form, the room may queue the request for review by the room admins or may immediately
|
2004-07-06 05:05:37 +02:00
|
|
|
* add the user to the member list by changing the user's affiliation from "none" to "member.<p>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
|
|
|
* If the desired room nickname is already reserved for that room, the room will return a
|
|
|
|
* "Conflict" error to the user (error code 409). If the room does not support registration,
|
2004-07-06 05:05:37 +02:00
|
|
|
* it will return a "Service Unavailable" error to the user (error code 503).
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param form the completed registration form.
|
2006-07-18 07:14:33 +02:00
|
|
|
* @throws XMPPException if an error occurs submitting the registration form. In particular, a
|
|
|
|
* 409 error can occur if the desired room nickname is already reserved for that room;
|
2004-07-06 05:05:37 +02:00
|
|
|
* or a 503 error can occur if the room does not support registration.
|
|
|
|
*/
|
|
|
|
public void sendRegistrationForm(Form form) throws XMPPException {
|
|
|
|
Registration reg = new Registration();
|
|
|
|
reg.setType(IQ.Type.SET);
|
|
|
|
reg.setTo(room);
|
|
|
|
reg.addExtension(form.getDataFormToSend());
|
|
|
|
|
|
|
|
PacketFilter filter =
|
|
|
|
new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
|
|
|
|
PacketCollector collector = connection.createPacketCollector(filter);
|
|
|
|
connection.sendPacket(reg);
|
|
|
|
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
collector.cancel();
|
|
|
|
if (result == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (result.getType() == IQ.Type.ERROR) {
|
|
|
|
throw new XMPPException(result.getError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a request to the server to destroy the room. The sender of the request
|
|
|
|
* should be the room's owner. If the sender of the destroy request is not the room's owner
|
|
|
|
* then the server will answer a "Forbidden" error (403).
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param reason the reason for the room destruction.
|
|
|
|
* @param alternateJID the JID of an alternate location.
|
|
|
|
* @throws XMPPException if an error occurs while trying to destroy the room.
|
|
|
|
* An error can occur which will be wrapped by an XMPPException --
|
|
|
|
* XMPP error code 403. The error code can be used to present more
|
|
|
|
* appropiate error messages to end-users.
|
|
|
|
*/
|
|
|
|
public void destroy(String reason, String alternateJID) throws XMPPException {
|
|
|
|
MUCOwner iq = new MUCOwner();
|
|
|
|
iq.setTo(room);
|
|
|
|
iq.setType(IQ.Type.SET);
|
|
|
|
|
|
|
|
// Create the reason for the room destruction
|
|
|
|
MUCOwner.Destroy destroy = new MUCOwner.Destroy();
|
|
|
|
destroy.setReason(reason);
|
|
|
|
destroy.setJid(alternateJID);
|
|
|
|
iq.setDestroy(destroy);
|
|
|
|
|
|
|
|
// Wait for a presence packet back from the server.
|
|
|
|
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
|
|
// Send the room destruction request.
|
|
|
|
connection.sendPacket(iq);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
2004-12-15 20:03:37 +01:00
|
|
|
// Reset occupant information.
|
2006-07-18 07:14:33 +02:00
|
|
|
occupantsMap.clear();
|
2004-07-06 05:05:37 +02:00
|
|
|
nickname = null;
|
|
|
|
joined = false;
|
|
|
|
userHasLeft();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Invites another user to the room in which one is an occupant. The invitation
|
2004-07-06 05:05:37 +02:00
|
|
|
* will be sent to the room which in turn will forward the invitation to the invitee.<p>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* If the room is password-protected, the invitee will receive a password to use to join
|
|
|
|
* the room. If the room is members-only, the the invitee may be added to the member list.
|
2004-12-15 20:03:37 +01:00
|
|
|
*
|
|
|
|
* @param user the user to invite to the room.(e.g. hecate@shakespeare.lit)
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param reason the reason why the user is being invited.
|
|
|
|
*/
|
2004-12-15 20:03:37 +01:00
|
|
|
public void invite(String user, String reason) {
|
2005-01-11 18:35:41 +01:00
|
|
|
invite(new Message(), user, reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invites another user to the room in which one is an occupant using a given Message. The invitation
|
|
|
|
* will be sent to the room which in turn will forward the invitation to the invitee.<p>
|
|
|
|
*
|
|
|
|
* If the room is password-protected, the invitee will receive a password to use to join
|
|
|
|
* the room. If the room is members-only, the the invitee may be added to the member list.
|
|
|
|
*
|
|
|
|
* @param message the message to use for sending the invitation.
|
|
|
|
* @param user the user to invite to the room.(e.g. hecate@shakespeare.lit)
|
|
|
|
* @param reason the reason why the user is being invited.
|
|
|
|
*/
|
|
|
|
public void invite(Message message, String user, String reason) {
|
2004-07-06 05:05:37 +02:00
|
|
|
// TODO listen for 404 error code when inviter supplies a non-existent JID
|
2005-01-11 18:35:41 +01:00
|
|
|
message.setTo(room);
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
// Create the MUCUser packet that will include the invitation
|
|
|
|
MUCUser mucUser = new MUCUser();
|
|
|
|
MUCUser.Invite invite = new MUCUser.Invite();
|
2004-12-15 20:03:37 +01:00
|
|
|
invite.setTo(user);
|
2004-07-06 05:05:37 +02:00
|
|
|
invite.setReason(reason);
|
|
|
|
mucUser.setInvite(invite);
|
|
|
|
// Add the MUCUser packet that includes the invitation to the message
|
|
|
|
message.addExtension(mucUser);
|
|
|
|
|
|
|
|
connection.sendPacket(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Informs the sender of an invitation that the invitee declines the invitation. The rejection
|
2004-07-06 05:05:37 +02:00
|
|
|
* will be sent to the room which in turn will forward the rejection to the inviter.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param conn the connection to use for sending the rejection.
|
|
|
|
* @param room the room that sent the original invitation.
|
|
|
|
* @param inviter the inviter of the declined invitation.
|
|
|
|
* @param reason the reason why the invitee is declining the invitation.
|
|
|
|
*/
|
|
|
|
public static void decline(XMPPConnection conn, String room, String inviter, String reason) {
|
|
|
|
Message message = new Message(room);
|
|
|
|
|
|
|
|
// Create the MUCUser packet that will include the rejection
|
|
|
|
MUCUser mucUser = new MUCUser();
|
|
|
|
MUCUser.Decline decline = new MUCUser.Decline();
|
|
|
|
decline.setTo(inviter);
|
|
|
|
decline.setReason(reason);
|
|
|
|
mucUser.setDecline(decline);
|
|
|
|
// Add the MUCUser packet that includes the rejection
|
|
|
|
message.addExtension(mucUser);
|
|
|
|
|
|
|
|
conn.sendPacket(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Adds a listener to invitation notifications. The listener will be fired anytime
|
2004-07-06 05:05:37 +02:00
|
|
|
* an invitation is received.
|
|
|
|
*
|
|
|
|
* @param conn the connection where the listener will be applied.
|
|
|
|
* @param listener an invitation listener.
|
|
|
|
*/
|
|
|
|
public static void addInvitationListener(XMPPConnection conn, InvitationListener listener) {
|
|
|
|
InvitationsMonitor.getInvitationsMonitor(conn).addInvitationListener(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Removes a listener to invitation notifications. The listener will be fired anytime
|
2004-07-06 05:05:37 +02:00
|
|
|
* an invitation is received.
|
|
|
|
*
|
|
|
|
* @param conn the connection where the listener was applied.
|
|
|
|
* @param listener an invitation listener.
|
|
|
|
*/
|
|
|
|
public static void removeInvitationListener(XMPPConnection conn, InvitationListener listener) {
|
|
|
|
InvitationsMonitor.getInvitationsMonitor(conn).removeInvitationListener(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Adds a listener to invitation rejections notifications. The listener will be fired anytime
|
2004-07-06 05:05:37 +02:00
|
|
|
* an invitation is declined.
|
|
|
|
*
|
|
|
|
* @param listener an invitation rejection listener.
|
|
|
|
*/
|
|
|
|
public void addInvitationRejectionListener(InvitationRejectionListener listener) {
|
|
|
|
synchronized (invitationRejectionListeners) {
|
|
|
|
if (!invitationRejectionListeners.contains(listener)) {
|
|
|
|
invitationRejectionListeners.add(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Removes a listener from invitation rejections notifications. The listener will be fired
|
2004-07-06 05:05:37 +02:00
|
|
|
* anytime an invitation is declined.
|
|
|
|
*
|
|
|
|
* @param listener an invitation rejection listener.
|
|
|
|
*/
|
|
|
|
public void removeInvitationRejectionListener(InvitationRejectionListener listener) {
|
|
|
|
synchronized (invitationRejectionListeners) {
|
|
|
|
invitationRejectionListeners.remove(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires invitation rejection listeners.
|
2006-11-21 00:09:11 +01:00
|
|
|
*
|
|
|
|
* @param invitee the user being invited.
|
|
|
|
* @param reason the reason for the rejection
|
2004-07-06 05:05:37 +02:00
|
|
|
*/
|
|
|
|
private void fireInvitationRejectionListeners(String invitee, String reason) {
|
2006-07-18 07:14:33 +02:00
|
|
|
InvitationRejectionListener[] listeners;
|
2004-07-06 05:05:37 +02:00
|
|
|
synchronized (invitationRejectionListeners) {
|
|
|
|
listeners = new InvitationRejectionListener[invitationRejectionListeners.size()];
|
|
|
|
invitationRejectionListeners.toArray(listeners);
|
|
|
|
}
|
2006-07-18 07:14:33 +02:00
|
|
|
for (InvitationRejectionListener listener : listeners) {
|
|
|
|
listener.invitationDeclined(invitee, reason);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
2006-07-18 07:14:33 +02:00
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Adds a listener to subject change notifications. The listener will be fired anytime
|
2004-07-06 05:05:37 +02:00
|
|
|
* the room's subject changes.
|
|
|
|
*
|
|
|
|
* @param listener a subject updated listener.
|
|
|
|
*/
|
|
|
|
public void addSubjectUpdatedListener(SubjectUpdatedListener listener) {
|
|
|
|
synchronized (subjectUpdatedListeners) {
|
|
|
|
if (!subjectUpdatedListeners.contains(listener)) {
|
|
|
|
subjectUpdatedListeners.add(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Removes a listener from subject change notifications. The listener will be fired
|
2004-07-06 05:05:37 +02:00
|
|
|
* anytime the room's subject changes.
|
|
|
|
*
|
|
|
|
* @param listener a subject updated listener.
|
|
|
|
*/
|
|
|
|
public void removeSubjectUpdatedListener(SubjectUpdatedListener listener) {
|
|
|
|
synchronized (subjectUpdatedListeners) {
|
|
|
|
subjectUpdatedListeners.remove(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires subject updated listeners.
|
|
|
|
*/
|
|
|
|
private void fireSubjectUpdatedListeners(String subject, String from) {
|
2006-07-18 07:14:33 +02:00
|
|
|
SubjectUpdatedListener[] listeners;
|
2004-07-06 05:05:37 +02:00
|
|
|
synchronized (subjectUpdatedListeners) {
|
|
|
|
listeners = new SubjectUpdatedListener[subjectUpdatedListeners.size()];
|
|
|
|
subjectUpdatedListeners.toArray(listeners);
|
|
|
|
}
|
2006-07-18 07:14:33 +02:00
|
|
|
for (SubjectUpdatedListener listener : listeners) {
|
|
|
|
listener.subjectUpdated(subject, from);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:59:50 +01:00
|
|
|
/**
|
|
|
|
* Adds a new {@link PacketInterceptor} that will be invoked every time a new presence
|
|
|
|
* is going to be sent by this MultiUserChat to the server. Packet interceptors may
|
|
|
|
* add new extensions to the presence that is going to be sent to the MUC service.
|
|
|
|
*
|
|
|
|
* @param presenceInterceptor the new packet interceptor that will intercept presence packets.
|
|
|
|
*/
|
|
|
|
public void addPresenceInterceptor(PacketInterceptor presenceInterceptor) {
|
|
|
|
presenceInterceptors.add(presenceInterceptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a {@link PacketInterceptor} that was being invoked every time a new presence
|
|
|
|
* was being sent by this MultiUserChat to the server. Packet interceptors may
|
|
|
|
* add new extensions to the presence that is going to be sent to the MUC service.
|
|
|
|
*
|
|
|
|
* @param presenceInterceptor the packet interceptor to remove.
|
|
|
|
*/
|
|
|
|
public void removePresenceInterceptor(PacketInterceptor presenceInterceptor) {
|
|
|
|
presenceInterceptors.remove(presenceInterceptor);
|
|
|
|
}
|
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Returns the last known room's subject or <tt>null</tt> if the user hasn't joined the room
|
|
|
|
* or the room does not have a subject yet. In case the room has a subject, as soon as the
|
2004-07-06 05:05:37 +02:00
|
|
|
* user joins the room a message with the current room's subject will be received.<p>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* To be notified every time the room's subject change you should add a listener
|
|
|
|
* to this room. {@link #addSubjectUpdatedListener(SubjectUpdatedListener)}<p>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* To change the room's subject use {@link #changeSubject(String)}.
|
|
|
|
*
|
2006-07-18 07:14:33 +02:00
|
|
|
* @return the room's subject or <tt>null</tt> if the user hasn't joined the room or the
|
2004-07-06 05:05:37 +02:00
|
|
|
* room does not have a subject yet.
|
|
|
|
*/
|
|
|
|
public String getSubject() {
|
|
|
|
return subject;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Returns the reserved room nickname for the user in the room. A user may have a reserved
|
|
|
|
* nickname, for example through explicit room registration or database integration. In such
|
|
|
|
* cases it may be desirable for the user to discover the reserved nickname before attempting
|
2004-07-06 05:05:37 +02:00
|
|
|
* to enter the room.
|
|
|
|
*
|
|
|
|
* @return the reserved room nickname or <tt>null</tt> if none.
|
|
|
|
*/
|
|
|
|
public String getReservedNickname() {
|
|
|
|
try {
|
|
|
|
DiscoverInfo result =
|
|
|
|
ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(
|
|
|
|
room,
|
|
|
|
"x-roomuser-item");
|
2006-07-18 07:14:33 +02:00
|
|
|
// Look for an Identity that holds the reserved nickname and return its name
|
|
|
|
for (Iterator<DiscoverInfo.Identity> identities = result.getIdentities();
|
|
|
|
identities.hasNext();) {
|
|
|
|
DiscoverInfo.Identity identity = identities.next();
|
2004-07-06 05:05:37 +02:00
|
|
|
return identity.getName();
|
|
|
|
}
|
|
|
|
// If no Identity was found then the user does not have a reserved room nickname
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
catch (XMPPException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the nickname that was used to join the room, or <tt>null</tt> if not
|
|
|
|
* currently joined.
|
|
|
|
*
|
|
|
|
* @return the nickname currently being used.
|
|
|
|
*/
|
|
|
|
public String getNickname() {
|
|
|
|
return nickname;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Changes the occupant's nickname to a new nickname within the room. Each room occupant
|
2006-07-18 07:14:33 +02:00
|
|
|
* will receive two presence packets. One of type "unavailable" for the old nickname and one
|
|
|
|
* indicating availability for the new nickname. The unavailable presence will contain the new
|
|
|
|
* nickname and an appropriate status code (namely 303) as extended presence information. The
|
2004-12-15 20:03:37 +01:00
|
|
|
* status code 303 indicates that the occupant is changing his/her nickname.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param nickname the new nickname within the room.
|
|
|
|
* @throws XMPPException if the new nickname is already in use by another occupant.
|
|
|
|
*/
|
|
|
|
public void changeNickname(String nickname) throws XMPPException {
|
|
|
|
if (nickname == null || nickname.equals("")) {
|
|
|
|
throw new IllegalArgumentException("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.");
|
|
|
|
}
|
|
|
|
// 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
|
2006-07-17 10:39:08 +02:00
|
|
|
Presence joinPresence = new Presence(Presence.Type.available);
|
2004-07-06 05:05:37 +02:00
|
|
|
joinPresence.setTo(room + "/" + nickname);
|
2006-02-27 22:59:50 +01:00
|
|
|
// Invoke presence interceptors so that extra information can be dynamically added
|
2006-07-18 07:14:33 +02:00
|
|
|
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
|
2006-02-27 22:59:50 +01:00
|
|
|
packetInterceptor.interceptPacket(joinPresence);
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
// Wait for a presence packet back from the server.
|
|
|
|
PacketFilter responseFilter =
|
|
|
|
new AndFilter(
|
2005-08-10 06:50:50 +02:00
|
|
|
new FromMatchesFilter(room + "/" + nickname),
|
2004-07-06 05:05:37 +02:00
|
|
|
new PacketTypeFilter(Presence.class));
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
|
|
// Send join packet.
|
|
|
|
connection.sendPacket(joinPresence);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
Presence presence =
|
|
|
|
(Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (presence == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (presence.getError() != null) {
|
|
|
|
throw new XMPPException(presence.getError());
|
|
|
|
}
|
|
|
|
this.nickname = nickname;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Changes the occupant's availability status within the room. The presence type
|
2004-07-06 05:05:37 +02:00
|
|
|
* will remain available but with a new status that describes the presence update and
|
|
|
|
* a new presence mode (e.g. Extended away).
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param status a text message describing the presence update.
|
|
|
|
* @param mode the mode type for the presence update.
|
|
|
|
*/
|
|
|
|
public void changeAvailabilityStatus(String status, Presence.Mode mode) {
|
|
|
|
if (nickname == null || nickname.equals("")) {
|
|
|
|
throw new IllegalArgumentException("Nickname must not be null or blank.");
|
|
|
|
}
|
|
|
|
// Check that we already have joined the room before attempting to change the
|
|
|
|
// availability status.
|
|
|
|
if (!joined) {
|
|
|
|
throw new IllegalStateException(
|
|
|
|
"Must be logged into the room to change the " + "availability status.");
|
|
|
|
}
|
|
|
|
// We change the availability status by sending a presence packet to the room with the
|
|
|
|
// new presence status and mode
|
2006-07-17 10:39:08 +02:00
|
|
|
Presence joinPresence = new Presence(Presence.Type.available);
|
2004-07-06 05:05:37 +02:00
|
|
|
joinPresence.setStatus(status);
|
|
|
|
joinPresence.setMode(mode);
|
|
|
|
joinPresence.setTo(room + "/" + nickname);
|
2006-02-27 22:59:50 +01:00
|
|
|
// Invoke presence interceptors so that extra information can be dynamically added
|
2006-07-18 07:14:33 +02:00
|
|
|
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
|
2006-02-27 22:59:50 +01:00
|
|
|
packetInterceptor.interceptPacket(joinPresence);
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
// Send join packet.
|
|
|
|
connection.sendPacket(joinPresence);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Kicks a visitor or participant from the room. The kicked occupant will receive a presence
|
2006-07-18 07:14:33 +02:00
|
|
|
* of type "unavailable" including a status code 307 and optionally along with the reason
|
2004-12-15 20:03:37 +01:00
|
|
|
* (if provided) and the bare JID of the user who initiated the kick. After the occupant
|
|
|
|
* was kicked from the room, the rest of the occupants will receive a presence of type
|
|
|
|
* "unavailable". The presence will include a status code 307 which means that the occupant
|
2006-07-18 07:14:33 +02:00
|
|
|
* was kicked from the room.
|
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param nickname the nickname of the participant or visitor to kick from the room
|
2004-07-06 05:05:37 +02:00
|
|
|
* (e.g. "john").
|
|
|
|
* @param reason the reason why the participant or visitor is being kicked from the room.
|
2004-12-15 20:03:37 +01:00
|
|
|
* @throws XMPPException if an error occurs kicking the occupant. In particular, a
|
2004-07-06 05:05:37 +02:00
|
|
|
* 405 error can occur if a moderator or a user with an affiliation of "owner" or "admin"
|
|
|
|
* was intended to be kicked (i.e. Not Allowed error); or a
|
2004-12-15 20:03:37 +01:00
|
|
|
* 403 error can occur if the occupant that intended to kick another occupant does
|
2004-07-06 05:05:37 +02:00
|
|
|
* not have kicking privileges (i.e. Forbidden error); or a
|
|
|
|
* 400 error can occur if the provided nickname is not present in the room.
|
|
|
|
*/
|
|
|
|
public void kickParticipant(String nickname, String reason) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeRole(nickname, "none", reason);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Grants voice to visitors in the room. In a moderated room, a moderator may want to manage
|
|
|
|
* who does and does not have "voice" in the room. To have voice means that a room occupant
|
2004-07-06 05:05:37 +02:00
|
|
|
* is able to send messages to the room occupants.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param nicknames the nicknames of the visitors to grant voice in the room (e.g. "john").
|
2006-07-18 07:14:33 +02:00
|
|
|
* @throws XMPPException if an error occurs granting voice to a visitor. In particular, a
|
2004-12-15 20:03:37 +01:00
|
|
|
* 403 error can occur if the occupant that intended to grant voice is not
|
2004-07-06 05:05:37 +02:00
|
|
|
* a moderator in this room (i.e. Forbidden error); or a
|
|
|
|
* 400 error can occur if the provided nickname is not present in the room.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public void grantVoice(Collection<String> nicknames) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeRole(nicknames, "participant");
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
|
2004-12-15 20:03:37 +01:00
|
|
|
/**
|
|
|
|
* Grants voice to a visitor in the room. In a moderated room, a moderator may want to manage
|
|
|
|
* who does and does not have "voice" in the room. To have voice means that a room occupant
|
|
|
|
* is able to send messages to the room occupants.
|
|
|
|
*
|
|
|
|
* @param nickname the nickname of the visitor to grant voice in the room (e.g. "john").
|
|
|
|
* @throws XMPPException if an error occurs granting voice to a visitor. In particular, a
|
|
|
|
* 403 error can occur if the occupant that intended to grant voice is not
|
|
|
|
* a moderator in this room (i.e. Forbidden error); or a
|
|
|
|
* 400 error can occur if the provided nickname is not present in the room.
|
|
|
|
*/
|
|
|
|
public void grantVoice(String nickname) throws XMPPException {
|
|
|
|
changeRole(nickname, "participant", null);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Revokes voice from participants in the room. In a moderated room, a moderator may want to
|
|
|
|
* revoke an occupant's privileges to speak. To have voice means that a room occupant
|
2004-07-06 05:05:37 +02:00
|
|
|
* is able to send messages to the room occupants.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param nicknames the nicknames of the participants to revoke voice (e.g. "john").
|
|
|
|
* @throws XMPPException if an error occurs revoking voice from a participant. In particular, a
|
|
|
|
* 405 error can occur if a moderator or a user with an affiliation of "owner" or "admin"
|
|
|
|
* was tried to revoke his voice (i.e. Not Allowed error); or a
|
|
|
|
* 400 error can occur if the provided nickname is not present in the room.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public void revokeVoice(Collection<String> nicknames) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeRole(nicknames, "visitor");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Revokes voice from a participant in the room. In a moderated room, a moderator may want to
|
|
|
|
* revoke an occupant's privileges to speak. To have voice means that a room occupant
|
|
|
|
* is able to send messages to the room occupants.
|
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param nickname the nickname of the participant to revoke voice (e.g. "john").
|
2004-12-15 20:03:37 +01:00
|
|
|
* @throws XMPPException if an error occurs revoking voice from a participant. In particular, a
|
2004-07-06 05:05:37 +02:00
|
|
|
* 405 error can occur if a moderator or a user with an affiliation of "owner" or "admin"
|
|
|
|
* was tried to revoke his voice (i.e. Not Allowed error); or a
|
|
|
|
* 400 error can occur if the provided nickname is not present in the room.
|
|
|
|
*/
|
|
|
|
public void revokeVoice(String nickname) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeRole(nickname, "visitor", null);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Bans users from the room. An admin or owner of the room can ban users from a room. This
|
2006-07-18 07:14:33 +02:00
|
|
|
* means that the banned user will no longer be able to join the room unless the ban has been
|
|
|
|
* removed. If the banned user was present in the room then he/she will be removed from the
|
|
|
|
* room and notified that he/she was banned along with the reason (if provided) and the bare
|
|
|
|
* XMPP user ID of the user who initiated the ban.
|
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param jids the bare XMPP user IDs of the users to ban.
|
|
|
|
* @throws XMPPException if an error occurs banning a user. In particular, a
|
|
|
|
* 405 error can occur if a moderator or a user with an affiliation of "owner" or "admin"
|
|
|
|
* was tried to be banned (i.e. Not Allowed error).
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public void banUsers(Collection<String> jids) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeAffiliationByAdmin(jids, "outcast");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bans a user from the room. An admin or owner of the room can ban users from a room. This
|
|
|
|
* means that the banned user will no longer be able to join the room unless the ban has been
|
|
|
|
* removed. If the banned user was present in the room then he/she will be removed from the
|
|
|
|
* room and notified that he/she was banned along with the reason (if provided) and the bare
|
|
|
|
* XMPP user ID of the user who initiated the ban.
|
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param jid the bare XMPP user ID of the user to ban (e.g. "user@host.org").
|
|
|
|
* @param reason the reason why the user was banned.
|
2004-12-15 20:03:37 +01:00
|
|
|
* @throws XMPPException if an error occurs banning a user. In particular, a
|
2004-07-06 05:05:37 +02:00
|
|
|
* 405 error can occur if a moderator or a user with an affiliation of "owner" or "admin"
|
|
|
|
* was tried to be banned (i.e. Not Allowed error).
|
|
|
|
*/
|
|
|
|
public void banUser(String jid, String reason) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeAffiliationByAdmin(jid, "outcast", reason);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Grants membership to other users. Only administrators are able to grant membership. A user
|
2004-07-06 05:05:37 +02:00
|
|
|
* that becomes a room member will be able to enter a room of type Members-Only (i.e. a room
|
2006-07-18 07:14:33 +02:00
|
|
|
* that a user cannot enter without being on the member list).
|
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param jids the XMPP user IDs of the users to grant membership.
|
|
|
|
* @throws XMPPException if an error occurs granting membership to a user.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public void grantMembership(Collection<String> jids) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeAffiliationByAdmin(jids, "member");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Grants membership to a user. Only administrators are able to grant membership. A user
|
|
|
|
* that becomes a room member will be able to enter a room of type Members-Only (i.e. a room
|
|
|
|
* that a user cannot enter without being on the member list).
|
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param jid the XMPP user ID of the user to grant membership (e.g. "user@host.org").
|
|
|
|
* @throws XMPPException if an error occurs granting membership to a user.
|
|
|
|
*/
|
|
|
|
public void grantMembership(String jid) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeAffiliationByAdmin(jid, "member", null);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Revokes users' membership. Only administrators are able to revoke membership. A user
|
2004-07-06 05:05:37 +02:00
|
|
|
* that becomes a room member will be able to enter a room of type Members-Only (i.e. a room
|
2006-07-18 07:14:33 +02:00
|
|
|
* that a user cannot enter without being on the member list). If the user is in the room and
|
2004-07-06 05:05:37 +02:00
|
|
|
* the room is of type members-only then the user will be removed from the room.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param jids the bare XMPP user IDs of the users to revoke membership.
|
2004-07-06 05:05:37 +02:00
|
|
|
* @throws XMPPException if an error occurs revoking membership to a user.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public void revokeMembership(Collection<String> jids) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeAffiliationByAdmin(jids, "none");
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
|
2004-12-15 20:03:37 +01:00
|
|
|
/**
|
|
|
|
* Revokes a user's membership. Only administrators are able to revoke membership. A user
|
|
|
|
* that becomes a room member will be able to enter a room of type Members-Only (i.e. a room
|
|
|
|
* that a user cannot enter without being on the member list). If the user is in the room and
|
|
|
|
* the room is of type members-only then the user will be removed from the room.
|
|
|
|
*
|
|
|
|
* @param jid the bare XMPP user ID of the user to revoke membership (e.g. "user@host.org").
|
|
|
|
* @throws XMPPException if an error occurs revoking membership to a user.
|
|
|
|
*/
|
|
|
|
public void revokeMembership(String jid) throws XMPPException {
|
|
|
|
changeAffiliationByAdmin(jid, "none", null);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Grants moderator privileges to participants or visitors. Room administrators may grant
|
2006-07-18 07:14:33 +02:00
|
|
|
* moderator privileges. A moderator is allowed to kick users, grant and revoke voice, invite
|
2004-07-06 05:05:37 +02:00
|
|
|
* other users, modify room's subject plus all the partcipants privileges.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param nicknames the nicknames of the occupants to grant moderator privileges.
|
|
|
|
* @throws XMPPException if an error occurs granting moderator privileges to a user.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public void grantModerator(Collection<String> nicknames) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeRole(nicknames, "moderator");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Grants moderator privileges to a participant or visitor. Room administrators may grant
|
|
|
|
* moderator privileges. A moderator is allowed to kick users, grant and revoke voice, invite
|
|
|
|
* other users, modify room's subject plus all the partcipants privileges.
|
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param nickname the nickname of the occupant to grant moderator privileges.
|
|
|
|
* @throws XMPPException if an error occurs granting moderator privileges to a user.
|
|
|
|
*/
|
|
|
|
public void grantModerator(String nickname) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeRole(nickname, "moderator", null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Revokes moderator privileges from other users. The occupant that loses moderator
|
|
|
|
* privileges will become a participant. Room administrators may revoke moderator privileges
|
2006-07-18 07:14:33 +02:00
|
|
|
* only to occupants whose affiliation is member or none. This means that an administrator is
|
2004-12-15 20:03:37 +01:00
|
|
|
* not allowed to revoke moderator privileges from other room administrators or owners.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param nicknames the nicknames of the occupants to revoke moderator privileges.
|
|
|
|
* @throws XMPPException if an error occurs revoking moderator privileges from a user.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public void revokeModerator(Collection<String> nicknames) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeRole(nicknames, "participant");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Revokes moderator privileges from another user. The occupant that loses moderator
|
|
|
|
* privileges will become a participant. Room administrators may revoke moderator privileges
|
|
|
|
* only to occupants whose affiliation is member or none. This means that an administrator is
|
|
|
|
* not allowed to revoke moderator privileges from other room administrators or owners.
|
|
|
|
*
|
|
|
|
* @param nickname the nickname of the occupant to revoke moderator privileges.
|
|
|
|
* @throws XMPPException if an error occurs revoking moderator privileges from a user.
|
|
|
|
*/
|
|
|
|
public void revokeModerator(String nickname) throws XMPPException {
|
|
|
|
changeRole(nickname, "participant", null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Grants ownership privileges to other users. Room owners may grant ownership privileges.
|
|
|
|
* Some room implementations will not allow to grant ownership privileges to other users.
|
|
|
|
* An owner is allowed to change defining room features as well as perform all administrative
|
|
|
|
* functions.
|
|
|
|
*
|
|
|
|
* @param jids the collection of bare XMPP user IDs of the users to grant ownership.
|
|
|
|
* @throws XMPPException if an error occurs granting ownership privileges to a user.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public void grantOwnership(Collection<String> jids) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeAffiliationByOwner(jids, "owner");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Grants ownership privileges to another user. Room owners may grant ownership privileges.
|
2004-12-15 20:03:37 +01:00
|
|
|
* Some room implementations will not allow to grant ownership privileges to other users.
|
2006-07-18 07:14:33 +02:00
|
|
|
* An owner is allowed to change defining room features as well as perform all administrative
|
2004-12-15 20:03:37 +01:00
|
|
|
* functions.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param jid the bare XMPP user ID of the user to grant ownership (e.g. "user@host.org").
|
|
|
|
* @throws XMPPException if an error occurs granting ownership privileges to a user.
|
|
|
|
*/
|
|
|
|
public void grantOwnership(String jid) throws XMPPException {
|
|
|
|
changeAffiliationByOwner(jid, "owner");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Revokes ownership privileges from other users. The occupant that loses ownership
|
|
|
|
* privileges will become an administrator. Room owners may revoke ownership privileges.
|
|
|
|
* Some room implementations will not allow to grant ownership privileges to other users.
|
|
|
|
*
|
|
|
|
* @param jids the bare XMPP user IDs of the users to revoke ownership.
|
|
|
|
* @throws XMPPException if an error occurs revoking ownership privileges from a user.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public void revokeOwnership(Collection<String> jids) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeAffiliationByOwner(jids, "admin");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Revokes ownership privileges from another user. The occupant that loses ownership
|
|
|
|
* privileges will become an administrator. Room owners may revoke ownership privileges.
|
2004-12-15 20:03:37 +01:00
|
|
|
* Some room implementations will not allow to grant ownership privileges to other users.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param jid the bare XMPP user ID of the user to revoke ownership (e.g. "user@host.org").
|
|
|
|
* @throws XMPPException if an error occurs revoking ownership privileges from a user.
|
|
|
|
*/
|
|
|
|
public void revokeOwnership(String jid) throws XMPPException {
|
|
|
|
changeAffiliationByOwner(jid, "admin");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Grants administrator privileges to other users. Room owners may grant administrator
|
|
|
|
* privileges to a member or unaffiliated user. An administrator is allowed to perform
|
|
|
|
* administrative functions such as banning users and edit moderator list.
|
|
|
|
*
|
|
|
|
* @param jids the bare XMPP user IDs of the users to grant administrator privileges.
|
|
|
|
* @throws XMPPException if an error occurs granting administrator privileges to a user.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public void grantAdmin(Collection<String> jids) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeAffiliationByOwner(jids, "admin");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Grants administrator privileges to another user. Room owners may grant administrator
|
|
|
|
* privileges to a member or unaffiliated user. An administrator is allowed to perform
|
|
|
|
* administrative functions such as banning users and edit moderator list.
|
|
|
|
*
|
|
|
|
* @param jid the bare XMPP user ID of the user to grant administrator privileges
|
2004-12-15 20:03:37 +01:00
|
|
|
* (e.g. "user@host.org").
|
|
|
|
* @throws XMPPException if an error occurs granting administrator privileges to a user.
|
|
|
|
*/
|
|
|
|
public void grantAdmin(String jid) throws XMPPException {
|
|
|
|
changeAffiliationByOwner(jid, "admin");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Revokes administrator privileges from users. The occupant that loses administrator
|
2006-07-18 07:14:33 +02:00
|
|
|
* privileges will become a member. Room owners may revoke administrator privileges from
|
|
|
|
* a member or unaffiliated user.
|
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param jids the bare XMPP user IDs of the user to revoke administrator privileges.
|
|
|
|
* @throws XMPPException if an error occurs revoking administrator privileges from a user.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public void revokeAdmin(Collection<String> jids) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
changeAffiliationByOwner(jids, "member");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Revokes administrator privileges from a user. The occupant that loses administrator
|
|
|
|
* privileges will become a member. Room owners may revoke administrator privileges from
|
|
|
|
* a member or unaffiliated user.
|
|
|
|
*
|
|
|
|
* @param jid the bare XMPP user ID of the user to revoke administrator privileges
|
|
|
|
* (e.g. "user@host.org").
|
|
|
|
* @throws XMPPException if an error occurs revoking administrator privileges from a user.
|
|
|
|
*/
|
|
|
|
public void revokeAdmin(String jid) throws XMPPException {
|
|
|
|
changeAffiliationByOwner(jid, "member");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void changeAffiliationByOwner(String jid, String affiliation) throws XMPPException {
|
|
|
|
MUCOwner iq = new MUCOwner();
|
2004-07-06 05:05:37 +02:00
|
|
|
iq.setTo(room);
|
|
|
|
iq.setType(IQ.Type.SET);
|
2004-12-15 20:03:37 +01:00
|
|
|
// Set the new affiliation.
|
|
|
|
MUCOwner.Item item = new MUCOwner.Item(affiliation);
|
|
|
|
item.setJid(jid);
|
2004-07-06 05:05:37 +02:00
|
|
|
iq.addItem(item);
|
|
|
|
|
|
|
|
// Wait for a response packet back from the server.
|
|
|
|
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
2004-12-15 20:03:37 +01:00
|
|
|
// Send the change request to the server.
|
2004-07-06 05:05:37 +02:00
|
|
|
connection.sendPacket(iq);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-18 07:14:33 +02:00
|
|
|
private void changeAffiliationByOwner(Collection<String> jids, String affiliation)
|
2004-12-15 20:03:37 +01:00
|
|
|
throws XMPPException {
|
|
|
|
MUCOwner iq = new MUCOwner();
|
2004-07-06 05:05:37 +02:00
|
|
|
iq.setTo(room);
|
|
|
|
iq.setType(IQ.Type.SET);
|
2006-07-18 07:14:33 +02:00
|
|
|
for (String jid : jids) {
|
2004-12-15 20:03:37 +01:00
|
|
|
// Set the new affiliation.
|
|
|
|
MUCOwner.Item item = new MUCOwner.Item(affiliation);
|
2006-07-18 07:14:33 +02:00
|
|
|
item.setJid(jid);
|
2004-12-15 20:03:37 +01:00
|
|
|
iq.addItem(item);
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
// Wait for a response packet back from the server.
|
|
|
|
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
2004-12-15 20:03:37 +01:00
|
|
|
// Send the change request to the server.
|
2004-07-06 05:05:37 +02:00
|
|
|
connection.sendPacket(iq);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-15 20:03:37 +01:00
|
|
|
private void changeAffiliationByAdmin(String jid, String affiliation, String reason)
|
|
|
|
throws XMPPException {
|
|
|
|
MUCAdmin iq = new MUCAdmin();
|
2004-07-06 05:05:37 +02:00
|
|
|
iq.setTo(room);
|
|
|
|
iq.setType(IQ.Type.SET);
|
2004-12-15 20:03:37 +01:00
|
|
|
// Set the new affiliation.
|
|
|
|
MUCAdmin.Item item = new MUCAdmin.Item(affiliation, null);
|
2004-07-06 05:05:37 +02:00
|
|
|
item.setJid(jid);
|
2004-12-15 20:03:37 +01:00
|
|
|
item.setReason(reason);
|
2004-07-06 05:05:37 +02:00
|
|
|
iq.addItem(item);
|
|
|
|
|
|
|
|
// Wait for a response packet back from the server.
|
|
|
|
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
2004-12-15 20:03:37 +01:00
|
|
|
// Send the change request to the server.
|
2004-07-06 05:05:37 +02:00
|
|
|
connection.sendPacket(iq);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-18 07:14:33 +02:00
|
|
|
private void changeAffiliationByAdmin(Collection<String> jids, String affiliation)
|
2004-12-15 20:03:37 +01:00
|
|
|
throws XMPPException {
|
|
|
|
MUCAdmin iq = new MUCAdmin();
|
2004-07-06 05:05:37 +02:00
|
|
|
iq.setTo(room);
|
|
|
|
iq.setType(IQ.Type.SET);
|
2006-07-18 07:14:33 +02:00
|
|
|
for (String jid : jids) {
|
2004-12-15 20:03:37 +01:00
|
|
|
// Set the new affiliation.
|
|
|
|
MUCAdmin.Item item = new MUCAdmin.Item(affiliation, null);
|
2006-07-18 07:14:33 +02:00
|
|
|
item.setJid(jid);
|
2004-12-15 20:03:37 +01:00
|
|
|
iq.addItem(item);
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
// Wait for a response packet back from the server.
|
|
|
|
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
2004-12-15 20:03:37 +01:00
|
|
|
// Send the change request to the server.
|
2004-07-06 05:05:37 +02:00
|
|
|
connection.sendPacket(iq);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-15 20:03:37 +01:00
|
|
|
private void changeRole(String nickname, String role, String reason) throws XMPPException {
|
|
|
|
MUCAdmin iq = new MUCAdmin();
|
2004-07-06 05:05:37 +02:00
|
|
|
iq.setTo(room);
|
|
|
|
iq.setType(IQ.Type.SET);
|
2004-12-15 20:03:37 +01:00
|
|
|
// Set the new role.
|
|
|
|
MUCAdmin.Item item = new MUCAdmin.Item(null, role);
|
|
|
|
item.setNick(nickname);
|
|
|
|
item.setReason(reason);
|
2004-07-06 05:05:37 +02:00
|
|
|
iq.addItem(item);
|
|
|
|
|
|
|
|
// Wait for a response packet back from the server.
|
|
|
|
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
2004-12-15 20:03:37 +01:00
|
|
|
// Send the change request to the server.
|
2004-07-06 05:05:37 +02:00
|
|
|
connection.sendPacket(iq);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-18 07:14:33 +02:00
|
|
|
private void changeRole(Collection<String> nicknames, String role) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
MUCAdmin iq = new MUCAdmin();
|
2004-07-06 05:05:37 +02:00
|
|
|
iq.setTo(room);
|
|
|
|
iq.setType(IQ.Type.SET);
|
2006-07-18 07:14:33 +02:00
|
|
|
for (String nickname : nicknames) {
|
2004-12-15 20:03:37 +01:00
|
|
|
// Set the new role.
|
|
|
|
MUCAdmin.Item item = new MUCAdmin.Item(null, role);
|
2006-07-18 07:14:33 +02:00
|
|
|
item.setNick(nickname);
|
2004-12-15 20:03:37 +01:00
|
|
|
iq.addItem(item);
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
// Wait for a response packet back from the server.
|
|
|
|
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
2004-12-15 20:03:37 +01:00
|
|
|
// Send the change request to the server.
|
2004-07-06 05:05:37 +02:00
|
|
|
connection.sendPacket(iq);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Returns the number of occupants in the group chat.<p>
|
2004-07-06 05:05:37 +02:00
|
|
|
*
|
|
|
|
* Note: this value will only be accurate after joining the group chat, and
|
|
|
|
* may fluctuate over time. If you query this value directly after joining the
|
|
|
|
* group chat it may not be accurate, as it takes a certain amount of time for
|
|
|
|
* the server to send all presence packets to this client.
|
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @return the number of occupants in the group chat.
|
2004-07-06 05:05:37 +02:00
|
|
|
*/
|
2004-12-15 20:03:37 +01:00
|
|
|
public int getOccupantsCount() {
|
2006-07-18 07:14:33 +02:00
|
|
|
return occupantsMap.size();
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Returns an Iterator (of Strings) for the list of fully qualified occupants
|
2004-07-06 05:05:37 +02:00
|
|
|
* in the group chat. For example, "conference@chat.jivesoftware.com/SomeUser".
|
2004-12-15 20:03:37 +01:00
|
|
|
* Typically, a client would only display the nickname of the occupant. To
|
2004-07-06 05:05:37 +02:00
|
|
|
* get the nickname from the fully qualified name, use the
|
|
|
|
* {@link org.jivesoftware.smack.util.StringUtils#parseResource(String)} method.
|
|
|
|
* Note: this value will only be accurate after joining the group chat, and may
|
|
|
|
* fluctuate over time.
|
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @return an Iterator for the occupants in the group chat.
|
2004-07-06 05:05:37 +02:00
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public Iterator<String> getOccupants() {
|
|
|
|
return Collections.unmodifiableList(new ArrayList<String>(occupantsMap.keySet()))
|
|
|
|
.iterator();
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Returns the presence info for a particular user, or <tt>null</tt> if the user
|
2004-07-06 05:05:37 +02:00
|
|
|
* is not in the room.<p>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param user the room occupant to search for his presence. The format of user must
|
2004-07-06 05:05:37 +02:00
|
|
|
* be: roomName@service/nickname (e.g. darkcave@macbeth.shakespeare.lit/thirdwitch).
|
2004-12-15 20:03:37 +01:00
|
|
|
* @return the occupant's current presence, or <tt>null</tt> if the user is unavailable
|
2004-07-06 05:05:37 +02:00
|
|
|
* or if no presence information is available.
|
|
|
|
*/
|
2004-12-15 20:03:37 +01:00
|
|
|
public Presence getOccupantPresence(String user) {
|
2006-07-18 07:14:33 +02:00
|
|
|
return occupantsMap.get(user);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Returns the Occupant information for a particular occupant, or <tt>null</tt> if the
|
|
|
|
* user is not in the room. The Occupant object may include information such as full
|
|
|
|
* JID of the user as well as the role and affiliation of the user in the room.<p>
|
|
|
|
*
|
|
|
|
* @param user the room occupant to search for his presence. The format of user must
|
2004-07-06 05:05:37 +02:00
|
|
|
* be: roomName@service/nickname (e.g. darkcave@macbeth.shakespeare.lit/thirdwitch).
|
2004-12-15 20:03:37 +01:00
|
|
|
* @return the Occupant or <tt>null</tt> if the user is unavailable (i.e. not in the room).
|
2004-07-06 05:05:37 +02:00
|
|
|
*/
|
2004-12-15 20:03:37 +01:00
|
|
|
public Occupant getOccupant(String user) {
|
2006-07-18 07:14:33 +02:00
|
|
|
Presence presence = occupantsMap.get(user);
|
2004-12-15 20:03:37 +01:00
|
|
|
if (presence != null) {
|
|
|
|
return new Occupant(presence);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a packet listener that will be notified of any new Presence packets
|
|
|
|
* sent to the group chat. Using a listener is a suitable way to know when the list
|
2004-12-15 20:03:37 +01:00
|
|
|
* of occupants should be re-loaded due to any changes.
|
2004-07-06 05:05:37 +02:00
|
|
|
*
|
|
|
|
* @param listener a packet listener that will be notified of any presence packets
|
|
|
|
* sent to the group chat.
|
|
|
|
*/
|
|
|
|
public void addParticipantListener(PacketListener listener) {
|
|
|
|
connection.addPacketListener(listener, presenceFilter);
|
2005-03-07 23:01:18 +01:00
|
|
|
connectionListeners.add(listener);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remoces a packet listener that was being notified of any new Presence packets
|
|
|
|
* sent to the group chat.
|
|
|
|
*
|
|
|
|
* @param listener a packet listener that was being notified of any presence packets
|
|
|
|
* sent to the group chat.
|
|
|
|
*/
|
|
|
|
public void removeParticipantListener(PacketListener listener) {
|
|
|
|
connection.removePacketListener(listener);
|
2005-03-07 23:01:18 +01:00
|
|
|
connectionListeners.remove(listener);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
2004-12-15 20:03:37 +01:00
|
|
|
/**
|
|
|
|
* Returns a collection of <code>Affiliate</code> with the room owners.
|
|
|
|
*
|
|
|
|
* @return a collection of <code>Affiliate</code> with the room owners.
|
|
|
|
* @throws XMPPException if an error occured while performing the request to the server or you
|
|
|
|
* don't have enough privileges to get this information.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public Collection<Affiliate> getOwners() throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
return getAffiliatesByOwner("owner");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a collection of <code>Affiliate</code> with the room administrators.
|
|
|
|
*
|
|
|
|
* @return a collection of <code>Affiliate</code> with the room administrators.
|
|
|
|
* @throws XMPPException if an error occured while performing the request to the server or you
|
|
|
|
* don't have enough privileges to get this information.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public Collection<Affiliate> getAdmins() throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
return getAffiliatesByOwner("admin");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a collection of <code>Affiliate</code> with the room members.
|
|
|
|
*
|
|
|
|
* @return a collection of <code>Affiliate</code> with the room members.
|
|
|
|
* @throws XMPPException if an error occured while performing the request to the server or you
|
|
|
|
* don't have enough privileges to get this information.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public Collection<Affiliate> getMembers() throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
return getAffiliatesByAdmin("member");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a collection of <code>Affiliate</code> with the room outcasts.
|
|
|
|
*
|
|
|
|
* @return a collection of <code>Affiliate</code> with the room outcasts.
|
|
|
|
* @throws XMPPException if an error occured while performing the request to the server or you
|
|
|
|
* don't have enough privileges to get this information.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public Collection<Affiliate> getOutcasts() throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
return getAffiliatesByAdmin("outcast");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a collection of <code>Affiliate</code> that have the specified room affiliation
|
|
|
|
* sending a request in the owner namespace.
|
|
|
|
*
|
|
|
|
* @param affiliation the affiliation of the users in the room.
|
|
|
|
* @return a collection of <code>Affiliate</code> that have the specified room affiliation.
|
|
|
|
* @throws XMPPException if an error occured while performing the request to the server or you
|
|
|
|
* don't have enough privileges to get this information.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
private Collection<Affiliate> getAffiliatesByOwner(String affiliation) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
MUCOwner iq = new MUCOwner();
|
|
|
|
iq.setTo(room);
|
|
|
|
iq.setType(IQ.Type.GET);
|
|
|
|
// Set the specified affiliation. This may request the list of owners/admins/members/outcasts.
|
|
|
|
MUCOwner.Item item = new MUCOwner.Item(affiliation);
|
|
|
|
iq.addItem(item);
|
|
|
|
|
|
|
|
// Wait for a response packet back from the server.
|
|
|
|
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
|
|
// Send the request to the server.
|
|
|
|
connection.sendPacket(iq);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
MUCOwner answer = (MUCOwner) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
|
|
|
// Get the list of affiliates from the server's answer
|
2006-07-18 07:14:33 +02:00
|
|
|
List<Affiliate> affiliates = new ArrayList<Affiliate>();
|
2004-12-15 20:03:37 +01:00
|
|
|
for (Iterator it = answer.getItems(); it.hasNext();) {
|
|
|
|
affiliates.add(new Affiliate((MUCOwner.Item) it.next()));
|
|
|
|
}
|
|
|
|
return affiliates;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a collection of <code>Affiliate</code> that have the specified room affiliation
|
|
|
|
* sending a request in the admin namespace.
|
|
|
|
*
|
|
|
|
* @param affiliation the affiliation of the users in the room.
|
|
|
|
* @return a collection of <code>Affiliate</code> that have the specified room affiliation.
|
|
|
|
* @throws XMPPException if an error occured while performing the request to the server or you
|
|
|
|
* don't have enough privileges to get this information.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
private Collection<Affiliate> getAffiliatesByAdmin(String affiliation) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
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.
|
|
|
|
MUCAdmin.Item item = new MUCAdmin.Item(affiliation, null);
|
|
|
|
iq.addItem(item);
|
|
|
|
|
|
|
|
// Wait for a response packet back from the server.
|
|
|
|
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
|
|
// Send the request to the server.
|
|
|
|
connection.sendPacket(iq);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
MUCAdmin answer = (MUCAdmin) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
|
|
|
// Get the list of affiliates from the server's answer
|
2006-07-18 07:14:33 +02:00
|
|
|
List<Affiliate> affiliates = new ArrayList<Affiliate>();
|
2004-12-15 20:03:37 +01:00
|
|
|
for (Iterator it = answer.getItems(); it.hasNext();) {
|
|
|
|
affiliates.add(new Affiliate((MUCAdmin.Item) it.next()));
|
|
|
|
}
|
|
|
|
return affiliates;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a collection of <code>Occupant</code> with the room moderators.
|
|
|
|
*
|
|
|
|
* @return a collection of <code>Occupant</code> with the room moderators.
|
|
|
|
* @throws XMPPException if an error occured while performing the request to the server or you
|
|
|
|
* don't have enough privileges to get this information.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public Collection<Occupant> getModerators() throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
return getOccupants("moderator");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a collection of <code>Occupant</code> with the room participants.
|
|
|
|
*
|
|
|
|
* @return a collection of <code>Occupant</code> with the room participants.
|
|
|
|
* @throws XMPPException if an error occured while performing the request to the server or you
|
|
|
|
* don't have enough privileges to get this information.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public Collection<Occupant> getParticipants() throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
return getOccupants("participant");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a collection of <code>Occupant</code> that have the specified room role.
|
|
|
|
*
|
|
|
|
* @param role the role of the occupant in the room.
|
|
|
|
* @return a collection of <code>Occupant</code> that have the specified room role.
|
|
|
|
* @throws XMPPException if an error occured while performing the request to the server or you
|
|
|
|
* don't have enough privileges to get this information.
|
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
private Collection<Occupant> getOccupants(String role) throws XMPPException {
|
2004-12-15 20:03:37 +01:00
|
|
|
MUCAdmin iq = new MUCAdmin();
|
|
|
|
iq.setTo(room);
|
|
|
|
iq.setType(IQ.Type.GET);
|
|
|
|
// Set the specified role. This may request the list of moderators/participants.
|
|
|
|
MUCAdmin.Item item = new MUCAdmin.Item(null, role);
|
|
|
|
iq.addItem(item);
|
|
|
|
|
|
|
|
// Wait for a response packet back from the server.
|
|
|
|
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
|
|
// Send the request to the server.
|
|
|
|
connection.sendPacket(iq);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
MUCAdmin answer = (MUCAdmin) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
|
|
|
// Get the list of participants from the server's answer
|
2006-07-18 07:14:33 +02:00
|
|
|
List<Occupant> participants = new ArrayList<Occupant>();
|
2004-12-15 20:03:37 +01:00
|
|
|
for (Iterator it = answer.getItems(); it.hasNext();) {
|
|
|
|
participants.add(new Occupant((MUCAdmin.Item) it.next()));
|
|
|
|
}
|
|
|
|
return participants;
|
|
|
|
}
|
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
/**
|
|
|
|
* Sends a message to the chat room.
|
|
|
|
*
|
|
|
|
* @param text the text of the message to send.
|
|
|
|
* @throws XMPPException if sending the message fails.
|
|
|
|
*/
|
|
|
|
public void sendMessage(String text) throws XMPPException {
|
2006-11-28 20:26:54 +01:00
|
|
|
Message message = new Message(room, Message.Type.groupchat);
|
2004-07-06 05:05:37 +02:00
|
|
|
message.setBody(text);
|
|
|
|
connection.sendPacket(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Returns a new Chat for sending private messages to a given room occupant.
|
|
|
|
* The Chat's occupant address is the room's JID (i.e. roomName@service/nick). The server
|
2006-07-18 07:14:33 +02:00
|
|
|
* service will change the 'from' address to the sender's room JID and delivering the message
|
2004-07-06 05:05:37 +02:00
|
|
|
* to the intended recipient's full JID.
|
|
|
|
*
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param occupant occupant unique room JID (e.g. 'darkcave@macbeth.shakespeare.lit/Paul').
|
2006-11-30 20:15:45 +01:00
|
|
|
* @param listener the listener is a message listener that will handle messages for the newly
|
|
|
|
* created chat.
|
2004-12-15 20:03:37 +01:00
|
|
|
* @return new Chat for sending private messages to a given room occupant.
|
2004-07-06 05:05:37 +02:00
|
|
|
*/
|
2006-11-30 20:15:45 +01:00
|
|
|
public Chat createPrivateChat(String occupant, MessageListener listener) {
|
|
|
|
return connection.getChatManager().createChat(occupant, listener);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new Message to send to the chat room.
|
|
|
|
*
|
|
|
|
* @return a new Message addressed to the chat room.
|
|
|
|
*/
|
|
|
|
public Message createMessage() {
|
2006-11-28 20:26:54 +01:00
|
|
|
return new Message(room, Message.Type.groupchat);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a Message to the chat room.
|
|
|
|
*
|
|
|
|
* @param message the message.
|
|
|
|
* @throws XMPPException if sending the message fails.
|
|
|
|
*/
|
|
|
|
public void sendMessage(Message message) throws XMPPException {
|
|
|
|
connection.sendPacket(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Polls for and returns the next message, or <tt>null</tt> if there isn't
|
|
|
|
* a message immediately available. This method provides significantly different
|
|
|
|
* functionalty than the {@link #nextMessage()} method since it's non-blocking.
|
|
|
|
* In other words, the method call will always return immediately, whereas the
|
|
|
|
* nextMessage method will return only when a message is available (or after
|
|
|
|
* a specific timeout).
|
|
|
|
*
|
|
|
|
* @return the next message if one is immediately available and
|
|
|
|
* <tt>null</tt> otherwise.
|
|
|
|
*/
|
|
|
|
public Message pollMessage() {
|
|
|
|
return (Message) messageCollector.pollResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the next available message in the chat. The method call will block
|
|
|
|
* (not return) until a message is available.
|
|
|
|
*
|
|
|
|
* @return the next message.
|
|
|
|
*/
|
|
|
|
public Message nextMessage() {
|
|
|
|
return (Message) messageCollector.nextResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the next available message in the chat. The method call will block
|
|
|
|
* (not return) until a packet is available or the <tt>timeout</tt> has elapased.
|
|
|
|
* If the timeout elapses without a result, <tt>null</tt> will be returned.
|
|
|
|
*
|
|
|
|
* @param timeout the maximum amount of time to wait for the next message.
|
|
|
|
* @return the next message, or <tt>null</tt> if the timeout elapses without a
|
|
|
|
* message becoming available.
|
|
|
|
*/
|
|
|
|
public Message nextMessage(long timeout) {
|
|
|
|
return (Message) messageCollector.nextResult(timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a packet listener that will be notified of any new messages in the
|
|
|
|
* group chat. Only "group chat" messages addressed to this group chat will
|
|
|
|
* be delivered to the listener. If you wish to listen for other packets
|
|
|
|
* that may be associated with this group chat, you should register a
|
|
|
|
* PacketListener directly with the XMPPConnection with the appropriate
|
|
|
|
* PacketListener.
|
|
|
|
*
|
|
|
|
* @param listener a packet listener.
|
|
|
|
*/
|
|
|
|
public void addMessageListener(PacketListener listener) {
|
|
|
|
connection.addPacketListener(listener, messageFilter);
|
2005-03-07 23:01:18 +01:00
|
|
|
connectionListeners.add(listener);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a packet listener that was being notified of any new messages in the
|
|
|
|
* multi user chat. Only "group chat" messages addressed to this multi user chat were
|
|
|
|
* being delivered to the listener.
|
|
|
|
*
|
|
|
|
* @param listener a packet listener.
|
|
|
|
*/
|
|
|
|
public void removeMessageListener(PacketListener listener) {
|
|
|
|
connection.removePacketListener(listener);
|
2005-03-07 23:01:18 +01:00
|
|
|
connectionListeners.remove(listener);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Changes the subject within the room. As a default, only users with a role of "moderator"
|
|
|
|
* are allowed to change the subject in a room. Although some rooms may be configured to
|
2004-07-06 05:05:37 +02:00
|
|
|
* allow a mere participant or even a visitor to change the subject.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
|
|
|
* @param subject the new room's subject to set.
|
|
|
|
* @throws XMPPException if someone without appropriate privileges attempts to change the
|
2004-07-06 05:05:37 +02:00
|
|
|
* room subject will throw an error with code 403 (i.e. Forbidden)
|
|
|
|
*/
|
|
|
|
public void changeSubject(final String subject) throws XMPPException {
|
2006-11-28 20:26:54 +01:00
|
|
|
Message message = new Message(room, Message.Type.groupchat);
|
2004-07-06 05:05:37 +02:00
|
|
|
message.setSubject(subject);
|
|
|
|
// Wait for an error or confirmation message back from the server.
|
|
|
|
PacketFilter responseFilter =
|
|
|
|
new AndFilter(
|
2005-08-10 06:50:50 +02:00
|
|
|
new FromMatchesFilter(room),
|
2004-07-06 05:05:37 +02:00
|
|
|
new PacketTypeFilter(Message.class));
|
|
|
|
responseFilter = new AndFilter(responseFilter, new PacketFilter() {
|
|
|
|
public boolean accept(Packet packet) {
|
|
|
|
Message msg = (Message) packet;
|
|
|
|
return subject.equals(msg.getSubject());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
|
|
// Send change subject packet.
|
|
|
|
connection.sendPacket(message);
|
|
|
|
// Wait up to a certain number of seconds for a reply.
|
|
|
|
Message answer =
|
|
|
|
(Message) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Stop queuing results
|
|
|
|
response.cancel();
|
|
|
|
|
|
|
|
if (answer == null) {
|
|
|
|
throw new XMPPException("No response from server.");
|
|
|
|
}
|
|
|
|
else if (answer.getError() != null) {
|
|
|
|
throw new XMPPException(answer.getError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Notification message that the user has joined the room.
|
2004-07-06 05:05:37 +02:00
|
|
|
*/
|
|
|
|
private synchronized void userHasJoined() {
|
|
|
|
// Update the list of joined rooms through this connection
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> rooms = joinedRooms.get(connection);
|
2004-07-06 05:05:37 +02:00
|
|
|
if (rooms == null) {
|
2006-07-18 07:14:33 +02:00
|
|
|
rooms = new ArrayList<String>();
|
2004-07-06 05:05:37 +02:00
|
|
|
joinedRooms.put(connection, rooms);
|
|
|
|
}
|
|
|
|
rooms.add(room);
|
|
|
|
}
|
2006-07-18 07:14:33 +02:00
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Notification message that the user has left the room.
|
2004-07-06 05:05:37 +02:00
|
|
|
*/
|
|
|
|
private synchronized void userHasLeft() {
|
|
|
|
// Update the list of joined rooms through this connection
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> rooms = joinedRooms.get(connection);
|
2004-07-06 05:05:37 +02:00
|
|
|
if (rooms == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rooms.remove(room);
|
|
|
|
}
|
2006-07-18 07:14:33 +02:00
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
/**
|
|
|
|
* Returns the MUCUser packet extension included in the packet or <tt>null</tt> if none.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param packet the packet that may include the MUCUser extension.
|
|
|
|
* @return the MUCUser found in the packet.
|
|
|
|
*/
|
|
|
|
private MUCUser getMUCUserExtension(Packet packet) {
|
|
|
|
if (packet != null) {
|
|
|
|
// Get the MUC User extension
|
|
|
|
return (MUCUser) packet.getExtension("x", "http://jabber.org/protocol/muc#user");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Adds a listener that will be notified of changes in your status in the room
|
|
|
|
* such as the user being kicked, banned, or granted admin permissions.
|
2004-07-06 05:05:37 +02:00
|
|
|
*
|
|
|
|
* @param listener a user status listener.
|
|
|
|
*/
|
|
|
|
public void addUserStatusListener(UserStatusListener listener) {
|
|
|
|
synchronized (userStatusListeners) {
|
|
|
|
if (!userStatusListeners.contains(listener)) {
|
|
|
|
userStatusListeners.add(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Removes a listener that was being notified of changes in your status in the room
|
|
|
|
* such as the user being kicked, banned, or granted admin permissions.
|
2004-07-06 05:05:37 +02:00
|
|
|
*
|
|
|
|
* @param listener a user status listener.
|
|
|
|
*/
|
|
|
|
public void removeUserStatusListener(UserStatusListener listener) {
|
|
|
|
synchronized (userStatusListeners) {
|
|
|
|
userStatusListeners.remove(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fireUserStatusListeners(String methodName, Object[] params) {
|
2006-07-18 07:14:33 +02:00
|
|
|
UserStatusListener[] listeners;
|
2004-07-06 05:05:37 +02:00
|
|
|
synchronized (userStatusListeners) {
|
|
|
|
listeners = new UserStatusListener[userStatusListeners.size()];
|
|
|
|
userStatusListeners.toArray(listeners);
|
|
|
|
}
|
|
|
|
// Get the classes of the method parameters
|
|
|
|
Class[] paramClasses = new Class[params.length];
|
|
|
|
for (int i = 0; i < params.length; i++) {
|
|
|
|
paramClasses[i] = params[i].getClass();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
// Get the method to execute based on the requested methodName and parameters classes
|
|
|
|
Method method = UserStatusListener.class.getDeclaredMethod(methodName, paramClasses);
|
2006-07-18 07:14:33 +02:00
|
|
|
for (UserStatusListener listener : listeners) {
|
|
|
|
method.invoke(listener, params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Adds a listener that will be notified of changes in occupants status in the room
|
2006-07-18 07:14:33 +02:00
|
|
|
* such as the user being kicked, banned, or granted admin permissions.
|
2004-07-06 05:05:37 +02:00
|
|
|
*
|
|
|
|
* @param listener a participant status listener.
|
|
|
|
*/
|
|
|
|
public void addParticipantStatusListener(ParticipantStatusListener listener) {
|
|
|
|
synchronized (participantStatusListeners) {
|
|
|
|
if (!participantStatusListeners.contains(listener)) {
|
|
|
|
participantStatusListeners.add(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-15 20:03:37 +01:00
|
|
|
* Removes a listener that was being notified of changes in occupants status in the room
|
2006-07-18 07:14:33 +02:00
|
|
|
* such as the user being kicked, banned, or granted admin permissions.
|
2004-07-06 05:05:37 +02:00
|
|
|
*
|
|
|
|
* @param listener a participant status listener.
|
|
|
|
*/
|
|
|
|
public void removeParticipantStatusListener(ParticipantStatusListener listener) {
|
|
|
|
synchronized (participantStatusListeners) {
|
|
|
|
participantStatusListeners.remove(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-18 07:14:33 +02:00
|
|
|
private void fireParticipantStatusListeners(String methodName, List<String> params) {
|
|
|
|
ParticipantStatusListener[] listeners;
|
2004-07-06 05:05:37 +02:00
|
|
|
synchronized (participantStatusListeners) {
|
|
|
|
listeners = new ParticipantStatusListener[participantStatusListeners.size()];
|
|
|
|
participantStatusListeners.toArray(listeners);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
// Get the method to execute based on the requested methodName and parameter
|
2005-11-08 18:15:18 +01:00
|
|
|
Class[] classes = new Class[params.size()];
|
|
|
|
for (int i=0;i<params.size(); i++) {
|
|
|
|
classes[i] = String.class;
|
|
|
|
}
|
|
|
|
Method method = ParticipantStatusListener.class.getDeclaredMethod(methodName, classes);
|
2006-07-18 07:14:33 +02:00
|
|
|
for (ParticipantStatusListener listener : listeners) {
|
|
|
|
method.invoke(listener, params.toArray());
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2006-07-18 07:14:33 +02:00
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
private void init() {
|
2006-07-18 07:14:33 +02:00
|
|
|
// Create filters
|
2004-07-06 05:05:37 +02:00
|
|
|
messageFilter =
|
|
|
|
new AndFilter(
|
2005-08-10 06:50:50 +02:00
|
|
|
new FromMatchesFilter(room),
|
2006-11-28 20:26:54 +01:00
|
|
|
new MessageTypeFilter(Message.Type.groupchat));
|
2004-07-06 05:05:37 +02:00
|
|
|
messageFilter = new AndFilter(messageFilter, new PacketFilter() {
|
|
|
|
public boolean accept(Packet packet) {
|
|
|
|
Message msg = (Message) packet;
|
|
|
|
return msg.getBody() != null;
|
|
|
|
}
|
|
|
|
});
|
2006-07-18 07:14:33 +02:00
|
|
|
presenceFilter =
|
|
|
|
new AndFilter(new FromMatchesFilter(room), new PacketTypeFilter(Presence.class));
|
|
|
|
|
|
|
|
// Create a collector for incoming messages.
|
|
|
|
messageCollector = new ConnectionDetachedPacketCollector();
|
2004-07-06 05:05:37 +02:00
|
|
|
|
|
|
|
// Create a listener for subject updates.
|
2006-07-18 07:14:33 +02:00
|
|
|
PacketListener subjectListener = new PacketListener() {
|
2004-07-06 05:05:37 +02:00
|
|
|
public void processPacket(Packet packet) {
|
|
|
|
Message msg = (Message) packet;
|
|
|
|
// Update the room subject
|
|
|
|
subject = msg.getSubject();
|
|
|
|
// Fire event for subject updated listeners
|
|
|
|
fireSubjectUpdatedListeners(
|
|
|
|
msg.getSubject(),
|
|
|
|
msg.getFrom());
|
2006-07-18 07:14:33 +02:00
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create a listener for all presence updates.
|
2006-07-18 07:14:33 +02:00
|
|
|
PacketListener presenceListener = new PacketListener() {
|
2004-07-06 05:05:37 +02:00
|
|
|
public void processPacket(Packet packet) {
|
|
|
|
Presence presence = (Presence) packet;
|
|
|
|
String from = presence.getFrom();
|
|
|
|
String myRoomJID = room + "/" + nickname;
|
|
|
|
boolean isUserStatusModification = presence.getFrom().equals(myRoomJID);
|
2006-07-17 10:39:08 +02:00
|
|
|
if (presence.getType() == Presence.Type.available) {
|
2006-07-18 07:14:33 +02:00
|
|
|
Presence oldPresence = occupantsMap.put(from, presence);
|
2004-07-06 05:05:37 +02:00
|
|
|
if (oldPresence != null) {
|
2004-12-15 20:03:37 +01:00
|
|
|
// Get the previous occupant's affiliation & role
|
2004-07-06 05:05:37 +02:00
|
|
|
MUCUser mucExtension = getMUCUserExtension(oldPresence);
|
2006-07-18 07:14:33 +02:00
|
|
|
String oldAffiliation = mucExtension.getItem().getAffiliation();
|
2004-07-06 05:05:37 +02:00
|
|
|
String oldRole = mucExtension.getItem().getRole();
|
2004-12-15 20:03:37 +01:00
|
|
|
// Get the new occupant's affiliation & role
|
2004-07-06 05:05:37 +02:00
|
|
|
mucExtension = getMUCUserExtension(presence);
|
2006-07-18 07:14:33 +02:00
|
|
|
String newAffiliation = mucExtension.getItem().getAffiliation();
|
2004-07-06 05:05:37 +02:00
|
|
|
String newRole = mucExtension.getItem().getRole();
|
|
|
|
// Fire role modification events
|
|
|
|
checkRoleModifications(oldRole, newRole, isUserStatusModification, from);
|
|
|
|
// Fire affiliation modification events
|
|
|
|
checkAffiliationModifications(
|
|
|
|
oldAffiliation,
|
|
|
|
newAffiliation,
|
|
|
|
isUserStatusModification,
|
|
|
|
from);
|
|
|
|
}
|
2004-12-26 22:55:41 +01:00
|
|
|
else {
|
|
|
|
// A new occupant has joined the room
|
|
|
|
if (!isUserStatusModification) {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("joined", params);
|
2004-12-26 22:55:41 +01:00
|
|
|
}
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
2006-07-17 10:39:08 +02:00
|
|
|
else if (presence.getType() == Presence.Type.unavailable) {
|
2006-07-18 07:14:33 +02:00
|
|
|
occupantsMap.remove(from);
|
2004-07-06 05:05:37 +02:00
|
|
|
MUCUser mucUser = getMUCUserExtension(presence);
|
|
|
|
if (mucUser != null && mucUser.getStatus() != null) {
|
|
|
|
// Fire events according to the received presence code
|
|
|
|
checkPresenceCode(
|
|
|
|
mucUser.getStatus().getCode(),
|
|
|
|
presence.getFrom().equals(myRoomJID),
|
|
|
|
mucUser,
|
|
|
|
from);
|
2004-12-26 22:55:41 +01:00
|
|
|
} else {
|
|
|
|
// An occupant has left the room
|
|
|
|
if (!isUserStatusModification) {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("left", params);
|
2004-12-26 22:55:41 +01:00
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-07-18 07:14:33 +02:00
|
|
|
// Listens for all messages that include a MUCUser extension and fire the invitation
|
2004-07-06 05:05:37 +02:00
|
|
|
// rejection listeners if the message includes an invitation rejection.
|
2006-07-18 07:14:33 +02:00
|
|
|
PacketListener declinesListener = new PacketListener() {
|
2004-07-06 05:05:37 +02:00
|
|
|
public void processPacket(Packet packet) {
|
|
|
|
// Get the MUC User extension
|
|
|
|
MUCUser mucUser = getMUCUserExtension(packet);
|
|
|
|
// Check if the MUCUser informs that the invitee has declined the invitation
|
2005-11-01 16:57:00 +01:00
|
|
|
if (mucUser.getDecline() != null &&
|
2006-11-28 20:26:54 +01:00
|
|
|
((Message) packet).getType() != Message.Type.error) {
|
2004-07-06 05:05:37 +02:00
|
|
|
// Fire event for invitation rejection listeners
|
|
|
|
fireInvitationRejectionListeners(
|
|
|
|
mucUser.getDecline().getFrom(),
|
|
|
|
mucUser.getDecline().getReason());
|
|
|
|
}
|
2006-07-18 07:14:33 +02:00
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
};
|
2006-07-18 07:14:33 +02:00
|
|
|
|
|
|
|
PacketMultiplexListener packetMultiplexor = new PacketMultiplexListener(
|
|
|
|
messageCollector, presenceListener, subjectListener,
|
|
|
|
declinesListener);
|
|
|
|
|
|
|
|
roomListenerMultiplexor = RoomListenerMultiplexor.getRoomMultiplexor(connection);
|
|
|
|
|
|
|
|
roomListenerMultiplexor.addRoom(room, packetMultiplexor);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Fires notification events if the role of a room occupant has changed. If the occupant that
|
|
|
|
* changed his role is your occupant then the <code>UserStatusListeners</code> added to this
|
|
|
|
* <code>MultiUserChat</code> will be fired. On the other hand, if the occupant that changed
|
|
|
|
* his role is not yours then the <code>ParticipantStatusListeners</code> added to this
|
|
|
|
* <code>MultiUserChat</code> will be fired. The following table shows the events that will
|
2004-07-06 05:05:37 +02:00
|
|
|
* be fired depending on the previous and new role of the occupant.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* <pre>
|
|
|
|
* <table border="1">
|
|
|
|
* <tr><td><b>Old</b></td><td><b>New</b></td><td><b>Events</b></td></tr>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* <tr><td>None</td><td>Visitor</td><td>--</td></tr>
|
|
|
|
* <tr><td>Visitor</td><td>Participant</td><td>voiceGranted</td></tr>
|
|
|
|
* <tr><td>Participant</td><td>Moderator</td><td>moderatorGranted</td></tr>
|
|
|
|
*
|
|
|
|
* <tr><td>None</td><td>Participant</td><td>voiceGranted</td></tr>
|
|
|
|
* <tr><td>None</td><td>Moderator</td><td>voiceGranted + moderatorGranted</td></tr>
|
|
|
|
* <tr><td>Visitor</td><td>Moderator</td><td>voiceGranted + moderatorGranted</td></tr>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* <tr><td>Moderator</td><td>Participant</td><td>moderatorRevoked</td></tr>
|
|
|
|
* <tr><td>Participant</td><td>Visitor</td><td>voiceRevoked</td></tr>
|
|
|
|
* <tr><td>Visitor</td><td>None</td><td>kicked</td></tr>
|
|
|
|
*
|
|
|
|
* <tr><td>Moderator</td><td>Visitor</td><td>voiceRevoked + moderatorRevoked</td></tr>
|
|
|
|
* <tr><td>Moderator</td><td>None</td><td>kicked</td></tr>
|
|
|
|
* <tr><td>Participant</td><td>None</td><td>kicked</td></tr>
|
|
|
|
* </table>
|
|
|
|
* </pre>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param oldRole the previous role of the user in the room before receiving the new presence
|
|
|
|
* @param newRole the new role of the user in the room after receiving the new presence
|
|
|
|
* @param isUserModification whether the received presence is about your user in the room or not
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param from the occupant whose role in the room has changed
|
2004-07-06 05:05:37 +02:00
|
|
|
* (e.g. room@conference.jabber.org/nick).
|
|
|
|
*/
|
|
|
|
private void checkRoleModifications(
|
|
|
|
String oldRole,
|
|
|
|
String newRole,
|
|
|
|
boolean isUserModification,
|
|
|
|
String from) {
|
|
|
|
// Voice was granted to a visitor
|
|
|
|
if (("visitor".equals(oldRole) || "none".equals(oldRole))
|
|
|
|
&& "participant".equals(newRole)) {
|
|
|
|
if (isUserModification) {
|
|
|
|
fireUserStatusListeners("voiceGranted", new Object[] {});
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("voiceGranted", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// The participant's voice was revoked from the room
|
|
|
|
else if (
|
|
|
|
"participant".equals(oldRole)
|
|
|
|
&& ("visitor".equals(newRole) || "none".equals(newRole))) {
|
|
|
|
if (isUserModification) {
|
|
|
|
fireUserStatusListeners("voiceRevoked", new Object[] {});
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("voiceRevoked", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Moderator privileges were granted to a participant
|
|
|
|
if (!"moderator".equals(oldRole) && "moderator".equals(newRole)) {
|
|
|
|
if ("visitor".equals(oldRole) || "none".equals(oldRole)) {
|
|
|
|
if (isUserModification) {
|
|
|
|
fireUserStatusListeners("voiceGranted", new Object[] {});
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("voiceGranted", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isUserModification) {
|
|
|
|
fireUserStatusListeners("moderatorGranted", new Object[] {});
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("moderatorGranted", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Moderator privileges were revoked from a participant
|
|
|
|
else if ("moderator".equals(oldRole) && !"moderator".equals(newRole)) {
|
|
|
|
if ("visitor".equals(newRole) || "none".equals(newRole)) {
|
|
|
|
if (isUserModification) {
|
|
|
|
fireUserStatusListeners("voiceRevoked", new Object[] {});
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("voiceRevoked", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isUserModification) {
|
|
|
|
fireUserStatusListeners("moderatorRevoked", new Object[] {});
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("moderatorRevoked", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-18 07:14:33 +02:00
|
|
|
* Fires notification events if the affiliation of a room occupant has changed. If the
|
|
|
|
* occupant that changed his affiliation is your occupant then the
|
|
|
|
* <code>UserStatusListeners</code> added to this <code>MultiUserChat</code> will be fired.
|
|
|
|
* On the other hand, if the occupant that changed his affiliation is not yours then the
|
|
|
|
* <code>ParticipantStatusListeners</code> added to this <code>MultiUserChat</code> will be
|
|
|
|
* fired. The following table shows the events that will be fired depending on the previous
|
2004-07-06 05:05:37 +02:00
|
|
|
* and new affiliation of the occupant.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* <pre>
|
|
|
|
* <table border="1">
|
|
|
|
* <tr><td><b>Old</b></td><td><b>New</b></td><td><b>Events</b></td></tr>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* <tr><td>None</td><td>Member</td><td>membershipGranted</td></tr>
|
|
|
|
* <tr><td>Member</td><td>Admin</td><td>membershipRevoked + adminGranted</td></tr>
|
|
|
|
* <tr><td>Admin</td><td>Owner</td><td>adminRevoked + ownershipGranted</td></tr>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* <tr><td>None</td><td>Admin</td><td>adminGranted</td></tr>
|
|
|
|
* <tr><td>None</td><td>Owner</td><td>ownershipGranted</td></tr>
|
|
|
|
* <tr><td>Member</td><td>Owner</td><td>membershipRevoked + ownershipGranted</td></tr>
|
|
|
|
*
|
|
|
|
* <tr><td>Owner</td><td>Admin</td><td>ownershipRevoked + adminGranted</td></tr>
|
|
|
|
* <tr><td>Admin</td><td>Member</td><td>adminRevoked + membershipGranted</td></tr>
|
|
|
|
* <tr><td>Member</td><td>None</td><td>membershipRevoked</td></tr>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* <tr><td>Owner</td><td>Member</td><td>ownershipRevoked + membershipGranted</td></tr>
|
|
|
|
* <tr><td>Owner</td><td>None</td><td>ownershipRevoked</td></tr>
|
|
|
|
* <tr><td>Admin</td><td>None</td><td>adminRevoked</td></tr>
|
|
|
|
* <tr><td><i>Anyone</i></td><td>Outcast</td><td>banned</td></tr>
|
|
|
|
* </table>
|
|
|
|
* </pre>
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
|
|
|
* @param oldAffiliation the previous affiliation of the user in the room before receiving the
|
2004-07-06 05:05:37 +02:00
|
|
|
* new presence
|
2006-07-18 07:14:33 +02:00
|
|
|
* @param newAffiliation the new affiliation of the user in the room after receiving the new
|
2004-07-06 05:05:37 +02:00
|
|
|
* presence
|
|
|
|
* @param isUserModification whether the received presence is about your user in the room or not
|
2004-12-15 20:03:37 +01:00
|
|
|
* @param from the occupant whose role in the room has changed
|
2004-07-06 05:05:37 +02:00
|
|
|
* (e.g. room@conference.jabber.org/nick).
|
|
|
|
*/
|
|
|
|
private void checkAffiliationModifications(
|
|
|
|
String oldAffiliation,
|
|
|
|
String newAffiliation,
|
|
|
|
boolean isUserModification,
|
|
|
|
String 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.
|
2006-07-18 07:14:33 +02:00
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
// The user's ownership to the room was revoked
|
|
|
|
if ("owner".equals(oldAffiliation) && !"owner".equals(newAffiliation)) {
|
|
|
|
if (isUserModification) {
|
|
|
|
fireUserStatusListeners("ownershipRevoked", new Object[] {});
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("ownershipRevoked", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// The user's administrative privileges to the room were revoked
|
|
|
|
else if ("admin".equals(oldAffiliation) && !"admin".equals(newAffiliation)) {
|
|
|
|
if (isUserModification) {
|
|
|
|
fireUserStatusListeners("adminRevoked", new Object[] {});
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("adminRevoked", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// The user's membership to the room was revoked
|
|
|
|
else if ("member".equals(oldAffiliation) && !"member".equals(newAffiliation)) {
|
|
|
|
if (isUserModification) {
|
|
|
|
fireUserStatusListeners("membershipRevoked", new Object[] {});
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("membershipRevoked", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The user was granted ownership to the room
|
|
|
|
if (!"owner".equals(oldAffiliation) && "owner".equals(newAffiliation)) {
|
|
|
|
if (isUserModification) {
|
|
|
|
fireUserStatusListeners("ownershipGranted", new Object[] {});
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("ownershipGranted", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// The user was granted administrative privileges to the room
|
|
|
|
else if (!"admin".equals(oldAffiliation) && "admin".equals(newAffiliation)) {
|
|
|
|
if (isUserModification) {
|
|
|
|
fireUserStatusListeners("adminGranted", new Object[] {});
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("adminGranted", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// The user was granted membership to the room
|
|
|
|
else if (!"member".equals(oldAffiliation) && "member".equals(newAffiliation)) {
|
|
|
|
if (isUserModification) {
|
|
|
|
fireUserStatusListeners("membershipGranted", new Object[] {});
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
fireParticipantStatusListeners("membershipGranted", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires events according to the received presence code.
|
2006-07-18 07:14:33 +02:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param code
|
|
|
|
* @param isUserModification
|
|
|
|
* @param mucUser
|
|
|
|
* @param from
|
|
|
|
*/
|
|
|
|
private void checkPresenceCode(
|
|
|
|
String code,
|
|
|
|
boolean isUserModification,
|
|
|
|
MUCUser mucUser,
|
|
|
|
String from) {
|
2004-12-15 20:03:37 +01:00
|
|
|
// Check if an occupant was kicked from the room
|
2004-07-06 05:05:37 +02:00
|
|
|
if ("307".equals(code)) {
|
2004-12-15 20:03:37 +01:00
|
|
|
// Check if this occupant was kicked
|
2004-07-06 05:05:37 +02:00
|
|
|
if (isUserModification) {
|
|
|
|
joined = false;
|
|
|
|
|
|
|
|
fireUserStatusListeners(
|
|
|
|
"kicked",
|
|
|
|
new Object[] { mucUser.getItem().getActor(), mucUser.getItem().getReason()});
|
|
|
|
|
2004-12-15 20:03:37 +01:00
|
|
|
// Reset occupant information.
|
2006-07-18 07:14:33 +02:00
|
|
|
occupantsMap.clear();
|
2004-07-06 05:05:37 +02:00
|
|
|
nickname = null;
|
|
|
|
userHasLeft();
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
params.add(mucUser.getItem().getActor());
|
|
|
|
params.add(mucUser.getItem().getReason());
|
|
|
|
fireParticipantStatusListeners("kicked", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
2006-07-18 07:14:33 +02:00
|
|
|
// A user was banned from the room
|
2004-07-06 05:05:37 +02:00
|
|
|
else if ("301".equals(code)) {
|
2004-12-15 20:03:37 +01:00
|
|
|
// Check if this occupant was banned
|
2004-07-06 05:05:37 +02:00
|
|
|
if (isUserModification) {
|
|
|
|
joined = false;
|
|
|
|
|
|
|
|
fireUserStatusListeners(
|
|
|
|
"banned",
|
|
|
|
new Object[] { mucUser.getItem().getActor(), mucUser.getItem().getReason()});
|
|
|
|
|
2004-12-15 20:03:37 +01:00
|
|
|
// Reset occupant information.
|
2006-07-18 07:14:33 +02:00
|
|
|
occupantsMap.clear();
|
2004-07-06 05:05:37 +02:00
|
|
|
nickname = null;
|
|
|
|
userHasLeft();
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
params.add(mucUser.getItem().getActor());
|
|
|
|
params.add(mucUser.getItem().getReason());
|
|
|
|
fireParticipantStatusListeners("banned", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
2006-07-18 07:14:33 +02:00
|
|
|
// A user's membership was revoked from the room
|
2004-07-06 05:05:37 +02:00
|
|
|
else if ("321".equals(code)) {
|
2004-12-15 20:03:37 +01:00
|
|
|
// Check if this occupant's membership was revoked
|
2004-07-06 05:05:37 +02:00
|
|
|
if (isUserModification) {
|
|
|
|
joined = false;
|
|
|
|
|
|
|
|
fireUserStatusListeners("membershipRevoked", new Object[] {});
|
|
|
|
|
2004-12-15 20:03:37 +01:00
|
|
|
// Reset occupant information.
|
2006-07-18 07:14:33 +02:00
|
|
|
occupantsMap.clear();
|
2004-07-06 05:05:37 +02:00
|
|
|
nickname = null;
|
|
|
|
userHasLeft();
|
|
|
|
}
|
|
|
|
}
|
2004-12-15 20:03:37 +01:00
|
|
|
// A occupant has changed his nickname in the room
|
2004-07-06 05:05:37 +02:00
|
|
|
else if ("303".equals(code)) {
|
2006-07-18 07:14:33 +02:00
|
|
|
List<String> params = new ArrayList<String>();
|
2005-11-08 18:15:18 +01:00
|
|
|
params.add(from);
|
|
|
|
params.add(mucUser.getItem().getNick());
|
|
|
|
fireParticipantStatusListeners("nicknameChanged", params);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-16 23:00:07 +02:00
|
|
|
public void finalize() throws Throwable {
|
|
|
|
super.finalize();
|
|
|
|
try {
|
|
|
|
if (connection != null) {
|
2006-07-18 07:14:33 +02:00
|
|
|
roomListenerMultiplexor.removeRoom(room);
|
2005-03-07 23:01:18 +01:00
|
|
|
// Remove all the PacketListeners added to the connection by this chat
|
2006-07-18 07:14:33 +02:00
|
|
|
for (PacketListener connectionListener : connectionListeners) {
|
|
|
|
connection.removePacketListener(connectionListener);
|
2005-03-07 23:01:18 +01:00
|
|
|
}
|
2004-07-16 23:00:07 +02:00
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
2006-07-18 07:14:33 +02:00
|
|
|
catch (Exception e) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An InvitationsMonitor monitors a given connection to detect room invitations. Every
|
2006-11-30 20:15:45 +01:00
|
|
|
* time the InvitationsMonitor detects a new invitation it will fire the invitation listeners.
|
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
|
|
|
private static class InvitationsMonitor implements ConnectionListener {
|
|
|
|
// We use a WeakHashMap so that the GC can collect the monitor when the
|
|
|
|
// connection is no longer referenced by any object.
|
2006-07-18 07:14:33 +02:00
|
|
|
private final static Map<XMPPConnection, WeakReference<InvitationsMonitor>> monitors =
|
|
|
|
new WeakHashMap<XMPPConnection, WeakReference<InvitationsMonitor>>();
|
2004-07-06 05:05:37 +02:00
|
|
|
|
2006-07-18 07:14:33 +02:00
|
|
|
private final List<InvitationListener> invitationsListeners =
|
|
|
|
new ArrayList<InvitationListener>();
|
2004-07-06 05:05:37 +02:00
|
|
|
private XMPPConnection connection;
|
|
|
|
private PacketFilter invitationFilter;
|
|
|
|
private PacketListener invitationPacketListener;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a new or existing InvitationsMonitor for a given connection.
|
2006-11-30 20:15:45 +01:00
|
|
|
*
|
2004-12-15 02:40:01 +01:00
|
|
|
* @param conn the connection to monitor for room invitations.
|
2004-07-06 05:05:37 +02:00
|
|
|
* @return a new or existing InvitationsMonitor for a given connection.
|
|
|
|
*/
|
|
|
|
public static InvitationsMonitor getInvitationsMonitor(XMPPConnection conn) {
|
|
|
|
synchronized (monitors) {
|
|
|
|
if (!monitors.containsKey(conn)) {
|
2006-11-30 20:15:45 +01:00
|
|
|
// We need to use a WeakReference because the monitor references the
|
2004-07-06 05:05:37 +02:00
|
|
|
// connection and this could prevent the GC from collecting the monitor
|
|
|
|
// when no other object references the monitor
|
2006-07-18 07:14:33 +02:00
|
|
|
monitors.put(conn, new WeakReference<InvitationsMonitor>(new InvitationsMonitor(conn)));
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
// Return the InvitationsMonitor that monitors the connection
|
2006-07-18 07:14:33 +02:00
|
|
|
return monitors.get(conn).get();
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new InvitationsMonitor that will monitor invitations received
|
|
|
|
* on a given connection.
|
|
|
|
*
|
|
|
|
* @param connection the connection to monitor for possible room invitations
|
|
|
|
*/
|
|
|
|
private InvitationsMonitor(XMPPConnection connection) {
|
|
|
|
this.connection = connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-11-30 20:15:45 +01:00
|
|
|
* Adds a listener to invitation notifications. The listener will be fired anytime
|
2004-07-06 05:05:37 +02:00
|
|
|
* an invitation is received.<p>
|
2006-11-30 20:15:45 +01:00
|
|
|
*
|
|
|
|
* If this is the first monitor's listener then the monitor will be initialized in
|
2004-07-06 05:05:37 +02:00
|
|
|
* order to start listening to room invitations.
|
2006-11-30 20:15:45 +01:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param listener an invitation listener.
|
|
|
|
*/
|
|
|
|
public void addInvitationListener(InvitationListener listener) {
|
|
|
|
synchronized (invitationsListeners) {
|
2006-11-30 20:15:45 +01:00
|
|
|
// If this is the first monitor's listener then initialize the listeners
|
2004-07-06 05:05:37 +02:00
|
|
|
// on the connection to detect room invitations
|
|
|
|
if (invitationsListeners.size() == 0) {
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
if (!invitationsListeners.contains(listener)) {
|
|
|
|
invitationsListeners.add(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-11-30 20:15:45 +01:00
|
|
|
* Removes a listener to invitation notifications. The listener will be fired anytime
|
2004-07-06 05:05:37 +02:00
|
|
|
* an invitation is received.<p>
|
2006-11-30 20:15:45 +01:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* If there are no more listeners to notifiy for room invitations then the monitor will
|
|
|
|
* be stopped. As soon as a new listener is added to the monitor, the monitor will resume
|
|
|
|
* monitoring the connection for new room invitations.
|
2006-11-30 20:15:45 +01:00
|
|
|
*
|
2004-07-06 05:05:37 +02:00
|
|
|
* @param listener an invitation listener.
|
|
|
|
*/
|
|
|
|
public void removeInvitationListener(InvitationListener listener) {
|
|
|
|
synchronized (invitationsListeners) {
|
|
|
|
if (invitationsListeners.contains(listener)) {
|
|
|
|
invitationsListeners.remove(listener);
|
|
|
|
}
|
|
|
|
// If there are no more listeners to notifiy for room invitations
|
2006-11-30 20:15:45 +01:00
|
|
|
// then proceed to cancel/release this monitor
|
2004-07-06 05:05:37 +02:00
|
|
|
if (invitationsListeners.size() == 0) {
|
|
|
|
cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires invitation listeners.
|
|
|
|
*/
|
2005-01-11 18:35:41 +01:00
|
|
|
private void fireInvitationListeners(String room, String inviter, String reason, String password,
|
|
|
|
Message message) {
|
2006-07-18 07:14:33 +02:00
|
|
|
InvitationListener[] listeners;
|
2004-07-06 05:05:37 +02:00
|
|
|
synchronized (invitationsListeners) {
|
|
|
|
listeners = new InvitationListener[invitationsListeners.size()];
|
|
|
|
invitationsListeners.toArray(listeners);
|
|
|
|
}
|
2006-07-18 07:14:33 +02:00
|
|
|
for (InvitationListener listener : listeners) {
|
|
|
|
listener.invitationReceived(connection, room, inviter, reason, password, message);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void connectionClosed() {
|
2007-02-19 09:59:33 +01:00
|
|
|
cancel();
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void connectionClosedOnError(Exception e) {
|
2007-02-19 09:59:33 +01:00
|
|
|
// ignore
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
|
|
|
|
2006-09-14 21:16:40 +02:00
|
|
|
public void reconnectingIn(int seconds) {
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
|
2006-11-15 23:29:25 +01:00
|
|
|
public void reconnectionSuccessful() {
|
2006-09-14 21:16:40 +02:00
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reconnectionFailed(Exception e) {
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
|
2004-07-06 05:05:37 +02:00
|
|
|
/**
|
2006-11-30 20:15:45 +01:00
|
|
|
* Initializes the listeners to detect received room invitations and to detect when the
|
|
|
|
* connection gets closed. As soon as a room invitation is received the invitations
|
2004-07-06 05:05:37 +02:00
|
|
|
* listeners will be fired. When the connection gets closed the monitor will remove
|
2006-11-30 20:15:45 +01:00
|
|
|
* his listeners on the connection.
|
2004-07-06 05:05:37 +02:00
|
|
|
*/
|
|
|
|
private void init() {
|
2006-11-30 20:15:45 +01:00
|
|
|
// Listens for all messages that include a MUCUser extension and fire the invitation
|
2004-07-06 05:05:37 +02:00
|
|
|
// listeners if the message includes an invitation.
|
|
|
|
invitationFilter =
|
|
|
|
new PacketExtensionFilter("x", "http://jabber.org/protocol/muc#user");
|
|
|
|
invitationPacketListener = new PacketListener() {
|
|
|
|
public void processPacket(Packet packet) {
|
|
|
|
// Get the MUCUser extension
|
2006-02-27 22:59:50 +01:00
|
|
|
MUCUser mucUser =
|
2004-07-06 05:05:37 +02:00
|
|
|
(MUCUser) packet.getExtension("x", "http://jabber.org/protocol/muc#user");
|
|
|
|
// Check if the MUCUser extension includes an invitation
|
2005-11-01 19:31:52 +01:00
|
|
|
if (mucUser.getInvite() != null &&
|
2006-11-28 20:26:54 +01:00
|
|
|
((Message) packet).getType() != Message.Type.error) {
|
2004-07-06 05:05:37 +02:00
|
|
|
// Fire event for invitation listeners
|
2005-01-11 18:35:41 +01:00
|
|
|
fireInvitationListeners(packet.getFrom(), mucUser.getInvite().getFrom(),
|
|
|
|
mucUser.getInvite().getReason(), mucUser.getPassword(), (Message) packet);
|
2004-07-06 05:05:37 +02:00
|
|
|
}
|
2006-07-18 07:14:33 +02:00
|
|
|
}
|
2004-07-06 05:05:37 +02:00
|
|
|
};
|
|
|
|
connection.addPacketListener(invitationPacketListener, invitationFilter);
|
|
|
|
// Add a listener to detect when the connection gets closed in order to
|
|
|
|
// cancel/release this monitor
|
|
|
|
connection.addConnectionListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels all the listeners that this InvitationsMonitor has added to the connection.
|
|
|
|
*/
|
|
|
|
private void cancel() {
|
|
|
|
connection.removePacketListener(invitationPacketListener);
|
|
|
|
connection.removeConnectionListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|