summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2013-02-25 23:20:59 (GMT)
committerSwift Review <review@swift.im>2013-03-04 15:18:47 (GMT)
commit836925a5cdc7017da7fb84416c803e652b48e399 (patch)
tree2f659c2bc3e6db70cbc09e0cb13953c1a8ccd8e4 /Swiften/Serializer
parentffbd6feb875a9d50ec834fd6dfe967528697a9ff (diff)
downloadswift-836925a5cdc7017da7fb84416c803e652b48e399.zip
swift-836925a5cdc7017da7fb84416c803e652b48e399.tar.bz2
Adding support for idle time.
Change-Id: I1b14edb97a0c87431ec377b084362e9761caded9 License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/IdleSerializer.h22
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/IdleSerializerTest.cpp32
3 files changed, 56 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index b4822cd..3f45a7c 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -51,6 +51,7 @@
#include <Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/LastSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/IdleSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.h>
@@ -110,6 +111,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new ReplaceSerializer());
serializers_.push_back(new LastSerializer());
serializers_.push_back(new WhiteboardSerializer());
+ serializers_.push_back(new IdleSerializer());
serializers_.push_back(new StreamInitiationFileInfoSerializer());
serializers_.push_back(new JingleContentPayloadSerializer());
diff --git a/Swiften/Serializer/PayloadSerializers/IdleSerializer.h b/Swiften/Serializer/PayloadSerializers/IdleSerializer.h
new file mode 100644
index 0000000..45f9da4
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/IdleSerializer.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+#include <Swiften/Elements/Idle.h>
+#include <Swiften/Base/DateTime.h>
+
+namespace Swift {
+ class IdleSerializer : public GenericPayloadSerializer<Idle> {
+ public:
+ IdleSerializer() : GenericPayloadSerializer<Idle>() {}
+
+ virtual std::string serializePayload(boost::shared_ptr<Idle> idle) const {
+ return "<idle xmlns='urn:xmpp:idle:1' since='" + dateTimeToString(idle->getSince()) + "'/>";
+ }
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/IdleSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/IdleSerializerTest.cpp
new file mode 100644
index 0000000..9700869
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/IdleSerializerTest.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <boost/make_shared.hpp>
+
+#include <Swiften/Serializer/PayloadSerializers/IdleSerializer.h>
+
+using namespace Swift;
+
+class IdleSerializerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(IdleSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ IdleSerializerTest() {}
+
+ void testSerialize() {
+ IdleSerializer testling;
+ Idle::ref idle = boost::make_shared<Idle>(stringToDateTime("1969-07-21T02:56:15Z"));
+
+ CPPUNIT_ASSERT_EQUAL(std::string("<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z'/>"), testling.serialize(idle));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(IdleSerializerTest);