mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Add Enable/Disable Carbon IQs
This commit is contained in:
parent
b60107db08
commit
bd333bd1ac
3 changed files with 83 additions and 13 deletions
|
@ -34,6 +34,8 @@ import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
||||||
|
import org.jivesoftware.smackx.carbons.packet.Carbon;
|
||||||
|
import org.jivesoftware.smackx.carbons.packet.CarbonExtension.Private;
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,13 +87,13 @@ public class CarbonManager extends Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IQ carbonsEnabledIQ(final boolean new_state) {
|
private static IQ carbonsEnabledIQ(final boolean new_state) {
|
||||||
IQ setIQ = new IQ() {
|
IQ request;
|
||||||
public String getChildElementXML() {
|
if (new_state) {
|
||||||
return "<" + (new_state? "enable" : "disable") + " xmlns='" + CarbonExtension.NAMESPACE + "'/>";
|
request = new Carbon.Enable();
|
||||||
}
|
} else {
|
||||||
};
|
request = new Carbon.Disable();
|
||||||
setIQ.setType(IQ.Type.set);
|
}
|
||||||
return setIQ;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -187,8 +189,10 @@ public class CarbonManager extends Manager {
|
||||||
* Mark a message as "private", so it will not be carbon-copied.
|
* Mark a message as "private", so it will not be carbon-copied.
|
||||||
*
|
*
|
||||||
* @param msg Message object to mark private
|
* @param msg Message object to mark private
|
||||||
|
* @deprecated use {@link Private#addTo(Message)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static void disableCarbons(Message msg) {
|
public static void disableCarbons(Message msg) {
|
||||||
msg.addExtension(new CarbonExtension.Private());
|
msg.addExtension(Private.INSTANCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright © 2014 Florian Schmaus
|
||||||
|
*
|
||||||
|
* 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.carbons.packet;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Carbon IQs
|
||||||
|
*/
|
||||||
|
public class Carbon {
|
||||||
|
public static final String NAMESPACE = "urn:xmpp:carbons:2";
|
||||||
|
|
||||||
|
public static class Enable extends IQ {
|
||||||
|
public static final String ELEMENT = "enable";
|
||||||
|
|
||||||
|
public Enable() {
|
||||||
|
setType(Type.set);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getChildElementXML() {
|
||||||
|
return "<" + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Disable extends IQ {
|
||||||
|
public static final String ELEMENT = "disable";
|
||||||
|
|
||||||
|
public Disable() {
|
||||||
|
setType(Type.set);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getChildElementXML() {
|
||||||
|
return "<" + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,7 +33,7 @@ import org.jivesoftware.smackx.forward.Forwarded;
|
||||||
* @author Georg Lukas
|
* @author Georg Lukas
|
||||||
*/
|
*/
|
||||||
public class CarbonExtension implements PacketExtension {
|
public class CarbonExtension implements PacketExtension {
|
||||||
public static final String NAMESPACE = "urn:xmpp:carbons:2";
|
public static final String NAMESPACE = Carbon.NAMESPACE;
|
||||||
|
|
||||||
private final Direction dir;
|
private final Direction dir;
|
||||||
private final Forwarded fwd;
|
private final Forwarded fwd;
|
||||||
|
@ -97,9 +97,9 @@ public class CarbonExtension implements PacketExtension {
|
||||||
* @return a Carbon if available, null otherwise.
|
* @return a Carbon if available, null otherwise.
|
||||||
*/
|
*/
|
||||||
public static CarbonExtension getFrom(Message msg) {
|
public static CarbonExtension getFrom(Message msg) {
|
||||||
CarbonExtension cc = msg.getExtension(Direction.received.name(), CarbonExtension.NAMESPACE);
|
CarbonExtension cc = msg.getExtension(Direction.received.name(), NAMESPACE);
|
||||||
if (cc == null)
|
if (cc == null)
|
||||||
cc = msg.getExtension(Direction.sent.name(), CarbonExtension.NAMESPACE);
|
cc = msg.getExtension(Direction.sent.name(), NAMESPACE);
|
||||||
return cc;
|
return cc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,8 +116,12 @@ public class CarbonExtension implements PacketExtension {
|
||||||
* extension to any message will disallow that message from being copied.
|
* extension to any message will disallow that message from being copied.
|
||||||
*/
|
*/
|
||||||
public static class Private implements PacketExtension {
|
public static class Private implements PacketExtension {
|
||||||
|
public static final Private INSTANCE = new Private();
|
||||||
public static final String ELEMENT = "private";
|
public static final String ELEMENT = "private";
|
||||||
|
|
||||||
|
private Private() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getElementName() {
|
public String getElementName() {
|
||||||
return ELEMENT;
|
return ELEMENT;
|
||||||
|
@ -125,12 +129,22 @@ public class CarbonExtension implements PacketExtension {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNamespace() {
|
public String getNamespace() {
|
||||||
return CarbonExtension.NAMESPACE;
|
return NAMESPACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toXML() {
|
public String toXML() {
|
||||||
return "<" + ELEMENT + " xmlns='" + CarbonExtension.NAMESPACE + "'/>";
|
return "<" + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a message "private", so that it will not be carbon-copied, by adding private packet
|
||||||
|
* extension to the message.
|
||||||
|
*
|
||||||
|
* @param message the message to add the private extension to
|
||||||
|
*/
|
||||||
|
public static void addTo(Message message) {
|
||||||
|
message.addExtension(INSTANCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue