mirror of https://github.com/sipwise/jitsi.git
parent
99a732d5f4
commit
2a5e9c4895
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.protocol.jabber.extensions.messagecorrection;
|
||||
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
|
||||
/**
|
||||
* Represents an XMPP Message correction extension, as defined in XEP-308.
|
||||
*
|
||||
* @author Ivan Vergiliev
|
||||
*/
|
||||
public class MessageCorrectionExtension
|
||||
implements PacketExtension
|
||||
{
|
||||
/**
|
||||
* The XMPP namespace that this extension belongs to.
|
||||
*/
|
||||
public static final String NAMESPACE = "urn:xmpp:message-correct:0";
|
||||
|
||||
/**
|
||||
* The XMPP namespace that Swift IM use to send message corrections.
|
||||
* Temporary until they start using the standard one.
|
||||
*/
|
||||
public static final String SWIFT_NAMESPACE =
|
||||
"http://swift.im/protocol/replace";
|
||||
|
||||
/**
|
||||
* The XML element name of this extension.
|
||||
*/
|
||||
public static final String ELEMENT_NAME = "replace";
|
||||
|
||||
/**
|
||||
* Name of the attribute that specifies the ID of the message
|
||||
* being corrected.
|
||||
*/
|
||||
public static final String ID_ATTRIBUTE_NAME = "id";
|
||||
|
||||
/**
|
||||
* The ID of the message being corrected.
|
||||
*/
|
||||
private String correctedMessageUID;
|
||||
|
||||
/**
|
||||
* Creates a new message correction extension that corrects the
|
||||
* message specified by the passed ID.
|
||||
*
|
||||
* @param correctedMessageUID The ID of the message being corrected.
|
||||
*/
|
||||
public MessageCorrectionExtension(String correctedMessageUID)
|
||||
{
|
||||
this.correctedMessageUID = correctedMessageUID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the XML element name of this extension.
|
||||
*
|
||||
* @return The XML element name of this extension.
|
||||
*/
|
||||
public String getElementName()
|
||||
{
|
||||
return ELEMENT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the XML namespace this extension belongs to.
|
||||
*
|
||||
* @return The XML namespace this extension belongs to.
|
||||
*/
|
||||
public String getNamespace()
|
||||
{
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an XML element representing this extension;
|
||||
* has the form '<replace id="..." xmlns="...">'.
|
||||
*
|
||||
* @return An XML representation of this extension.
|
||||
*/
|
||||
public String toXML()
|
||||
{
|
||||
return "<" + ELEMENT_NAME + " id='" + correctedMessageUID
|
||||
+ "' xmlns='" + NAMESPACE + "' />";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the correctedMessageUID The UID of the message being corrected.
|
||||
*
|
||||
* @return the correctedMessageUID The UID of the message being corrected.
|
||||
*/
|
||||
public String getCorrectedMessageUID()
|
||||
{
|
||||
return correctedMessageUID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the UID of the message being corrected.
|
||||
*
|
||||
* @param correctedMessageUID The UID of the message being corrected.
|
||||
*/
|
||||
public void setCorrectedMessageUID(String correctedMessageUID)
|
||||
{
|
||||
this.correctedMessageUID = correctedMessageUID;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.protocol.jabber.extensions.messagecorrection;
|
||||
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.provider.*;
|
||||
import org.xmlpull.v1.*;
|
||||
|
||||
/**
|
||||
* Creates Smack packet extensions by parsing <replace /> tags
|
||||
* from incoming XMPP packets.
|
||||
*
|
||||
* @author Ivan Vergiliev
|
||||
*/
|
||||
public class MessageCorrectionExtensionProvider
|
||||
implements PacketExtensionProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a new correction extension by parsing an XML element.
|
||||
*
|
||||
* @param parser An XML parser.
|
||||
* @return A new MesssageCorrectionExtension parsed from the XML.
|
||||
* @throws Exception if an error occurs parsing the XML.
|
||||
*/
|
||||
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
|
||||
{
|
||||
MessageCorrectionExtension res = new MessageCorrectionExtension(null);
|
||||
|
||||
do
|
||||
{
|
||||
if (parser.getEventType() == XmlPullParser.START_TAG)
|
||||
{
|
||||
res.setCorrectedMessageUID(parser.getAttributeValue(
|
||||
null, MessageCorrectionExtension.ID_ATTRIBUTE_NAME));
|
||||
}
|
||||
}
|
||||
while (parser.next() != XmlPullParser.END_TAG);
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.service.protocol;
|
||||
|
||||
/**
|
||||
* Provides functionality for correcting instant messages.
|
||||
*
|
||||
* @author Ivan Vergiliev
|
||||
*/
|
||||
public interface OperationSetMessageCorrection
|
||||
extends OperationSetBasicInstantMessaging
|
||||
{
|
||||
/**
|
||||
* Replaces the message with ID <tt>correctedMessageUID</tt> sent to
|
||||
* the contact <tt>to</tt> with the message <tt>message</tt>
|
||||
*
|
||||
* @param to The contact to send the message to.
|
||||
* @param message The new message.
|
||||
* @param correctedMessageUID The ID of the message being replaced.
|
||||
*/
|
||||
public void correctMessage(Contact to, Message message,
|
||||
String correctedMessageUID);
|
||||
}
|
||||
Loading…
Reference in new issue