Commit ab4ab0e9 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added support for deaf occupants. JM-579

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3494 b35dd754-fafc-0310-a699-88a17e54d16e
parent 26da5404
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
package org.jivesoftware.wildfire.muc; package org.jivesoftware.wildfire.muc;
import org.dom4j.Element;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import org.dom4j.Element; import org.xmpp.packet.Presence;
/** /**
* Defines the permissions and actions that a MUCUser may use in * Defines the permissions and actions that a MUCUser may use in
...@@ -215,6 +215,26 @@ public interface MUCRole { ...@@ -215,6 +215,26 @@ public interface MUCRole {
*/ */
public void changeNickname(String nickname); public void changeNickname(String nickname);
/**
* Returns true if the room occupant does not want to get messages broadcasted to all
* room occupants. This type of users are called "deaf" occupants. Deaf occupants will still
* be able to get private messages, presences, IQ packets or room history.<p>
*
* To be a deaf occupant the initial presence sent to the room while joining the room has
* to include the following child element:
* <pre>
* &lt;x xmlns='http://jivesoftware.org/protocol/muc'&gt;
* &lt;deaf-occupant/&gt;
* &lt;/x&gt;
* </pre>
*
* Note that this is a custom extension to the MUC specification.
*
* @return true if the room occupant does not want to get messages broadcasted to all
* room occupants.
*/
boolean isVoiceOnly();
/** /**
* Obtain the chat user that plays this role. * Obtain the chat user that plays this role.
* *
......
...@@ -11,20 +11,18 @@ ...@@ -11,20 +11,18 @@
package org.jivesoftware.wildfire.muc.spi; package org.jivesoftware.wildfire.muc.spi;
import org.dom4j.Element;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.QName; import org.dom4j.QName;
import org.jivesoftware.wildfire.PacketRouter; import org.jivesoftware.util.ElementUtil;
import org.jivesoftware.wildfire.ClientSession; import org.jivesoftware.wildfire.ClientSession;
import org.jivesoftware.wildfire.XMPPServer; import org.jivesoftware.wildfire.PacketRouter;
import org.jivesoftware.wildfire.Session; import org.jivesoftware.wildfire.Session;
import org.jivesoftware.wildfire.muc.MUCRole; import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.muc.MUCRoom; import org.jivesoftware.wildfire.muc.*;
import org.jivesoftware.wildfire.muc.MUCUser; import org.xmpp.packet.JID;
import org.jivesoftware.wildfire.muc.MultiUserChatServer; import org.xmpp.packet.Packet;
import org.jivesoftware.wildfire.muc.NotAllowedException; import org.xmpp.packet.Presence;
import org.jivesoftware.util.ElementUtil;
import org.xmpp.packet.*;
/** /**
* Simple in-memory implementation of a role in a chatroom * Simple in-memory implementation of a role in a chatroom
...@@ -68,6 +66,12 @@ public class MUCRoleImpl implements MUCRole { ...@@ -68,6 +66,12 @@ public class MUCRoleImpl implements MUCRole {
*/ */
private MUCRole.Affiliation affiliation; private MUCRole.Affiliation affiliation;
/**
* Flag that indicates if the room occupant is in the room only to send messages or also
* to receive room messages. True means that the room occupant is deaf.
*/
private boolean voiceOnly = false;
/** /**
* The router used to send packets from this role. * The router used to send packets from this role.
*/ */
...@@ -120,6 +124,12 @@ public class MUCRoleImpl implements MUCRole { ...@@ -120,6 +124,12 @@ public class MUCRoleImpl implements MUCRole {
calculateExtendedInformation(); calculateExtendedInformation();
rJID = new JID(room.getName(), server.getServiceDomain(), nick); rJID = new JID(room.getName(), server.getServiceDomain(), nick);
setPresence(presence); setPresence(presence);
// Check if new occupant wants to be a deaf occupant
Element element = presence.getElement()
.element(QName.get("x", "http://jivesoftware.org/protocol/muc"));
if (element != null) {
voiceOnly = element.element("deaf-occupant/") != null;
}
// Add the new role to the list of roles // Add the new role to the list of roles
user.addRole(room.getName(), this); user.addRole(room.getName(), this);
} }
...@@ -216,6 +226,10 @@ public class MUCRoleImpl implements MUCRole { ...@@ -216,6 +226,10 @@ public class MUCRoleImpl implements MUCRole {
presence.setFrom(jid); presence.setFrom(jid);
} }
public boolean isVoiceOnly() {
return voiceOnly;
}
public void send(Packet packet) { public void send(Packet packet) {
if (packet == null) { if (packet == null) {
return; return;
......
...@@ -11,21 +11,24 @@ ...@@ -11,21 +11,24 @@
package org.jivesoftware.wildfire.muc.spi; package org.jivesoftware.wildfire.muc.spi;
import java.util.*; import org.dom4j.Element;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.jivesoftware.database.SequenceManager; import org.jivesoftware.database.SequenceManager;
import org.jivesoftware.wildfire.muc.*; import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.*; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.wildfire.*; import org.jivesoftware.util.Log;
import org.jivesoftware.util.NotFoundException;
import org.jivesoftware.wildfire.PacketRouter;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.muc.*;
import org.jivesoftware.wildfire.user.UserAlreadyExistsException; import org.jivesoftware.wildfire.user.UserAlreadyExistsException;
import org.jivesoftware.wildfire.user.UserNotFoundException; import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.*; import org.xmpp.packet.*;
import org.dom4j.Element;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/** /**
* Simple in-memory implementation of a chatroom. A MUCRoomImpl could represent a persistent room * Simple in-memory implementation of a chatroom. A MUCRoomImpl could represent a persistent room
...@@ -834,7 +837,10 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -834,7 +837,10 @@ public class MUCRoomImpl implements MUCRoom {
private void broadcast(Message message) { private void broadcast(Message message) {
for (MUCRole occupant : occupants.values()) { for (MUCRole occupant : occupants.values()) {
occupant.send(message); // Do not send broadcast messages to deaf occupants
if (!occupant.isVoiceOnly()) {
occupant.send(message);
}
} }
if (isLogEnabled()) { if (isLogEnabled()) {
MUCRole senderRole = null; MUCRole senderRole = null;
...@@ -900,6 +906,10 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -900,6 +906,10 @@ public class MUCRoomImpl implements MUCRoom {
return null; return null;
} }
public boolean isVoiceOnly() {
return false;
}
public MUCRoom getChatRoom() { public MUCRoom getChatRoom() {
return room; return room;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment