diff options
6 files changed, 40 insertions, 0 deletions
diff --git a/Sluift/ElementConvertors/ResultSetConvertor.cpp b/Sluift/ElementConvertors/ResultSetConvertor.cpp index a4ebbf1..bd517b3 100644 --- a/Sluift/ElementConvertors/ResultSetConvertor.cpp +++ b/Sluift/ElementConvertors/ResultSetConvertor.cpp @@ -54,4 +54,9 @@ boost::shared_ptr<ResultSet> ResultSetConvertor::doConvertFromLua(lua_State* L) } lua_pop(L, 1); + lua_getfield(L, -1, "before"); + if (lua_isstring(L, -1)) { + result->setBefore(std::string(lua_tostring(L, -1))); + } + lua_pop(L, 1); return result; } @@ -83,4 +88,8 @@ void ResultSetConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<ResultSe lua_setfield(L, -2, "after"); } + if (payload->getBefore()) { + lua_pushstring(L, (*payload->getBefore()).c_str()); + lua_setfield(L, -2, "before"); + } } diff --git a/Swiften/Elements/ResultSet.h b/Swiften/Elements/ResultSet.h index 871b699..e84be35 100644 --- a/Swiften/Elements/ResultSet.h +++ b/Swiften/Elements/ResultSet.h @@ -31,4 +31,7 @@ namespace Swift { const boost::optional<std::string>& getLastID() const { return lastID_; } + void setBefore(const boost::optional<std::string>& before) { before_ = before; } + const boost::optional<std::string>& getBefore() const { return before_; } + void setAfter(const boost::optional<std::string>& after) { after_ = after; } const boost::optional<std::string>& getAfter() const { return after_; } @@ -40,4 +43,5 @@ namespace Swift { boost::optional<std::string> firstID_; boost::optional<std::string> lastID_; + boost::optional<std::string> before_; boost::optional<std::string> after_; }; diff --git a/Swiften/Parser/PayloadParsers/ResultSetParser.cpp b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp index 95960d7..4c8283b 100644 --- a/Swiften/Parser/PayloadParsers/ResultSetParser.cpp +++ b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp @@ -48,4 +48,6 @@ void ResultSetParser::handleEndElement(const std::string& element, const std::st } else if (element == "last") { getPayloadInternal()->setLastID(currentText_); + } else if (element == "before") { + getPayloadInternal()->setBefore(currentText_); } else if (element == "after") { getPayloadInternal()->setAfter(currentText_); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp index 68df71b..e345323 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp @@ -29,4 +29,5 @@ class ResultSetParserTest : public CppUnit::TestFixture "<first index=\"123\">stpeter@jabber.org</first>" "<last>peterpan@neverland.lit</last>" + "<before>decaf-badba-dbad1</before>" "<after>09af3-cc343-b409f</after>" "</set>")); @@ -44,4 +45,6 @@ class ResultSetParserTest : public CppUnit::TestFixture CPPUNIT_ASSERT(payload->getLastID()); CPPUNIT_ASSERT_EQUAL(std::string("peterpan@neverland.lit"), *payload->getLastID()); + CPPUNIT_ASSERT(payload->getBefore()); + CPPUNIT_ASSERT_EQUAL(std::string("decaf-badba-dbad1"), *payload->getBefore()); CPPUNIT_ASSERT(payload->getAfter()); CPPUNIT_ASSERT_EQUAL(std::string("09af3-cc343-b409f"), *payload->getAfter()); diff --git a/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp index 86d8830..0f464a4 100644 --- a/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp @@ -46,4 +46,8 @@ std::string ResultSetSerializer::serializePayload(boost::shared_ptr<ResultSet> p } + if (payload->getBefore()) { + element.addNode(boost::make_shared<XMLElement>("before", "", *payload->getBefore())); + } + if (payload->getAfter()) { element.addNode(boost::make_shared<XMLElement>("after", "", *payload->getAfter())); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp index 641b856..354db85 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp @@ -20,4 +20,5 @@ class ResultSetSerializerTest : public CppUnit::TestFixture { CPPUNIT_TEST(testSerializeFull); CPPUNIT_TEST(testSerializeMaxItems); + CPPUNIT_TEST(testSerializeEmptyBefore); CPPUNIT_TEST(testSerializeFirst); CPPUNIT_TEST(testSerializeFirstWithIndex); @@ -36,4 +37,5 @@ class ResultSetSerializerTest : public CppUnit::TestFixture { resultSet->setLastID(std::string("peterpan@neverland.lit")); resultSet->setAfter(std::string("09af3-cc343-b409f")); + resultSet->setBefore(std::string("decaf-badba-dbad1")); std::string expectedResult = @@ -43,4 +45,5 @@ class ResultSetSerializerTest : public CppUnit::TestFixture { "<first index=\"123\">stpeter@jabber.org</first>" "<last>peterpan@neverland.lit</last>" + "<before>decaf-badba-dbad1</before>" "<after>09af3-cc343-b409f</after>" "</set>"; @@ -64,4 +67,19 @@ class ResultSetSerializerTest : public CppUnit::TestFixture { } + void testSerializeEmptyBefore() { + ResultSetSerializer serializer; + + boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>()); + + resultSet->setBefore(std::string()); + + std::string expectedResult = + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<before/>" + "</set>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); + } + void testSerializeFirst() { ResultSetSerializer serializer; |