summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2011-11-11 15:01:32 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-11-28 16:44:22 (GMT)
commit86aad702d1f2e831c8e27bbe4ca1402626e4c542 (patch)
tree3be5a8ed23aef3877c9b313d0ee0f58afb54f57a /Swiften/Serializer
parent81a7776d5ab523894a7c4745baee3988ad9f1ef9 (diff)
downloadswift-contrib-86aad702d1f2e831c8e27bbe4ca1402626e4c542.zip
swift-contrib-86aad702d1f2e831c8e27bbe4ca1402626e4c542.tar.bz2
Message Receipts (XEP-0184) support for 1-to-1 conversations (including 1-to-1 MUC).
Warn icon from already existing theme. Check icon from Wikipedia. See Swift/resources/icons/license_info.txt for details. License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.cpp22
-rw-r--r--Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h19
-rw-r--r--Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.cpp21
-rw-r--r--Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h19
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp4
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp45
6 files changed, 130 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.cpp b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.cpp
new file mode 100644
index 0000000..eeb0d90
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.cpp
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
+
+#include <Swiften/Base/Log.h>
+
+namespace Swift {
+
+DeliveryReceiptRequestSerializer::DeliveryReceiptRequestSerializer() : GenericPayloadSerializer<DeliveryReceiptRequest>() {
+}
+
+std::string DeliveryReceiptRequestSerializer::serializePayload(boost::shared_ptr<DeliveryReceiptRequest> /* request*/) const {
+ XMLElement requestXML("request", "urn:xmpp:receipts");
+ return requestXML.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h
new file mode 100644
index 0000000..aa3c315
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+#include <Swiften/Elements/DeliveryReceiptRequest.h>
+
+namespace Swift {
+ class DeliveryReceiptRequestSerializer : public GenericPayloadSerializer<DeliveryReceiptRequest> {
+ public:
+ DeliveryReceiptRequestSerializer();
+
+ virtual std::string serializePayload(boost::shared_ptr<DeliveryReceiptRequest> request) const;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.cpp b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.cpp
new file mode 100644
index 0000000..a9033b2
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
+
+namespace Swift {
+
+DeliveryReceiptSerializer::DeliveryReceiptSerializer() : GenericPayloadSerializer<DeliveryReceipt>() {
+}
+
+std::string DeliveryReceiptSerializer::serializePayload(boost::shared_ptr<DeliveryReceipt> receipt) const {
+ XMLElement received("received", "urn:xmpp:receipts");
+ received.setAttribute("id", receipt->getReceivedID());
+ return received.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h
new file mode 100644
index 0000000..5fda3ea
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+#include <Swiften/Elements/DeliveryReceipt.h>
+
+namespace Swift {
+ class DeliveryReceiptSerializer : public GenericPayloadSerializer<DeliveryReceipt> {
+ public:
+ DeliveryReceiptSerializer();
+
+ virtual std::string serializePayload(boost::shared_ptr<DeliveryReceipt> receipt) const;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index 87dfbc3..499a185 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -60,6 +60,8 @@
#include <Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/S5BProxyRequestSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h>
namespace Swift {
@@ -116,6 +118,8 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new JingleS5BTransportPayloadSerializer());
serializers_.push_back(new JinglePayloadSerializer(this));
serializers_.push_back(new S5BProxyRequestSerializer());
+ serializers_.push_back(new DeliveryReceiptSerializer());
+ serializers_.push_back(new DeliveryReceiptRequestSerializer());
foreach(PayloadSerializer* serializer, serializers_) {
addSerializer(serializer);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp
new file mode 100644
index 0000000..9282db4
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <boost/shared_ptr.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h>
+
+using namespace Swift;
+
+class DeliveryReceiptSerializerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(DeliveryReceiptSerializerTest);
+ CPPUNIT_TEST(testSerialize_XEP0184Example3);
+ CPPUNIT_TEST(testSerialize_XEP0184Example4);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testSerialize_XEP0184Example3() {
+ std::string expected = "<request xmlns=\"urn:xmpp:receipts\"/>";
+
+ DeliveryReceiptRequest::ref receipt = boost::make_shared<DeliveryReceiptRequest>();
+
+ boost::shared_ptr<DeliveryReceiptRequestSerializer> serializer = boost::make_shared<DeliveryReceiptRequestSerializer>();
+ CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(receipt));
+ }
+
+ void testSerialize_XEP0184Example4() {
+ std::string expected = "<received id=\"richard2-4.1.247\" xmlns=\"urn:xmpp:receipts\"/>";
+
+ DeliveryReceipt::ref receipt = boost::make_shared<DeliveryReceipt>("richard2-4.1.247");
+
+ boost::shared_ptr<DeliveryReceiptSerializer> serializer = boost::make_shared<DeliveryReceiptSerializer>();
+ CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(receipt));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(DeliveryReceiptSerializerTest);
+