1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-30 16:02:07 +01:00
Smack/source/org/jivesoftware/smackx/muc/DeafOccupantInterceptor.java
Gaston Dombiak f57ff10ad9 1. Clean up code
2. Refactoring work
3. Optimization work. SMACK-153
4. Fixed roster test cases. SMACK-154
4. Fixed vCard issue. SMACK-152

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@4538 b35dd754-fafc-0310-a699-88a17e54d16e
2006-07-18 05:14:33 +00:00

76 lines
2.8 KiB
Java

/**
* $RCSfile$
* $Revision: $
* $Date: $
*
* 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();
}
}
}