From e386f8e1a2731f866659465097a913a13b8509d1 Mon Sep 17 00:00:00 2001 From: Fernando Ramirez Date: Fri, 16 Sep 2016 15:50:56 -0300 Subject: [PATCH] Chat Markers (XEP-0333) implementation --- documentation/extensions/index.md | 7 +- .../chat_markers/ChatMarkersManager.java | 89 +++++++ .../element/ChatMarkersElements.java | 234 ++++++++++++++++++ .../chat_markers/element/package-info.java | 24 ++ .../smackx/chat_markers/package-info.java | 24 ++ .../provider/AcknowledgedProvider.java | 39 +++ .../provider/DisplayedProvider.java | 39 +++ .../provider/MarkableProvider.java | 38 +++ .../provider/ReceivedProvider.java | 39 +++ .../chat_markers/provider/package-info.java | 24 ++ .../experimental.providers | 22 ++ .../AcknowledgedExtensionTest.java | 55 ++++ .../chat_markers/DisplayedExtensionTest.java | 55 ++++ .../chat_markers/MarkableExtensionTest.java | 57 +++++ .../chat_markers/ReceivedExtensionTest.java | 55 ++++ 15 files changed, 798 insertions(+), 3 deletions(-) create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/ChatMarkersManager.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/element/ChatMarkersElements.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/element/package-info.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/package-info.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/AcknowledgedProvider.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/DisplayedProvider.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/MarkableProvider.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/ReceivedProvider.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/package-info.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/AcknowledgedExtensionTest.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/DisplayedExtensionTest.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/MarkableExtensionTest.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/ReceivedExtensionTest.java diff --git a/documentation/extensions/index.md b/documentation/extensions/index.md index 7a669a407b..75d75fc01c 100644 --- a/documentation/extensions/index.md +++ b/documentation/extensions/index.md @@ -61,6 +61,7 @@ Smack Extensions and currently supported XEPs of smack-extensions | Data Forms Layout | [XEP-0141](http://xmpp.org/extensions/xep-0141.html) | Enables an application to specify form layouts. | | Personal Eventing Protocol | [XEP-0163](http://xmpp.org/extensions/xep-0163.html) | Using the XMPP publish-subscribe protocol to broadcast state change events associated with an XMPP account. | | Message Delivery Receipts | [XEP-0184](http://xmpp.org/extensions/xep-0184.html) | Extension for message delivery receipts. The sender can request notification that the message has been delivered. | +| [Blocking Command](blockingcommand.md) | [XEP-0191](http://xmpp.org/extensions/xep-0191.html) | Communications blocking that is intended to be simpler than privacy lists (XEP-0016). | | XMPP Ping | [XEP-0199](http://xmpp.org/extensions/xep-0199.html) | Sending application-level pings over XML streams. | Entity Time | [XEP-0202](http://xmpp.org/extensions/xep-0202.html) | Allows entities to communicate their local time | | Delayed Delivery | [XEP-0203](http://xmpp.org/extensions/xep-0203.html) | Extension for communicating the fact that an XML stanza has been delivered with a delay. | @@ -69,7 +70,6 @@ Smack Extensions and currently supported XEPs of smack-extensions | Last Message Correction | [XEP-0308](http://xmpp.org/extensions/xep-0308.html) | Provides a method for indicating that a message is a correction of the last sent message. | | [Group Chat Invitations](invitation.md) | n/a | Send invitations to other users to join a group chat room. | | [Jive Properties](properties.md) | n/a | TODO | -| [Blocking Command](blockingcommand.md) | [XEP-0191](http://xmpp.org/extensions/xep-0191.html) | Communications blocking that is intended to be simpler than privacy lists (XEP-0016). | Experimental Smack Extensions and currently supported XEPs of smack-experimental @@ -78,15 +78,16 @@ Experimental Smack Extensions and currently supported XEPs of smack-experimental | Name | XEP | Description | |---------------------------------------------|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------| | Message Carbons | [XEP-0280](http://xmpp.org/extensions/xep-0280.html) | Keep all IM clients for a user engaged in a conversation, by carbon-copy outbound messages to all interested resources. +| [Message Archive Management](mam.md) | [XEP-0313](http://xmpp.org/extensions/xep-0313.html) | Query and control an archive of messages stored on a server. | | [Internet of Things - Sensor Data](iot.md) | [XEP-0323](http://xmpp.org/extensions/xep-0323.html) | Sensor data interchange over XMPP. | | [Internet of Things - Provisioning](iot.md) | [XEP-0324](http://xmpp.org/extensions/xep-0324.html) | Provisioning, access rights and user priviliges for the Internet of Things. | | [Internet of Things - Control](iot.md) | [XEP-0325](http://xmpp.org/extensions/xep-0325.html) | Describes how to control devices or actuators in an XMPP-based sensor netowrk. | | [HTTP over XMPP transport](hoxt.md) | [XEP-0332](http://xmpp.org/extensions/xep-0332.html) | Allows to transport HTTP communication over XMPP peer-to-peer networks. | +| Chat Markers | [XEP-0333](http://xmpp.org/extensions/xep-0333.html) | A solution of marking the last received, displayed and acknowledged message in a chat. | | JSON Containers | [XEP-0335](http://xmpp.org/extensions/xep-0335.html) | Encapsulation of JSON data within XMPP Stanzas. | | [Internet of Things - Discovery](iot.md) | [XEP-0347](http://xmpp.org/extensions/xep-0347.html) | Describes how Things can be installed and discovered by their owners. | -| Google GCM JSON payload | n/a | Semantically the same as XEP-0335: JSON Containers | | Client State Indication | [XEP-0352](http://xmpp.org/extensions/xep-0352.html) | A way for the client to indicate its active/inactive state. | -| [Message Archive Management](mam.md) | [XEP-0313](http://xmpp.org/extensions/xep-0313.html) | Query and control an archive of messages stored on a server. | +| Google GCM JSON payload | n/a | Semantically the same as XEP-0335: JSON Containers | Legacy Smack Extensions and currently supported XEPs of smack-legacy diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/ChatMarkersManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/ChatMarkersManager.java new file mode 100644 index 0000000000..1727f83a34 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/ChatMarkersManager.java @@ -0,0 +1,89 @@ +/** + * + * Copyright © 2016 Fernando Ramirez + * + * 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.chat_markers; + +import java.util.Map; +import java.util.WeakHashMap; + +import org.jivesoftware.smack.ConnectionCreationListener; +import org.jivesoftware.smack.Manager; +import org.jivesoftware.smack.SmackException.NoResponseException; +import org.jivesoftware.smack.SmackException.NotConnectedException; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPConnectionRegistry; +import org.jivesoftware.smack.XMPPException.XMPPErrorException; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements; +import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; + +/** + * Chat Markers Manager class (XEP-0333). + * + * @see XEP-0333: Chat + * Markers + * @author Fernando Ramirez + * + */ +public final class ChatMarkersManager extends Manager { + + static { + XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { + @Override + public void connectionCreated(XMPPConnection connection) { + getInstanceFor(connection); + } + }); + } + + private static final Map INSTANCES = new WeakHashMap<>(); + + /** + * Get the singleton instance of ChatMarkersManager. + * + * @param connection + * @return the instance of ChatMarkersManager + */ + public static synchronized ChatMarkersManager getInstanceFor(XMPPConnection connection) { + ChatMarkersManager chatMarkersManager = INSTANCES.get(connection); + + if (chatMarkersManager == null) { + chatMarkersManager = new ChatMarkersManager(connection); + INSTANCES.put(connection, chatMarkersManager); + } + + return chatMarkersManager; + } + + private ChatMarkersManager(XMPPConnection connection) { + super(connection); + } + + /** + * Returns true if Chat Markers is supported by the server. + * + * @return true if Chat Markers is supported by the server. + * @throws NotConnectedException + * @throws XMPPErrorException + * @throws NoResponseException + * @throws InterruptedException + */ + public boolean isSupportedByServer() + throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + return ServiceDiscoveryManager.getInstanceFor(connection()) + .serverSupportsFeature(ChatMarkersElements.NAMESPACE); + } + +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/element/ChatMarkersElements.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/element/ChatMarkersElements.java new file mode 100644 index 0000000000..419c0e15bf --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/element/ChatMarkersElements.java @@ -0,0 +1,234 @@ +/** + * + * Copyright © 2016 Fernando Ramirez + * + * 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.chat_markers.element; + +import org.jivesoftware.smack.packet.ExtensionElement; +import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.util.XmlStringBuilder; + +/** + * Chat Markers elements (XEP-0333). + * + * @see XEP-0333: Chat + * Markers + * @author Fernando Ramirez + * + */ +public class ChatMarkersElements { + + public static final String NAMESPACE = "urn:xmpp:chat-markers:0"; + + /** + * Markable extension class. + * + * @see XEP-0333: Chat + * Markers + * @author Fernando Ramirez + * + */ + public static class MarkableExtension implements ExtensionElement { + + /** + * markable element. + */ + public static final String ELEMENT = "markable"; + + public MarkableExtension() { + } + + @Override + public String getElementName() { + return ELEMENT; + } + + @Override + public String getNamespace() { + return NAMESPACE; + } + + @Override + public CharSequence toXML() { + XmlStringBuilder xml = new XmlStringBuilder(this); + xml.closeEmptyElement(); + return xml; + } + + public static MarkableExtension from(Message message) { + return (MarkableExtension) message.getExtension(ELEMENT, NAMESPACE); + } + } + + /** + * Received extension class. + * + * @see XEP-0333: Chat + * Markers + * @author Fernando Ramirez + * + */ + public static class ReceivedExtension implements ExtensionElement { + + /** + * received element. + */ + public static final String ELEMENT = "received"; + + private String id; + + public ReceivedExtension(String id) { + this.id = id; + } + + /** + * Get the id. + * + * @return the id + */ + public String getId() { + return id; + } + + @Override + public String getElementName() { + return ELEMENT; + } + + @Override + public String getNamespace() { + return NAMESPACE; + } + + @Override + public CharSequence toXML() { + XmlStringBuilder xml = new XmlStringBuilder(this); + xml.attribute("id", id); + xml.closeEmptyElement(); + return xml; + } + + public static ReceivedExtension from(Message message) { + return (ReceivedExtension) message.getExtension(ELEMENT, NAMESPACE); + } + } + + /** + * Displayed extension class. + * + * @see XEP-0333: Chat + * Markers + * @author Fernando Ramirez + * + */ + public static class DisplayedExtension implements ExtensionElement { + + /** + * displayed element. + */ + public static final String ELEMENT = "displayed"; + + private String id; + + public DisplayedExtension(String id) { + this.id = id; + } + + /** + * Get the id. + * + * @return the id + */ + public String getId() { + return id; + } + + @Override + public String getElementName() { + return ELEMENT; + } + + @Override + public String getNamespace() { + return NAMESPACE; + } + + @Override + public CharSequence toXML() { + XmlStringBuilder xml = new XmlStringBuilder(this); + xml.attribute("id", id); + xml.closeEmptyElement(); + return xml; + } + + public static DisplayedExtension from(Message message) { + return (DisplayedExtension) message.getExtension(ELEMENT, NAMESPACE); + } + } + + /** + * Acknowledged extension class. + * + * @see XEP-0333: Chat + * Markers + * @author Fernando Ramirez + * + */ + public static class AcknowledgedExtension implements ExtensionElement { + + /** + * acknowledged element. + */ + public static final String ELEMENT = "acknowledged"; + + private String id; + + public AcknowledgedExtension(String id) { + this.id = id; + } + + /** + * Get the id. + * + * @return the id + */ + public String getId() { + return id; + } + + @Override + public String getElementName() { + return ELEMENT; + } + + @Override + public String getNamespace() { + return NAMESPACE; + } + + @Override + public CharSequence toXML() { + XmlStringBuilder xml = new XmlStringBuilder(this); + xml.attribute("id", id); + xml.closeEmptyElement(); + return xml; + } + + public static AcknowledgedExtension from(Message message) { + return (AcknowledgedExtension) message.getExtension(ELEMENT, NAMESPACE); + } + } + +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/element/package-info.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/element/package-info.java new file mode 100644 index 0000000000..6a919f016d --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/element/package-info.java @@ -0,0 +1,24 @@ +/** + * + * Copyright © 2016 Fernando Ramirez + * + * 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. + */ +/** + * Chat Markers elements (XEP-0333). + * + * @see XEP-0333: Chat + * Markers + * + */ +package org.jivesoftware.smackx.chat_markers.element; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/package-info.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/package-info.java new file mode 100644 index 0000000000..72fb0c8e57 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/package-info.java @@ -0,0 +1,24 @@ +/** + * + * Copyright © 2016 Fernando Ramirez + * + * 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. + */ +/** + * XEP-0333: Chat Markers. + * + * @see XEP-0333: Chat + * Markers + * + */ +package org.jivesoftware.smackx.chat_markers; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/AcknowledgedProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/AcknowledgedProvider.java new file mode 100644 index 0000000000..b4ca97d5d3 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/AcknowledgedProvider.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2016 Fernando Ramirez + * + * 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.chat_markers.provider; + +import org.jivesoftware.smack.provider.ExtensionElementProvider; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.AcknowledgedExtension; +import org.xmlpull.v1.XmlPullParser; + +/** + * Acknowledged extension provider class (XEP-0333). + * + * @see XEP-0333: Chat + * Markers + * @author Fernando Ramirez + * + */ +public class AcknowledgedProvider extends ExtensionElementProvider { + + @Override + public AcknowledgedExtension parse(XmlPullParser parser, int initialDepth) throws Exception { + String id = parser.getAttributeValue("", "id"); + return new AcknowledgedExtension(id); + } + +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/DisplayedProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/DisplayedProvider.java new file mode 100644 index 0000000000..340bd3e82f --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/DisplayedProvider.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2016 Fernando Ramirez + * + * 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.chat_markers.provider; + +import org.jivesoftware.smack.provider.ExtensionElementProvider; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.DisplayedExtension; +import org.xmlpull.v1.XmlPullParser; + +/** + * Displayed extension provider class (XEP-0333). + * + * @see XEP-0333: Chat + * Markers + * @author Fernando Ramirez + * + */ +public class DisplayedProvider extends ExtensionElementProvider { + + @Override + public DisplayedExtension parse(XmlPullParser parser, int initialDepth) throws Exception { + String id = parser.getAttributeValue("", "id"); + return new DisplayedExtension(id); + } + +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/MarkableProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/MarkableProvider.java new file mode 100644 index 0000000000..452d54d38b --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/MarkableProvider.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2016 Fernando Ramirez + * + * 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.chat_markers.provider; + +import org.jivesoftware.smack.provider.ExtensionElementProvider; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.MarkableExtension; +import org.xmlpull.v1.XmlPullParser; + +/** + * Markable extension provider class (XEP-0333). + * + * @see XEP-0333: Chat + * Markers + * @author Fernando Ramirez + * + */ +public class MarkableProvider extends ExtensionElementProvider { + + @Override + public MarkableExtension parse(XmlPullParser parser, int initialDepth) throws Exception { + return new MarkableExtension(); + } + +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/ReceivedProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/ReceivedProvider.java new file mode 100644 index 0000000000..4e06766066 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/ReceivedProvider.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2016 Fernando Ramirez + * + * 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.chat_markers.provider; + +import org.jivesoftware.smack.provider.ExtensionElementProvider; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.ReceivedExtension; +import org.xmlpull.v1.XmlPullParser; + +/** + * Received extension provider class (XEP-0333). + * + * @see XEP-0333: Chat + * Markers + * @author Fernando Ramirez + * + */ +public class ReceivedProvider extends ExtensionElementProvider { + + @Override + public ReceivedExtension parse(XmlPullParser parser, int initialDepth) throws Exception { + String id = parser.getAttributeValue("", "id"); + return new ReceivedExtension(id); + } + +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/package-info.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/package-info.java new file mode 100644 index 0000000000..10ecdf320c --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/provider/package-info.java @@ -0,0 +1,24 @@ +/** + * + * Copyright © 2016 Fernando Ramirez + * + * 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. + */ +/** + * Chat Markers providers (XEP-0333). + * + * @see XEP-0333: Chat + * Markers + * + */ +package org.jivesoftware.smackx.chat_markers.provider; diff --git a/smack-experimental/src/main/resources/org.jivesoftware.smack.experimental/experimental.providers b/smack-experimental/src/main/resources/org.jivesoftware.smack.experimental/experimental.providers index 9d70664998..b365474798 100644 --- a/smack-experimental/src/main/resources/org.jivesoftware.smack.experimental/experimental.providers +++ b/smack-experimental/src/main/resources/org.jivesoftware.smack.experimental/experimental.providers @@ -167,4 +167,26 @@ org.jivesoftware.smackx.iot.control.provider.IoTSetResponseProvider + + + markable + urn:xmpp:chat-markers:0 + org.jivesoftware.smackx.chat_markers.provider.MarkableProvider + + + received + urn:xmpp:chat-markers:0 + org.jivesoftware.smackx.chat_markers.provider.ReceivedProvider + + + displayed + urn:xmpp:chat-markers:0 + org.jivesoftware.smackx.chat_markers.provider.DisplayedProvider + + + acknowledged + urn:xmpp:chat-markers:0 + org.jivesoftware.smackx.chat_markers.provider.AcknowledgedProvider + + diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/AcknowledgedExtensionTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/AcknowledgedExtensionTest.java new file mode 100644 index 0000000000..20546ca029 --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/AcknowledgedExtensionTest.java @@ -0,0 +1,55 @@ +/** + * + * Copyright © 2016 Fernando Ramirez + * + * 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.chat_markers; + +import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.util.PacketParserUtils; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.AcknowledgedExtension; +import org.jivesoftware.smackx.chat_markers.provider.AcknowledgedProvider; +import org.junit.Assert; +import org.junit.Test; +import org.jxmpp.jid.impl.JidCreate; +import org.xmlpull.v1.XmlPullParser; + +public class AcknowledgedExtensionTest { + + String acknowledgedMessageStanza = "" + + "" + ""; + + String acknowledgedExtension = ""; + + @Test + public void checkDisplayedExtension() throws Exception { + Message message = new Message(JidCreate.from("northumberland@shakespeare.lit/westminster")); + message.setStanzaId("message-2"); + message.addExtension(new ChatMarkersElements.AcknowledgedExtension("message-1")); + Assert.assertEquals(acknowledgedMessageStanza, message.toXML().toString()); + } + + @Test + public void checkDisplayedProvider() throws Exception { + XmlPullParser parser = PacketParserUtils.getParserFor(acknowledgedExtension); + AcknowledgedExtension acknowledgedExtension1 = new AcknowledgedProvider().parse(parser); + Assert.assertEquals("message-1", acknowledgedExtension1.getId()); + + Message message = (Message) PacketParserUtils.parseStanza(acknowledgedMessageStanza); + AcknowledgedExtension acknowledgedExtension2 = AcknowledgedExtension.from(message); + Assert.assertEquals("message-1", acknowledgedExtension2.getId()); + } + +} diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/DisplayedExtensionTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/DisplayedExtensionTest.java new file mode 100644 index 0000000000..7bd146400c --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/DisplayedExtensionTest.java @@ -0,0 +1,55 @@ +/** + * + * Copyright © 2016 Fernando Ramirez + * + * 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.chat_markers; + +import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.util.PacketParserUtils; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.DisplayedExtension; +import org.jivesoftware.smackx.chat_markers.provider.DisplayedProvider; +import org.junit.Assert; +import org.junit.Test; +import org.jxmpp.jid.impl.JidCreate; +import org.xmlpull.v1.XmlPullParser; + +public class DisplayedExtensionTest { + + String displayedMessageStanza = "" + + "" + ""; + + String displayedExtension = ""; + + @Test + public void checkDisplayedExtension() throws Exception { + Message message = new Message(JidCreate.from("northumberland@shakespeare.lit/westminster")); + message.setStanzaId("message-2"); + message.addExtension(new ChatMarkersElements.DisplayedExtension("message-1")); + Assert.assertEquals(displayedMessageStanza, message.toXML().toString()); + } + + @Test + public void checkDisplayedProvider() throws Exception { + XmlPullParser parser = PacketParserUtils.getParserFor(displayedExtension); + DisplayedExtension displayedExtension1 = new DisplayedProvider().parse(parser); + Assert.assertEquals("message-1", displayedExtension1.getId()); + + Message message = (Message) PacketParserUtils.parseStanza(displayedMessageStanza); + DisplayedExtension displayedExtension2 = DisplayedExtension.from(message); + Assert.assertEquals("message-1", displayedExtension2.getId()); + } + +} diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/MarkableExtensionTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/MarkableExtensionTest.java new file mode 100644 index 0000000000..a595a21f51 --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/MarkableExtensionTest.java @@ -0,0 +1,57 @@ +/** + * + * Copyright © 2016 Fernando Ramirez + * + * 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.chat_markers; + +import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.util.PacketParserUtils; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.MarkableExtension; +import org.jivesoftware.smackx.chat_markers.provider.MarkableProvider; +import org.junit.Assert; +import org.junit.Test; +import org.jxmpp.jid.impl.JidCreate; +import org.xmlpull.v1.XmlPullParser; + +public class MarkableExtensionTest { + + String markableMessageStanza = "" + + "My lord, dispatch; read o'er these articles." + + "" + ""; + + String markableExtension = ""; + + @Test + public void checkMarkableExtension() throws Exception { + Message message = new Message(JidCreate.from("ingrichard@royalty.england.lit/throne")); + message.setStanzaId("message-1"); + message.setBody("My lord, dispatch; read o'er these articles."); + message.addExtension(new ChatMarkersElements.MarkableExtension()); + Assert.assertEquals(markableMessageStanza, message.toXML().toString()); + } + + @Test + public void checkMarkableProvider() throws Exception { + XmlPullParser parser = PacketParserUtils.getParserFor(markableExtension); + MarkableExtension markableExtension1 = new MarkableProvider().parse(parser); + Assert.assertEquals(markableExtension, markableExtension1.toXML().toString()); + + Message message = (Message) PacketParserUtils.parseStanza(markableMessageStanza); + MarkableExtension markableExtension2 = MarkableExtension.from(message); + Assert.assertEquals(markableExtension, markableExtension2.toXML().toString()); + } + +} diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/ReceivedExtensionTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/ReceivedExtensionTest.java new file mode 100644 index 0000000000..ffdadec3df --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/chat_markers/ReceivedExtensionTest.java @@ -0,0 +1,55 @@ +/** + * + * Copyright © 2016 Fernando Ramirez + * + * 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.chat_markers; + +import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.util.PacketParserUtils; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements; +import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.ReceivedExtension; +import org.jivesoftware.smackx.chat_markers.provider.ReceivedProvider; +import org.junit.Assert; +import org.junit.Test; +import org.jxmpp.jid.impl.JidCreate; +import org.xmlpull.v1.XmlPullParser; + +public class ReceivedExtensionTest { + + String receivedMessageStanza = "" + + "" + ""; + + String receivedExtension = ""; + + @Test + public void checkReceivedExtension() throws Exception { + Message message = new Message(JidCreate.from("northumberland@shakespeare.lit/westminster")); + message.setStanzaId("message-2"); + message.addExtension(new ChatMarkersElements.ReceivedExtension("message-1")); + Assert.assertEquals(receivedMessageStanza, message.toXML().toString()); + } + + @Test + public void checkReceivedProvider() throws Exception { + XmlPullParser parser = PacketParserUtils.getParserFor(receivedExtension); + ReceivedExtension receivedExtension1 = new ReceivedProvider().parse(parser); + Assert.assertEquals("message-1", receivedExtension1.getId()); + + Message message = (Message) PacketParserUtils.parseStanza(receivedMessageStanza); + ReceivedExtension receivedExtension2 = ReceivedExtension.from(message); + Assert.assertEquals("message-1", receivedExtension2.getId()); + } + +}