mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-13 22:41:08 +01:00
Migrate from Ant to Gradle (SMACK-265)
This commit is contained in:
parent
235eca3a3d
commit
201152ef42
767 changed files with 1088 additions and 4296 deletions
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jivesoftware.smackx.packet.MUCAdmin;
|
||||
import org.jivesoftware.smackx.packet.MUCOwner;
|
||||
|
||||
/**
|
||||
* Represents an affiliation of a user to a given room. The affiliate's information will always have
|
||||
* the bare jid of the real user and its affiliation. If the affiliate is an occupant of the room
|
||||
* then we will also have information about the role and nickname of the user in the room.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class Affiliate {
|
||||
// Fields that must have a value
|
||||
private String jid;
|
||||
private String affiliation;
|
||||
|
||||
// Fields that may have a value
|
||||
private String role;
|
||||
private String nick;
|
||||
|
||||
Affiliate(MUCOwner.Item item) {
|
||||
super();
|
||||
this.jid = item.getJid();
|
||||
this.affiliation = item.getAffiliation();
|
||||
this.role = item.getRole();
|
||||
this.nick = item.getNick();
|
||||
}
|
||||
|
||||
Affiliate(MUCAdmin.Item item) {
|
||||
super();
|
||||
this.jid = item.getJid();
|
||||
this.affiliation = item.getAffiliation();
|
||||
this.role = item.getRole();
|
||||
this.nick = item.getNick();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bare JID of the affiliated user. This information will always be available.
|
||||
*
|
||||
* @return the bare JID of the affiliated user.
|
||||
*/
|
||||
public String getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the affiliation of the afffiliated user. Possible affiliations are: "owner", "admin",
|
||||
* "member", "outcast". This information will always be available.
|
||||
*
|
||||
* @return the affiliation of the afffiliated user.
|
||||
*/
|
||||
public String getAffiliation() {
|
||||
return affiliation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current role of the affiliated user if the user is currently in the room.
|
||||
* If the user is not present in the room then the answer will be null.
|
||||
*
|
||||
* @return the current role of the affiliated user in the room or null if the user is not in
|
||||
* the room.
|
||||
*/
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current nickname of the affiliated user if the user is currently in the room.
|
||||
* If the user is not present in the room then the answer will be null.
|
||||
*
|
||||
* @return the current nickname of the affiliated user in the room or null if the user is not in
|
||||
* the room.
|
||||
*/
|
||||
public String getNick() {
|
||||
return nick;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2006 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
|
||||
/**
|
||||
* A variant of the {@link org.jivesoftware.smack.PacketCollector} class
|
||||
* that does not force attachment to a <code>Connection</code>
|
||||
* on creation and no filter is required. Used to collect message
|
||||
* packets targeted to a group chat room.
|
||||
*
|
||||
* @author Larry Kirschner
|
||||
*/
|
||||
class ConnectionDetachedPacketCollector {
|
||||
/**
|
||||
* Max number of packets that any one collector can hold. After the max is
|
||||
* reached, older packets will be automatically dropped from the queue as
|
||||
* new packets are added.
|
||||
*/
|
||||
private int maxPackets = SmackConfiguration.getPacketCollectorSize();
|
||||
|
||||
private ArrayBlockingQueue<Packet> resultQueue;
|
||||
|
||||
/**
|
||||
* Creates a new packet collector. If the packet filter is <tt>null</tt>, then
|
||||
* all packets will match this collector.
|
||||
*/
|
||||
public ConnectionDetachedPacketCollector() {
|
||||
this(SmackConfiguration.getPacketCollectorSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new packet collector. If the packet filter is <tt>null</tt>, then
|
||||
* all packets will match this collector.
|
||||
*/
|
||||
public ConnectionDetachedPacketCollector(int maxSize) {
|
||||
this.resultQueue = new ArrayBlockingQueue<Packet>(maxSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Polls to see if a packet is currently available and returns it, or
|
||||
* immediately returns <tt>null</tt> if no packets are currently in the
|
||||
* result queue.
|
||||
*
|
||||
* @return the next packet result, or <tt>null</tt> if there are no more
|
||||
* results.
|
||||
*/
|
||||
public Packet pollResult() {
|
||||
return resultQueue.poll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next available packet. The method call will block (not return)
|
||||
* until a packet is available.
|
||||
*
|
||||
* @return the next available packet.
|
||||
*/
|
||||
public Packet nextResult() {
|
||||
try {
|
||||
return resultQueue.take();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next available packet. 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 amount of time to wait for the next packet (in milleseconds).
|
||||
* @return the next available packet.
|
||||
*/
|
||||
public Packet nextResult(long timeout) {
|
||||
try {
|
||||
return resultQueue.poll(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a packet to see if it meets the criteria for this packet collector.
|
||||
* If so, the packet is added to the result queue.
|
||||
*
|
||||
* @param packet the packet to process.
|
||||
*/
|
||||
protected void processPacket(Packet packet) {
|
||||
if (packet == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (!resultQueue.offer(packet)) {
|
||||
// Since we know the queue is full, this poll should never actually block.
|
||||
resultQueue.poll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2006 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jivesoftware.smack.PacketInterceptor;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
|
||||
/**
|
||||
* Packet interceptor that will intercept presence packets sent to the MUC service to indicate
|
||||
* that the user wants to be a deaf occupant. A user can only indicate that he wants to be a
|
||||
* deaf occupant while joining the room. It is not possible to become deaf or stop being deaf
|
||||
* after the user joined the room.<p>
|
||||
*
|
||||
* Deaf occupants will not get messages broadcasted to all room occupants. However, they will
|
||||
* be able to get private messages, presences, IQ packets or room history. To use this
|
||||
* functionality you will need to send the message
|
||||
* {@link MultiUserChat#addPresenceInterceptor(org.jivesoftware.smack.PacketInterceptor)} and
|
||||
* pass this interceptor as the parameter.<p>
|
||||
*
|
||||
* Note that this is a custom extension to the MUC service so it may not work with other servers
|
||||
* than Wildfire.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class DeafOccupantInterceptor implements PacketInterceptor {
|
||||
|
||||
public void interceptPacket(Packet packet) {
|
||||
Presence presence = (Presence) packet;
|
||||
// Check if user is joining a room
|
||||
if (Presence.Type.available == presence.getType() &&
|
||||
presence.getExtension("x", "http://jabber.org/protocol/muc") != null) {
|
||||
// Add extension that indicates that user wants to be a deaf occupant
|
||||
packet.addExtension(new DeafExtension());
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeafExtension implements PacketExtension {
|
||||
|
||||
public String getElementName() {
|
||||
return "x";
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return "http://jivesoftware.org/protocol/muc";
|
||||
}
|
||||
|
||||
public String toXML() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace())
|
||||
.append("\">");
|
||||
buf.append("<deaf-occupant/>");
|
||||
buf.append("</").append(getElementName()).append(">");
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
/**
|
||||
* Default implementation of the ParticipantStatusListener interface.<p>
|
||||
*
|
||||
* This class does not provide any behavior by default. It just avoids having
|
||||
* to implement all the inteface methods if the user is only interested in implementing
|
||||
* some of the methods.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class DefaultParticipantStatusListener implements ParticipantStatusListener {
|
||||
|
||||
public void joined(String participant) {
|
||||
}
|
||||
|
||||
public void left(String participant) {
|
||||
}
|
||||
|
||||
public void kicked(String participant, String actor, String reason) {
|
||||
}
|
||||
|
||||
public void voiceGranted(String participant) {
|
||||
}
|
||||
|
||||
public void voiceRevoked(String participant) {
|
||||
}
|
||||
|
||||
public void banned(String participant, String actor, String reason) {
|
||||
}
|
||||
|
||||
public void membershipGranted(String participant) {
|
||||
}
|
||||
|
||||
public void membershipRevoked(String participant) {
|
||||
}
|
||||
|
||||
public void moderatorGranted(String participant) {
|
||||
}
|
||||
|
||||
public void moderatorRevoked(String participant) {
|
||||
}
|
||||
|
||||
public void ownershipGranted(String participant) {
|
||||
}
|
||||
|
||||
public void ownershipRevoked(String participant) {
|
||||
}
|
||||
|
||||
public void adminGranted(String participant) {
|
||||
}
|
||||
|
||||
public void adminRevoked(String participant) {
|
||||
}
|
||||
|
||||
public void nicknameChanged(String participant, String newNickname) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
/**
|
||||
* Default implementation of the UserStatusListener interface.<p>
|
||||
*
|
||||
* This class does not provide any behavior by default. It just avoids having
|
||||
* to implement all the inteface methods if the user is only interested in implementing
|
||||
* some of the methods.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class DefaultUserStatusListener implements UserStatusListener {
|
||||
|
||||
public void kicked(String actor, String reason) {
|
||||
}
|
||||
|
||||
public void voiceGranted() {
|
||||
}
|
||||
|
||||
public void voiceRevoked() {
|
||||
}
|
||||
|
||||
public void banned(String actor, String reason) {
|
||||
}
|
||||
|
||||
public void membershipGranted() {
|
||||
}
|
||||
|
||||
public void membershipRevoked() {
|
||||
}
|
||||
|
||||
public void moderatorGranted() {
|
||||
}
|
||||
|
||||
public void moderatorRevoked() {
|
||||
}
|
||||
|
||||
public void ownershipGranted() {
|
||||
}
|
||||
|
||||
public void ownershipRevoked() {
|
||||
}
|
||||
|
||||
public void adminGranted() {
|
||||
}
|
||||
|
||||
public void adminRevoked() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.jivesoftware.smackx.packet.MUCInitialPresence;
|
||||
|
||||
/**
|
||||
* The DiscussionHistory class controls the number of characters or messages to receive
|
||||
* when entering a room. The room will decide the amount of history to return if you don't
|
||||
* specify a DiscussionHistory while joining a room.<p>
|
||||
*
|
||||
* You can use some or all of these variable to control the amount of history to receive:
|
||||
* <ul>
|
||||
* <li>maxchars -> total number of characters to receive in the history.
|
||||
* <li>maxstanzas -> total number of messages to receive in the history.
|
||||
* <li>seconds -> only the messages received in the last "X" seconds will be included in the
|
||||
* history.
|
||||
* <li>since -> only the messages received since the datetime specified will be included in
|
||||
* the history.
|
||||
* </ul>
|
||||
*
|
||||
* Note: Setting maxchars to 0 indicates that the user requests to receive no history.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class DiscussionHistory {
|
||||
|
||||
private int maxChars = -1;
|
||||
private int maxStanzas = -1;
|
||||
private int seconds = -1;
|
||||
private Date since;
|
||||
|
||||
/**
|
||||
* Returns the total number of characters to receive in the history.
|
||||
*
|
||||
* @return total number of characters to receive in the history.
|
||||
*/
|
||||
public int getMaxChars() {
|
||||
return maxChars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of messages to receive in the history.
|
||||
*
|
||||
* @return the total number of messages to receive in the history.
|
||||
*/
|
||||
public int getMaxStanzas() {
|
||||
return maxStanzas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of seconds to use to filter the messages received during that time.
|
||||
* In other words, only the messages received in the last "X" seconds will be included in
|
||||
* the history.
|
||||
*
|
||||
* @return the number of seconds to use to filter the messages received during that time.
|
||||
*/
|
||||
public int getSeconds() {
|
||||
return seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the since date to use to filter the messages received during that time.
|
||||
* In other words, only the messages received since the datetime specified will be
|
||||
* included in the history.
|
||||
*
|
||||
* @return the since date to use to filter the messages received during that time.
|
||||
*/
|
||||
public Date getSince() {
|
||||
return since;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the total number of characters to receive in the history.
|
||||
*
|
||||
* @param maxChars the total number of characters to receive in the history.
|
||||
*/
|
||||
public void setMaxChars(int maxChars) {
|
||||
this.maxChars = maxChars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the total number of messages to receive in the history.
|
||||
*
|
||||
* @param maxStanzas the total number of messages to receive in the history.
|
||||
*/
|
||||
public void setMaxStanzas(int maxStanzas) {
|
||||
this.maxStanzas = maxStanzas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of seconds to use to filter the messages received during that time.
|
||||
* In other words, only the messages received in the last "X" seconds will be included in
|
||||
* the history.
|
||||
*
|
||||
* @param seconds the number of seconds to use to filter the messages received during
|
||||
* that time.
|
||||
*/
|
||||
public void setSeconds(int seconds) {
|
||||
this.seconds = seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the since date to use to filter the messages received during that time.
|
||||
* In other words, only the messages received since the datetime specified will be
|
||||
* included in the history.
|
||||
*
|
||||
* @param since the since date to use to filter the messages received during that time.
|
||||
*/
|
||||
public void setSince(Date since) {
|
||||
this.since = since;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the history has been configured with some values.
|
||||
*
|
||||
* @return true if the history has been configured with some values.
|
||||
*/
|
||||
private boolean isConfigured() {
|
||||
return maxChars > -1 || maxStanzas > -1 || seconds > -1 || since != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the History that manages the amount of discussion history provided on entering a
|
||||
* room.
|
||||
*
|
||||
* @return the History that manages the amount of discussion history provided on entering a
|
||||
* room.
|
||||
*/
|
||||
MUCInitialPresence.History getMUCHistory() {
|
||||
// Return null if the history was not properly configured
|
||||
if (!isConfigured()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MUCInitialPresence.History mucHistory = new MUCInitialPresence.History();
|
||||
if (maxChars > -1) {
|
||||
mucHistory.setMaxChars(maxChars);
|
||||
}
|
||||
if (maxStanzas > -1) {
|
||||
mucHistory.setMaxStanzas(maxStanzas);
|
||||
}
|
||||
if (seconds > -1) {
|
||||
mucHistory.setSeconds(seconds);
|
||||
}
|
||||
if (since != null) {
|
||||
mucHistory.setSince(since);
|
||||
}
|
||||
return mucHistory;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jivesoftware.smackx.packet.DiscoverItems;
|
||||
|
||||
/**
|
||||
* Hosted rooms by a chat service may be discovered if they are configured to appear in the room
|
||||
* directory . The information that may be discovered is the XMPP address of the room and the room
|
||||
* name. The address of the room may be used for obtaining more detailed information
|
||||
* {@link org.jivesoftware.smackx.muc.MultiUserChat#getRoomInfo(org.jivesoftware.smack.Connection, String)}
|
||||
* or could be used for joining the room
|
||||
* {@link org.jivesoftware.smackx.muc.MultiUserChat#MultiUserChat(org.jivesoftware.smack.Connection, String)}
|
||||
* and {@link org.jivesoftware.smackx.muc.MultiUserChat#join(String)}.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class HostedRoom {
|
||||
|
||||
private String jid;
|
||||
|
||||
private String name;
|
||||
|
||||
public HostedRoom(DiscoverItems.Item item) {
|
||||
super();
|
||||
jid = item.getEntityID();
|
||||
name = item.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the XMPP address of the hosted room by the chat service. This address may be used
|
||||
* when creating a <code>MultiUserChat</code> when joining a room.
|
||||
*
|
||||
* @return the XMPP address of the hosted room by the chat service.
|
||||
*/
|
||||
public String getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the room.
|
||||
*
|
||||
* @return the name of the room.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
||||
/**
|
||||
* A listener that is fired anytime an invitation to join a MUC room is received.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public interface InvitationListener {
|
||||
|
||||
/**
|
||||
* Called when the an invitation to join a MUC room is received.<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 conn the Connection that received the invitation.
|
||||
* @param room the room that invitation refers to.
|
||||
* @param inviter the inviter that sent the invitation. (e.g. crone1@shakespeare.lit).
|
||||
* @param reason the reason why the inviter sent the invitation.
|
||||
* @param password the password to use when joining the room.
|
||||
* @param message the message used by the inviter to send the invitation.
|
||||
*/
|
||||
public abstract void invitationReceived(Connection conn, String room, String inviter, String reason,
|
||||
String password, Message message);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
/**
|
||||
* A listener that is fired anytime an invitee declines or rejects an invitation.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public interface InvitationRejectionListener {
|
||||
|
||||
/**
|
||||
* Called when the invitee declines the invitation.
|
||||
*
|
||||
* @param invitee the invitee that declined the invitation. (e.g. hecate@shakespeare.lit).
|
||||
* @param reason the reason why the invitee declined the invitation.
|
||||
*/
|
||||
public abstract void invitationDeclined(String invitee, String reason);
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,118 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jivesoftware.smackx.packet.MUCAdmin;
|
||||
import org.jivesoftware.smackx.packet.MUCUser;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Represents the information about an occupant in a given room. The information will always have
|
||||
* the affiliation and role of the occupant in the room. The full JID and nickname are optional.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class Occupant {
|
||||
// Fields that must have a value
|
||||
private String affiliation;
|
||||
private String role;
|
||||
// Fields that may have a value
|
||||
private String jid;
|
||||
private String nick;
|
||||
|
||||
Occupant(MUCAdmin.Item item) {
|
||||
super();
|
||||
this.jid = item.getJid();
|
||||
this.affiliation = item.getAffiliation();
|
||||
this.role = item.getRole();
|
||||
this.nick = item.getNick();
|
||||
}
|
||||
|
||||
Occupant(Presence presence) {
|
||||
super();
|
||||
MUCUser mucUser = (MUCUser) presence.getExtension("x",
|
||||
"http://jabber.org/protocol/muc#user");
|
||||
MUCUser.Item item = mucUser.getItem();
|
||||
this.jid = item.getJid();
|
||||
this.affiliation = item.getAffiliation();
|
||||
this.role = item.getRole();
|
||||
// Get the nickname from the FROM attribute of the presence
|
||||
this.nick = StringUtils.parseResource(presence.getFrom());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full JID of the occupant. If this information was extracted from a presence and
|
||||
* the room is semi or full-anonymous then the answer will be null. On the other hand, if this
|
||||
* information was obtained while maintaining the voice list or the moderator list then we will
|
||||
* always have a full JID.
|
||||
*
|
||||
* @return the full JID of the occupant.
|
||||
*/
|
||||
public String getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the affiliation of the occupant. Possible affiliations are: "owner", "admin",
|
||||
* "member", "outcast". This information will always be available.
|
||||
*
|
||||
* @return the affiliation of the occupant.
|
||||
*/
|
||||
public String getAffiliation() {
|
||||
return affiliation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current role of the occupant in the room. This information will always be
|
||||
* available.
|
||||
*
|
||||
* @return the current role of the occupant in the room.
|
||||
*/
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current nickname of the occupant in the room. If this information was extracted
|
||||
* from a presence then the answer will be null.
|
||||
*
|
||||
* @return the current nickname of the occupant in the room or null if this information was
|
||||
* obtained from a presence.
|
||||
*/
|
||||
public String getNick() {
|
||||
return nick;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof Occupant)) {
|
||||
return false;
|
||||
}
|
||||
Occupant occupant = (Occupant)obj;
|
||||
return jid.equals(occupant.jid);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = affiliation.hashCode();
|
||||
result = 17 * result + role.hashCode();
|
||||
result = 17 * result + jid.hashCode();
|
||||
result = 17 * result + (nick != null ? nick.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2006 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.filter.MessageTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketExtensionFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
|
||||
/**
|
||||
* The single <code>PacketListener</code> used by each {@link MultiUserChat}
|
||||
* for all basic processing of presence, and message packets targeted to that chat.
|
||||
*
|
||||
* @author Larry Kirschner
|
||||
*/
|
||||
class PacketMultiplexListener implements PacketListener {
|
||||
|
||||
private static final PacketFilter MESSAGE_FILTER =
|
||||
new MessageTypeFilter(Message.Type.groupchat);
|
||||
private static final PacketFilter PRESENCE_FILTER = new PacketTypeFilter(Presence.class);
|
||||
private static final PacketFilter SUBJECT_FILTER = new PacketFilter() {
|
||||
public boolean accept(Packet packet) {
|
||||
Message msg = (Message) packet;
|
||||
return msg.getSubject() != null;
|
||||
}
|
||||
};
|
||||
private static final PacketFilter DECLINES_FILTER =
|
||||
new PacketExtensionFilter("x",
|
||||
"http://jabber.org/protocol/muc#user");
|
||||
|
||||
private ConnectionDetachedPacketCollector messageCollector;
|
||||
private PacketListener presenceListener;
|
||||
private PacketListener subjectListener;
|
||||
private PacketListener declinesListener;
|
||||
|
||||
public PacketMultiplexListener(
|
||||
ConnectionDetachedPacketCollector messageCollector,
|
||||
PacketListener presenceListener,
|
||||
PacketListener subjectListener, PacketListener declinesListener) {
|
||||
if (messageCollector == null) {
|
||||
throw new IllegalArgumentException("MessageCollector is null");
|
||||
}
|
||||
if (presenceListener == null) {
|
||||
throw new IllegalArgumentException("Presence listener is null");
|
||||
}
|
||||
if (subjectListener == null) {
|
||||
throw new IllegalArgumentException("Subject listener is null");
|
||||
}
|
||||
if (declinesListener == null) {
|
||||
throw new IllegalArgumentException("Declines listener is null");
|
||||
}
|
||||
this.messageCollector = messageCollector;
|
||||
this.presenceListener = presenceListener;
|
||||
this.subjectListener = subjectListener;
|
||||
this.declinesListener = declinesListener;
|
||||
}
|
||||
|
||||
public void processPacket(Packet p) {
|
||||
if (PRESENCE_FILTER.accept(p)) {
|
||||
presenceListener.processPacket(p);
|
||||
}
|
||||
else if (MESSAGE_FILTER.accept(p)) {
|
||||
messageCollector.processPacket(p);
|
||||
|
||||
if (SUBJECT_FILTER.accept(p)) {
|
||||
subjectListener.processPacket(p);
|
||||
}
|
||||
}
|
||||
else if (DECLINES_FILTER.accept(p)) {
|
||||
declinesListener.processPacket(p);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
/**
|
||||
* A listener that is fired anytime a participant's status in a room is changed, such as the
|
||||
* user being kicked, banned, or granted admin permissions.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public interface ParticipantStatusListener {
|
||||
|
||||
/**
|
||||
* Called when a new room occupant has joined the room. Note: Take in consideration that when
|
||||
* you join a room you will receive the list of current occupants in the room. This message will
|
||||
* be sent for each occupant.
|
||||
*
|
||||
* @param participant the participant that has just joined the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void joined(String participant);
|
||||
|
||||
/**
|
||||
* Called when a room occupant has left the room on its own. This means that the occupant was
|
||||
* neither kicked nor banned from the room.
|
||||
*
|
||||
* @param participant the participant that has left the room on its own.
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void left(String participant);
|
||||
|
||||
/**
|
||||
* Called when a room participant has been kicked from the room. This means that the kicked
|
||||
* participant is no longer participating in the room.
|
||||
*
|
||||
* @param participant the participant that was kicked from the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
* @param actor the moderator that kicked the occupant from the room (e.g. user@host.org).
|
||||
* @param reason the reason provided by the actor to kick the occupant from the room.
|
||||
*/
|
||||
public abstract void kicked(String participant, String actor, String reason);
|
||||
|
||||
/**
|
||||
* Called when a moderator grants voice to a visitor. This means that the visitor
|
||||
* can now participate in the moderated room sending messages to all occupants.
|
||||
*
|
||||
* @param participant the participant that was granted voice in the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void voiceGranted(String participant);
|
||||
|
||||
/**
|
||||
* Called when a moderator revokes voice from a participant. This means that the participant
|
||||
* in the room was able to speak and now is a visitor that can't send messages to the room
|
||||
* occupants.
|
||||
*
|
||||
* @param participant the participant that was revoked voice from the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void voiceRevoked(String participant);
|
||||
|
||||
/**
|
||||
* Called when an administrator or owner banned a participant from the room. This means that
|
||||
* banned participant will no longer be able to join the room unless the ban has been removed.
|
||||
*
|
||||
* @param participant the participant that was banned from the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
* @param actor the administrator that banned the occupant (e.g. user@host.org).
|
||||
* @param reason the reason provided by the administrator to ban the occupant.
|
||||
*/
|
||||
public abstract void banned(String participant, String actor, String reason);
|
||||
|
||||
/**
|
||||
* Called when an administrator grants a user membership to the room. This means that the user
|
||||
* will be able to join the members-only room.
|
||||
*
|
||||
* @param participant the participant that was granted membership in the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void membershipGranted(String participant);
|
||||
|
||||
/**
|
||||
* Called when an administrator revokes a user membership to the room. This means that the
|
||||
* user will not be able to join the members-only room.
|
||||
*
|
||||
* @param participant the participant that was revoked membership from the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void membershipRevoked(String participant);
|
||||
|
||||
/**
|
||||
* Called when an administrator grants moderator privileges to a user. This means that the user
|
||||
* will be able to kick users, grant and revoke voice, invite other users, modify room's
|
||||
* subject plus all the partcipants privileges.
|
||||
*
|
||||
* @param participant the participant that was granted moderator privileges in the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void moderatorGranted(String participant);
|
||||
|
||||
/**
|
||||
* Called when an administrator revokes moderator privileges from a user. This means that the
|
||||
* user will no longer be able to kick users, grant and revoke voice, invite other users,
|
||||
* modify room's subject plus all the partcipants privileges.
|
||||
*
|
||||
* @param participant the participant that was revoked moderator privileges in the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void moderatorRevoked(String participant);
|
||||
|
||||
/**
|
||||
* Called when an owner grants a user ownership on the room. This means that the user
|
||||
* will be able to change defining room features as well as perform all administrative
|
||||
* functions.
|
||||
*
|
||||
* @param participant the participant that was granted ownership on the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void ownershipGranted(String participant);
|
||||
|
||||
/**
|
||||
* Called when an owner revokes a user ownership on the room. This means that the user
|
||||
* will no longer be able to change defining room features as well as perform all
|
||||
* administrative functions.
|
||||
*
|
||||
* @param participant the participant that was revoked ownership on the room
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void ownershipRevoked(String participant);
|
||||
|
||||
/**
|
||||
* Called when an owner grants administrator privileges to a user. This means that the user
|
||||
* will be able to perform administrative functions such as banning users and edit moderator
|
||||
* list.
|
||||
*
|
||||
* @param participant the participant that was granted administrator privileges
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void adminGranted(String participant);
|
||||
|
||||
/**
|
||||
* Called when an owner revokes administrator privileges from a user. This means that the user
|
||||
* will no longer be able to perform administrative functions such as banning users and edit
|
||||
* moderator list.
|
||||
*
|
||||
* @param participant the participant that was revoked administrator privileges
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void adminRevoked(String participant);
|
||||
|
||||
/**
|
||||
* Called when a participant changed his/her nickname in the room. The new participant's
|
||||
* nickname will be informed with the next available presence.
|
||||
*
|
||||
* @param participant the participant that was revoked administrator privileges
|
||||
* (e.g. room@conference.jabber.org/nick).
|
||||
* @param newNickname the new nickname that the participant decided to use.
|
||||
*/
|
||||
public abstract void nicknameChanged(String participant, String newNickname);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jivesoftware.smackx.Form;
|
||||
import org.jivesoftware.smackx.FormField;
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Represents the room information that was discovered using Service Discovery. It's possible to
|
||||
* obtain information about a room before joining the room but only for rooms that are public (i.e.
|
||||
* rooms that may be discovered).
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class RoomInfo {
|
||||
|
||||
/**
|
||||
* JID of the room. The node of the JID is commonly used as the ID of the room or name.
|
||||
*/
|
||||
private String room;
|
||||
/**
|
||||
* Description of the room.
|
||||
*/
|
||||
private String description = "";
|
||||
/**
|
||||
* Last known subject of the room.
|
||||
*/
|
||||
private String subject = "";
|
||||
/**
|
||||
* Current number of occupants in the room.
|
||||
*/
|
||||
private int occupantsCount = -1;
|
||||
/**
|
||||
* A room is considered members-only if an invitation is required in order to enter the room.
|
||||
* Any user that is not a member of the room won't be able to join the room unless the user
|
||||
* decides to register with the room (thus becoming a member).
|
||||
*/
|
||||
private boolean membersOnly;
|
||||
/**
|
||||
* Moderated rooms enable only participants to speak. Users that join the room and aren't
|
||||
* participants can't speak (they are just visitors).
|
||||
*/
|
||||
private boolean moderated;
|
||||
/**
|
||||
* Every presence packet can include the JID of every occupant unless the owner deactives this
|
||||
* configuration.
|
||||
*/
|
||||
private boolean nonanonymous;
|
||||
/**
|
||||
* Indicates if users must supply a password to join the room.
|
||||
*/
|
||||
private boolean passwordProtected;
|
||||
/**
|
||||
* Persistent rooms are saved to the database to make sure that rooms configurations can be
|
||||
* restored in case the server goes down.
|
||||
*/
|
||||
private boolean persistent;
|
||||
|
||||
RoomInfo(DiscoverInfo info) {
|
||||
super();
|
||||
this.room = info.getFrom();
|
||||
// Get the information based on the discovered features
|
||||
this.membersOnly = info.containsFeature("muc_membersonly");
|
||||
this.moderated = info.containsFeature("muc_moderated");
|
||||
this.nonanonymous = info.containsFeature("muc_nonanonymous");
|
||||
this.passwordProtected = info.containsFeature("muc_passwordprotected");
|
||||
this.persistent = info.containsFeature("muc_persistent");
|
||||
// Get the information based on the discovered extended information
|
||||
Form form = Form.getFormFrom(info);
|
||||
if (form != null) {
|
||||
FormField descField = form.getField("muc#roominfo_description");
|
||||
this.description = ( descField == null || !(descField.getValues().hasNext()) )? "" : descField.getValues().next();
|
||||
|
||||
FormField subjField = form.getField("muc#roominfo_subject");
|
||||
this.subject = ( subjField == null || !(subjField.getValues().hasNext()) ) ? "" : subjField.getValues().next();
|
||||
|
||||
FormField occCountField = form.getField("muc#roominfo_occupants");
|
||||
this.occupantsCount = occCountField == null ? -1 : Integer.parseInt(occCountField.getValues()
|
||||
.next());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JID of the room whose information was discovered.
|
||||
*
|
||||
* @return the JID of the room whose information was discovered.
|
||||
*/
|
||||
public String getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the discovered description of the room.
|
||||
*
|
||||
* @return the discovered description of the room.
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the discovered subject of the room. The subject may be empty if the room does not
|
||||
* have a subject.
|
||||
*
|
||||
* @return the discovered subject of the room.
|
||||
*/
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the discovered number of occupants that are currently in the room. If this
|
||||
* information was not discovered (i.e. the server didn't send it) then a value of -1 will be
|
||||
* returned.
|
||||
*
|
||||
* @return the number of occupants that are currently in the room or -1 if that information was
|
||||
* not provided by the server.
|
||||
*/
|
||||
public int getOccupantsCount() {
|
||||
return occupantsCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the room has restricted the access so that only members may enter the room.
|
||||
*
|
||||
* @return true if the room has restricted the access so that only members may enter the room.
|
||||
*/
|
||||
public boolean isMembersOnly() {
|
||||
return membersOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the room enabled only participants to speak. Occupants with a role of
|
||||
* visitor won't be able to speak in the room.
|
||||
*
|
||||
* @return true if the room enabled only participants to speak.
|
||||
*/
|
||||
public boolean isModerated() {
|
||||
return moderated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if presence packets will include the JID of every occupant.
|
||||
*
|
||||
* @return true if presence packets will include the JID of every occupant.
|
||||
*/
|
||||
public boolean isNonanonymous() {
|
||||
return nonanonymous;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if users musy provide a valid password in order to join the room.
|
||||
*
|
||||
* @return true if users musy provide a valid password in order to join the room.
|
||||
*/
|
||||
public boolean isPasswordProtected() {
|
||||
return passwordProtected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the room will persist after the last occupant have left the room.
|
||||
*
|
||||
* @return true if the room will persist after the last occupant have left the room.
|
||||
*/
|
||||
public boolean isPersistent() {
|
||||
return persistent;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,224 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2006 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jivesoftware.smack.ConnectionListener;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* A <code>RoomListenerMultiplexor</code> multiplexes incoming packets on
|
||||
* a <code>Connection</code> using a single listener/filter pair.
|
||||
* A single <code>RoomListenerMultiplexor</code> is created for each
|
||||
* {@link org.jivesoftware.smack.Connection} that has joined MUC rooms
|
||||
* within its session.
|
||||
*
|
||||
* @author Larry Kirschner
|
||||
*/
|
||||
class RoomListenerMultiplexor implements ConnectionListener {
|
||||
|
||||
// We use a WeakHashMap so that the GC can collect the monitor when the
|
||||
// connection is no longer referenced by any object.
|
||||
private static final Map<Connection, WeakReference<RoomListenerMultiplexor>> monitors =
|
||||
new WeakHashMap<Connection, WeakReference<RoomListenerMultiplexor>>();
|
||||
|
||||
private Connection connection;
|
||||
private RoomMultiplexFilter filter;
|
||||
private RoomMultiplexListener listener;
|
||||
|
||||
/**
|
||||
* Returns a new or existing RoomListenerMultiplexor for a given connection.
|
||||
*
|
||||
* @param conn the connection to monitor for room invitations.
|
||||
* @return a new or existing RoomListenerMultiplexor for a given connection.
|
||||
*/
|
||||
public static RoomListenerMultiplexor getRoomMultiplexor(Connection conn) {
|
||||
synchronized (monitors) {
|
||||
if (!monitors.containsKey(conn) || monitors.get(conn).get() == null) {
|
||||
RoomListenerMultiplexor rm = new RoomListenerMultiplexor(conn, new RoomMultiplexFilter(),
|
||||
new RoomMultiplexListener());
|
||||
|
||||
rm.init();
|
||||
|
||||
// We need to use a WeakReference because the monitor references the
|
||||
// connection and this could prevent the GC from collecting the monitor
|
||||
// when no other object references the monitor
|
||||
monitors.put(conn, new WeakReference<RoomListenerMultiplexor>(rm));
|
||||
}
|
||||
// Return the InvitationsMonitor that monitors the connection
|
||||
return monitors.get(conn).get();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All access should be through
|
||||
* the static method {@link #getRoomMultiplexor(Connection)}.
|
||||
*/
|
||||
private RoomListenerMultiplexor(Connection connection, RoomMultiplexFilter filter,
|
||||
RoomMultiplexListener listener) {
|
||||
if (connection == null) {
|
||||
throw new IllegalArgumentException("Connection is null");
|
||||
}
|
||||
if (filter == null) {
|
||||
throw new IllegalArgumentException("Filter is null");
|
||||
}
|
||||
if (listener == null) {
|
||||
throw new IllegalArgumentException("Listener is null");
|
||||
}
|
||||
this.connection = connection;
|
||||
this.filter = filter;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void addRoom(String address, PacketMultiplexListener roomListener) {
|
||||
filter.addRoom(address);
|
||||
listener.addRoom(address, roomListener);
|
||||
}
|
||||
|
||||
public void connectionClosed() {
|
||||
cancel();
|
||||
}
|
||||
|
||||
public void connectionClosedOnError(Exception e) {
|
||||
cancel();
|
||||
}
|
||||
|
||||
public void reconnectingIn(int seconds) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
public void reconnectionSuccessful() {
|
||||
// ignore
|
||||
}
|
||||
|
||||
public void reconnectionFailed(Exception e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* listeners will be fired. When the connection gets closed the monitor will remove
|
||||
* his listeners on the connection.
|
||||
*/
|
||||
public void init() {
|
||||
connection.addConnectionListener(this);
|
||||
connection.addPacketListener(listener, filter);
|
||||
}
|
||||
|
||||
public void removeRoom(String address) {
|
||||
filter.removeRoom(address);
|
||||
listener.removeRoom(address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels all the listeners that this InvitationsMonitor has added to the connection.
|
||||
*/
|
||||
private void cancel() {
|
||||
connection.removeConnectionListener(this);
|
||||
connection.removePacketListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* The single <code>Connection</code>-level <code>PacketFilter</code> used by a {@link RoomListenerMultiplexor}
|
||||
* for all muc chat rooms on an <code>Connection</code>.
|
||||
* Each time a muc chat room is added to/removed from an
|
||||
* <code>Connection</code> the address for that chat room
|
||||
* is added to/removed from that <code>Connection</code>'s
|
||||
* <code>RoomMultiplexFilter</code>.
|
||||
*/
|
||||
private static class RoomMultiplexFilter implements PacketFilter {
|
||||
|
||||
private Map<String, String> roomAddressTable = new ConcurrentHashMap<String, String>();
|
||||
|
||||
public boolean accept(Packet p) {
|
||||
String from = p.getFrom();
|
||||
if (from == null) {
|
||||
return false;
|
||||
}
|
||||
return roomAddressTable.containsKey(StringUtils.parseBareAddress(from).toLowerCase());
|
||||
}
|
||||
|
||||
public void addRoom(String address) {
|
||||
if (address == null) {
|
||||
return;
|
||||
}
|
||||
roomAddressTable.put(address.toLowerCase(), address);
|
||||
}
|
||||
|
||||
public void removeRoom(String address) {
|
||||
if (address == null) {
|
||||
return;
|
||||
}
|
||||
roomAddressTable.remove(address.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The single <code>Connection</code>-level <code>PacketListener</code>
|
||||
* used by a {@link RoomListenerMultiplexor}
|
||||
* for all muc chat rooms on an <code>Connection</code>.
|
||||
* Each time a muc chat room is added to/removed from an
|
||||
* <code>Connection</code> the address and listener for that chat room
|
||||
* are added to/removed from that <code>Connection</code>'s
|
||||
* <code>RoomMultiplexListener</code>.
|
||||
*
|
||||
* @author Larry Kirschner
|
||||
*/
|
||||
private static class RoomMultiplexListener implements PacketListener {
|
||||
|
||||
private Map<String, PacketMultiplexListener> roomListenersByAddress =
|
||||
new ConcurrentHashMap<String, PacketMultiplexListener>();
|
||||
|
||||
public void processPacket(Packet p) {
|
||||
String from = p.getFrom();
|
||||
if (from == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PacketMultiplexListener listener =
|
||||
roomListenersByAddress.get(StringUtils.parseBareAddress(from).toLowerCase());
|
||||
|
||||
if (listener != null) {
|
||||
listener.processPacket(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void addRoom(String address, PacketMultiplexListener listener) {
|
||||
if (address == null) {
|
||||
return;
|
||||
}
|
||||
roomListenersByAddress.put(address.toLowerCase(), listener);
|
||||
}
|
||||
|
||||
public void removeRoom(String address) {
|
||||
if (address == null) {
|
||||
return;
|
||||
}
|
||||
roomListenersByAddress.remove(address.toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
/**
|
||||
* A listener that is fired anytime a MUC room changes its subject.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public interface SubjectUpdatedListener {
|
||||
|
||||
/**
|
||||
* Called when a MUC room has changed its subject.
|
||||
*
|
||||
* @param subject the new room's subject.
|
||||
* @param from the user that changed the room's subject (e.g. room@conference.jabber.org/nick).
|
||||
*/
|
||||
public abstract void subjectUpdated(String subject, String from);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
/**
|
||||
* A listener that is fired anytime your participant's status in a room is changed, such as the
|
||||
* user being kicked, banned, or granted admin permissions.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public interface UserStatusListener {
|
||||
|
||||
/**
|
||||
* Called when a moderator kicked your user from the room. This means that you are no longer
|
||||
* participanting in the room.
|
||||
*
|
||||
* @param actor the moderator that kicked your user from the room (e.g. user@host.org).
|
||||
* @param reason the reason provided by the actor to kick you from the room.
|
||||
*/
|
||||
public abstract void kicked(String actor, String reason);
|
||||
|
||||
/**
|
||||
* Called when a moderator grants voice to your user. This means that you were a visitor in
|
||||
* the moderated room before and now you can participate in the room by sending messages to
|
||||
* all occupants.
|
||||
*
|
||||
*/
|
||||
public abstract void voiceGranted();
|
||||
|
||||
/**
|
||||
* Called when a moderator revokes voice from your user. This means that you were a
|
||||
* participant in the room able to speak and now you are a visitor that can't send
|
||||
* messages to the room occupants.
|
||||
*
|
||||
*/
|
||||
public abstract void voiceRevoked();
|
||||
|
||||
/**
|
||||
* Called when an administrator or owner banned your user from the room. This means that you
|
||||
* will no longer be able to join the room unless the ban has been removed.
|
||||
*
|
||||
* @param actor the administrator that banned your user (e.g. user@host.org).
|
||||
* @param reason the reason provided by the administrator to banned you.
|
||||
*/
|
||||
public abstract void banned(String actor, String reason);
|
||||
|
||||
/**
|
||||
* Called when an administrator grants your user membership to the room. This means that you
|
||||
* will be able to join the members-only room.
|
||||
*
|
||||
*/
|
||||
public abstract void membershipGranted();
|
||||
|
||||
/**
|
||||
* Called when an administrator revokes your user membership to the room. This means that you
|
||||
* will not be able to join the members-only room.
|
||||
*
|
||||
*/
|
||||
public abstract void membershipRevoked();
|
||||
|
||||
/**
|
||||
* Called when an administrator grants moderator privileges to your user. This means that you
|
||||
* will be able to kick users, grant and revoke voice, invite other users, modify room's
|
||||
* subject plus all the partcipants privileges.
|
||||
*
|
||||
*/
|
||||
public abstract void moderatorGranted();
|
||||
|
||||
/**
|
||||
* Called when an administrator revokes moderator privileges from your user. This means that
|
||||
* you will no longer be able to kick users, grant and revoke voice, invite other users,
|
||||
* modify room's subject plus all the partcipants privileges.
|
||||
*
|
||||
*/
|
||||
public abstract void moderatorRevoked();
|
||||
|
||||
/**
|
||||
* Called when an owner grants to your user ownership on the room. This means that you
|
||||
* will be able to change defining room features as well as perform all administrative
|
||||
* functions.
|
||||
*
|
||||
*/
|
||||
public abstract void ownershipGranted();
|
||||
|
||||
/**
|
||||
* Called when an owner revokes from your user ownership on the room. This means that you
|
||||
* will no longer be able to change defining room features as well as perform all
|
||||
* administrative functions.
|
||||
*
|
||||
*/
|
||||
public abstract void ownershipRevoked();
|
||||
|
||||
/**
|
||||
* Called when an owner grants administrator privileges to your user. This means that you
|
||||
* will be able to perform administrative functions such as banning users and edit moderator
|
||||
* list.
|
||||
*
|
||||
*/
|
||||
public abstract void adminGranted();
|
||||
|
||||
/**
|
||||
* Called when an owner revokes administrator privileges from your user. This means that you
|
||||
* will no longer be able to perform administrative functions such as banning users and edit
|
||||
* moderator list.
|
||||
*
|
||||
*/
|
||||
public abstract void adminRevoked();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
<body>Classes and Interfaces that implement Multi-User Chat (MUC).</body>
|
||||
Loading…
Add table
Add a link
Reference in a new issue