summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-06-06 10:33:34 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-06-06 11:03:11 (GMT)
commitbabda920a6c6efdd6464093b55c7ff752181a63b (patch)
tree0333cc2a4cc4e97354c6f208c690eb8076fb9ad0
parent4fbd449f8ec45eb4cc3f5fcd51630caf102145af (diff)
downloadswift-contrib-babda920a6c6efdd6464093b55c7ff752181a63b.zip
swift-contrib-babda920a6c6efdd6464093b55c7ff752181a63b.tar.bz2
Use delay when printing MUC history.
Resolves: #415
-rw-r--r--Swift/Controllers/Chat/ChatController.cpp5
-rw-r--r--Swift/Controllers/Chat/ChatController.h1
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.cpp15
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.h5
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp4
-rw-r--r--Swift/Controllers/Chat/MUCController.h1
-rw-r--r--Swift/Controllers/UIInterfaces/ChatWindow.h5
-rw-r--r--Swift/Controllers/UnitTest/MockChatWindow.h6
-rw-r--r--Swift/QtUI/QtChatWindow.cpp12
-rw-r--r--Swift/QtUI/QtChatWindow.h6
-rw-r--r--Swift/QtUI/QtSwiftUtil.h4
-rw-r--r--Swiften/Elements/Delay.h2
-rw-r--r--Swiften/Elements/Stanza.cpp16
-rw-r--r--Swiften/Elements/Stanza.h12
-rw-r--r--Swiften/Elements/UnitTest/StanzaTest.cpp57
15 files changed, 123 insertions, 28 deletions
diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp
index 2e1b1c8..7b52fba 100644
--- a/Swift/Controllers/Chat/ChatController.cpp
+++ b/Swift/Controllers/Chat/ChatController.cpp
@@ -70,7 +70,7 @@ void ChatController::preSendMessageRequest(boost::shared_ptr<Message> message) {
}
void ChatController::postSendMessage(const String& body) {
- addMessage(body, "me", true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel() : boost::optional<SecurityLabel>(), String(avatarManager_->getAvatarPath(selfJID_).string()));
+ addMessage(body, "me", true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel() : boost::optional<SecurityLabel>(), String(avatarManager_->getAvatarPath(selfJID_).string()), boost::posix_time::microsec_clock::universal_time());
chatStateNotifier_->userSentMessage();
}
@@ -107,5 +107,8 @@ void ChatController::handlePresenceChange(boost::shared_ptr<Presence> newPresenc
}
}
+boost::optional<boost::posix_time::ptime> ChatController::getMessageTimestamp(boost::shared_ptr<Message> message) const {
+ return message->getTimestamp();
+}
}
diff --git a/Swift/Controllers/Chat/ChatController.h b/Swift/Controllers/Chat/ChatController.h
index 7d2072d..26015a1 100644
--- a/Swift/Controllers/Chat/ChatController.h
+++ b/Swift/Controllers/Chat/ChatController.h
@@ -28,6 +28,7 @@ namespace Swift {
void preHandleIncomingMessage(boost::shared_ptr<Message> message);
void preSendMessageRequest(boost::shared_ptr<Message>);
String senderDisplayNameFromMessage(const JID& from);
+ virtual boost::optional<boost::posix_time::ptime> getMessageTimestamp(boost::shared_ptr<Message>) const;
private:
NickResolver* nickResolver_;
diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp
index d1452c7..adafff0 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.cpp
+++ b/Swift/Controllers/Chat/ChatControllerBase.cpp
@@ -105,11 +105,11 @@ void ChatControllerBase::activateChatWindow() {
chatWindow_->activate();
}
-void ChatControllerBase::addMessage(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath) {
+void ChatControllerBase::addMessage(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const boost::posix_time::ptime& time) {
if (message.beginsWith("/me ")) {
- chatWindow_->addAction(message.getSplittedAtFirst(' ').second, senderName, senderIsSelf, label, avatarPath);
+ chatWindow_->addAction(message.getSplittedAtFirst(' ').second, senderName, senderIsSelf, label, avatarPath, time);
} else {
- chatWindow_->addMessage(message, senderName, senderIsSelf, label, avatarPath);
+ chatWindow_->addMessage(message, senderName, senderIsSelf, label, avatarPath, time);
}
}
@@ -148,7 +148,14 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> m
}
boost::shared_ptr<SecurityLabel> label = message->getPayload<SecurityLabel>();
boost::optional<SecurityLabel> maybeLabel = label ? boost::optional<SecurityLabel>(*label) : boost::optional<SecurityLabel>();
- addMessage(body, senderDisplayNameFromMessage(from), isIncomingMessageFromMe(message), maybeLabel, String(avatarManager_->getAvatarPath(from).string()));
+
+ // TODO: determine the timestamp
+ boost::posix_time::ptime timeStamp = boost::posix_time::microsec_clock::universal_time();
+ boost::optional<boost::posix_time::ptime> messageTimeStamp = getMessageTimestamp(message);
+ if (messageTimeStamp) {
+ timeStamp = *messageTimeStamp;
+ }
+ addMessage(body, senderDisplayNameFromMessage(from), isIncomingMessageFromMe(message), maybeLabel, String(avatarManager_->getAvatarPath(from).string()), timeStamp);
}
}
diff --git a/Swift/Controllers/Chat/ChatControllerBase.h b/Swift/Controllers/Chat/ChatControllerBase.h
index e4d14af..b851857 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.h
+++ b/Swift/Controllers/Chat/ChatControllerBase.h
@@ -12,6 +12,8 @@
#include <boost/shared_ptr.hpp>
#include "Swiften/Base/boost_bsignals.h"
#include <boost/filesystem.hpp>
+#include <boost/optional.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
#include "Swiften/Base/String.h"
#include "Swiften/Elements/DiscoInfo.h"
@@ -37,7 +39,7 @@ namespace Swift {
void activateChatWindow();
void setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info);
void handleIncomingMessage(boost::shared_ptr<MessageEvent> message);
- void addMessage(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath);
+ void addMessage(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const boost::posix_time::ptime& time);
void setEnabled(bool enabled);
virtual void setToJID(const JID& jid) {toJID_ = jid;};
protected:
@@ -49,6 +51,7 @@ namespace Swift {
virtual void preHandleIncomingMessage(boost::shared_ptr<Message>) {};
virtual void preSendMessageRequest(boost::shared_ptr<Message>) {};
virtual bool isFromContact(const JID& from);
+ virtual boost::optional<boost::posix_time::ptime> getMessageTimestamp(boost::shared_ptr<Message>) const = 0;
private:
void handleSendMessageRequest(const String &body);
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index 65603d7..544043d 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -247,4 +247,8 @@ void MUCController::preSendMessageRequest(boost::shared_ptr<Message> message) {
message->setType(Swift::Message::Groupchat);
}
+boost::optional<boost::posix_time::ptime> MUCController::getMessageTimestamp(boost::shared_ptr<Message> message) const {
+ return message->getTimestampFrom(toJID_);
+}
+
}
diff --git a/Swift/Controllers/Chat/MUCController.h b/Swift/Controllers/Chat/MUCController.h
index a3c72e7..e93af1e 100644
--- a/Swift/Controllers/Chat/MUCController.h
+++ b/Swift/Controllers/Chat/MUCController.h
@@ -40,6 +40,7 @@ namespace Swift {
void preSendMessageRequest(boost::shared_ptr<Message> message);
bool isIncomingMessageFromMe(boost::shared_ptr<Message> message);
String senderDisplayNameFromMessage(const JID& from);
+ boost::optional<boost::posix_time::ptime> getMessageTimestamp(boost::shared_ptr<Message> message) const;
private:
void handleWindowClosed();
diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h
index 7e97f0c..50a0b39 100644
--- a/Swift/Controllers/UIInterfaces/ChatWindow.h
+++ b/Swift/Controllers/UIInterfaces/ChatWindow.h
@@ -10,6 +10,7 @@
#include <boost/optional.hpp>
#include "Swiften/Base/boost_bsignals.h"
#include <boost/shared_ptr.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
#include <vector>
#include "Swiften/Base/String.h"
@@ -27,8 +28,8 @@ namespace Swift {
ChatWindow() {}
virtual ~ChatWindow() {};
- virtual void addMessage(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath) = 0;
- virtual void addAction(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath) = 0;
+ virtual void addMessage(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const boost::posix_time::ptime& time) = 0;
+ virtual void addAction(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const boost::posix_time::ptime& time) = 0;
virtual void addSystemMessage(const String& message) = 0;
virtual void addErrorMessage(const String& message) = 0;
diff --git a/Swift/Controllers/UnitTest/MockChatWindow.h b/Swift/Controllers/UnitTest/MockChatWindow.h
index 78705ce..ff61bf6 100644
--- a/Swift/Controllers/UnitTest/MockChatWindow.h
+++ b/Swift/Controllers/UnitTest/MockChatWindow.h
@@ -14,8 +14,8 @@ namespace Swift {
MockChatWindow() {};
virtual ~MockChatWindow();
- virtual void addMessage(const String& message, const String& /*senderName*/, bool /*senderIsSelf*/, const boost::optional<SecurityLabel>& /*label*/, const String& /*avatarPath*/) {lastMessageBody_ = message;};
- virtual void addAction(const String& message, const String& /*senderName*/, bool /*senderIsSelf*/, const boost::optional<SecurityLabel>& /*label*/, const String& /*avatarPath*/) {lastMessageBody_ = message;};
+ virtual void addMessage(const String& message, const String& /*senderName*/, bool /*senderIsSelf*/, const boost::optional<SecurityLabel>& /*label*/, const String& /*avatarPath*/, const boost::posix_time::ptime&) {lastMessageBody_ = message;};
+ virtual void addAction(const String& message, const String& /*senderName*/, bool /*senderIsSelf*/, const boost::optional<SecurityLabel>& /*label*/, const String& /*avatarPath*/, const boost::posix_time::ptime&) {lastMessageBody_ = message;};
virtual void addSystemMessage(const String& /*message*/) {};
virtual void addErrorMessage(const String& /*message*/) {};
@@ -31,7 +31,7 @@ namespace Swift {
virtual SecurityLabel getSelectedSecurityLabel() {return SecurityLabel();};
virtual void setInputEnabled(bool /*enabled*/) {};
virtual void setRosterModel(Roster* /*roster*/) {};
- virtual void setTabComplete(TabComplete* complete) {};
+ virtual void setTabComplete(TabComplete*) {};
boost::signal<void ()> onClosed;
boost::signal<void ()> onAllMessagesRead;
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 6f49082..d5cadf4 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -224,11 +224,11 @@ void QtChatWindow::updateTitleWithUnreadCount() {
emit titleUpdated();
}
-void QtChatWindow::addMessage(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath) {
- addMessage(message, senderName, senderIsSelf, label, avatarPath, "");
+void QtChatWindow::addMessage(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const boost::posix_time::ptime& time) {
+ addMessage(message, senderName, senderIsSelf, label, avatarPath, "", time);
}
-void QtChatWindow::addMessage(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const QString& style) {
+void QtChatWindow::addMessage(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const QString& style, const boost::posix_time::ptime& time) {
if (isWidgetSelected()) {
onAllMessagesRead();
}
@@ -247,15 +247,15 @@ void QtChatWindow::addMessage(const String &message, const String &senderName, b
bool appendToPrevious = !previousMessageWasSystem_ && ((senderIsSelf && previousMessageWasSelf_) || (!senderIsSelf && !previousMessageWasSelf_ && previousSenderName_ == P2QSTRING(senderName)));
QString qAvatarPath = avatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(P2QSTRING(avatarPath)).toEncoded();
- messageLog_->addMessage(MessageSnippet(htmlString, Qt::escape(P2QSTRING(senderName)), QDateTime::currentDateTime(), qAvatarPath, senderIsSelf, appendToPrevious));
+ messageLog_->addMessage(MessageSnippet(htmlString, Qt::escape(P2QSTRING(senderName)), B2QDATE(time), qAvatarPath, senderIsSelf, appendToPrevious));
previousMessageWasSelf_ = senderIsSelf;
previousSenderName_ = P2QSTRING(senderName);
previousMessageWasSystem_ = false;
}
-void QtChatWindow::addAction(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath) {
- addMessage(" *" + message + "*", senderName, senderIsSelf, label, avatarPath, "font-style:italic ");
+void QtChatWindow::addAction(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const boost::posix_time::ptime& time) {
+ addMessage(" *" + message + "*", senderName, senderIsSelf, label, avatarPath, "font-style:italic ", time);
}
void QtChatWindow::addErrorMessage(const String& errorMessage) {
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index ff2f1cb..44d79a1 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -27,8 +27,8 @@ namespace Swift {
public:
QtChatWindow(const QString &contact, UIEventStream* eventStream);
~QtChatWindow();
- void addMessage(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath);
- void addAction(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath);
+ void addMessage(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const boost::posix_time::ptime& time);
+ void addAction(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const boost::posix_time::ptime& time);
void addSystemMessage(const String& message);
void addErrorMessage(const String& errorMessage);
void show();
@@ -61,7 +61,7 @@ namespace Swift {
private:
void updateTitleWithUnreadCount();
void tabComplete();
- void addMessage(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const QString& style);
+ void addMessage(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const QString& style, const boost::posix_time::ptime& time);
int unreadCount_;
bool contactIsTyping_;
diff --git a/Swift/QtUI/QtSwiftUtil.h b/Swift/QtUI/QtSwiftUtil.h
index a2ad4db..3f1ad3b 100644
--- a/Swift/QtUI/QtSwiftUtil.h
+++ b/Swift/QtUI/QtSwiftUtil.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -10,4 +10,6 @@
#define P2QSTRING(a) QString::fromUtf8(a.getUTF8Data())
#define Q2PSTRING(a) Swift::String(a.toUtf8())
+#define B2QDATE(a) QDateTime::fromTime_t((a - boost::posix_time::from_time_t(0)).total_seconds())
+
#endif
diff --git a/Swiften/Elements/Delay.h b/Swiften/Elements/Delay.h
index f59d729..3213037 100644
--- a/Swiften/Elements/Delay.h
+++ b/Swiften/Elements/Delay.h
@@ -16,7 +16,7 @@ namespace Swift {
class Delay : public Payload {
public:
Delay() {};
- Delay(const boost::posix_time::ptime& time, const JID& from) : time_(time), from_(from) {};
+ Delay(const boost::posix_time::ptime& time, const JID& from = JID()) : time_(time), from_(from) {};
const boost::posix_time::ptime& getStamp() const {return time_;};
void setStamp(const boost::posix_time::ptime& time) {time_ = time;};
diff --git a/Swiften/Elements/Stanza.cpp b/Swiften/Elements/Stanza.cpp
index dd6021d..d15d778 100644
--- a/Swiften/Elements/Stanza.cpp
+++ b/Swiften/Elements/Stanza.cpp
@@ -5,6 +5,7 @@
*/
#include "Swiften/Elements/Stanza.h"
+#include "Swiften/Elements/Delay.h"
#include <typeinfo>
@@ -33,5 +34,20 @@ boost::shared_ptr<Payload> Stanza::getPayloadOfSameType(boost::shared_ptr<Payloa
return boost::shared_ptr<Payload>();
}
+boost::optional<boost::posix_time::ptime> Stanza::getTimestamp() const {
+ boost::shared_ptr<Delay> delay = getPayload<Delay>();
+ return delay ? delay->getStamp() : boost::optional<boost::posix_time::ptime>();
+}
+
+boost::optional<boost::posix_time::ptime> Stanza::getTimestampFrom(const JID& jid) const {
+ std::vector< boost::shared_ptr<Delay> > delays = getPayloads<Delay>();
+ for (size_t i = 0; i < delays.size(); ++i) {
+ if (delays[i]->getFrom() == jid) {
+ return delays[i]->getStamp();
+ }
+ }
+ return getTimestamp();
+}
+
}
diff --git a/Swiften/Elements/Stanza.h b/Swiften/Elements/Stanza.h
index f42048e..20fb557 100644
--- a/Swiften/Elements/Stanza.h
+++ b/Swiften/Elements/Stanza.h
@@ -4,11 +4,12 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_STANZAS_STANZA_H
-#define SWIFTEN_STANZAS_STANZA_H
+#pragma once
#include <vector>
#include <boost/shared_ptr.hpp>
+#include <boost/optional.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
#include "Swiften/Elements/Element.h"
#include "Swiften/Elements/Payload.h"
@@ -65,6 +66,11 @@ namespace Swift {
const String& getID() const { return id_; }
void setID(const String& id) { id_ = id; }
+
+ boost::optional<boost::posix_time::ptime> getTimestamp() const;
+
+ // Falls back to any timestamp if no specific timestamp for the given JID is found.
+ boost::optional<boost::posix_time::ptime> getTimestampFrom(const JID& jid) const;
private:
String id_;
@@ -75,5 +81,3 @@ namespace Swift {
Payloads payloads_;
};
}
-
-#endif
diff --git a/Swiften/Elements/UnitTest/StanzaTest.cpp b/Swiften/Elements/UnitTest/StanzaTest.cpp
index 1e7e9c4..15f8629 100644
--- a/Swiften/Elements/UnitTest/StanzaTest.cpp
+++ b/Swiften/Elements/UnitTest/StanzaTest.cpp
@@ -11,6 +11,7 @@
#include "Swiften/Elements/Stanza.h"
#include "Swiften/Elements/Payload.h"
#include "Swiften/Elements/Message.h"
+#include "Swiften/Elements/Delay.h"
using namespace Swift;
@@ -27,6 +28,11 @@ class StanzaTest : public CppUnit::TestFixture
CPPUNIT_TEST(testUpdatePayload_NewPayload);
CPPUNIT_TEST(testGetPayloadOfSameType);
CPPUNIT_TEST(testGetPayloadOfSameType_NoSuchPayload);
+ CPPUNIT_TEST(testGetTimestamp);
+ CPPUNIT_TEST(testGetTimestamp_TimestampWithFrom);
+ CPPUNIT_TEST(testGetTimestamp_NoDelay);
+ CPPUNIT_TEST(testGetTimestampFrom);
+ CPPUNIT_TEST(testGetTimestampFrom_Fallsback);
CPPUNIT_TEST_SUITE_END();
public:
@@ -60,8 +66,6 @@ class StanzaTest : public CppUnit::TestFixture
bool* alive_;
};
- StanzaTest() {}
-
void testConstructor_Copy() {
Message m;
m.addPayload(boost::shared_ptr<MyPayload1>(new MyPayload1()));
@@ -172,6 +176,55 @@ class StanzaTest : public CppUnit::TestFixture
CPPUNIT_ASSERT(!m.getPayloadOfSameType(boost::shared_ptr<MyPayload2>(new MyPayload2("bar"))));
}
+
+ void testGetTimestamp() {
+ Message m;
+ m.addPayload(boost::shared_ptr<Delay>(new Delay(boost::posix_time::from_time_t(1))));
+
+ boost::optional<boost::posix_time::ptime> timestamp = m.getTimestamp();
+
+ CPPUNIT_ASSERT(timestamp);
+ CPPUNIT_ASSERT_EQUAL(std::string("1970-Jan-01 00:00:01"), boost::posix_time::to_simple_string(*timestamp));
+ }
+
+ void testGetTimestamp_TimestampWithFrom() {
+ Message m;
+ m.addPayload(boost::shared_ptr<Delay>(new Delay(boost::posix_time::from_time_t(1), JID("foo@bar.com"))));
+
+ boost::optional<boost::posix_time::ptime> timestamp = m.getTimestamp();
+
+ CPPUNIT_ASSERT(timestamp);
+ CPPUNIT_ASSERT_EQUAL(std::string("1970-Jan-01 00:00:01"), boost::posix_time::to_simple_string(*timestamp));
+ }
+
+ void testGetTimestamp_NoDelay() {
+ Message m;
+ CPPUNIT_ASSERT(!m.getTimestamp());
+ }
+
+ void testGetTimestampFrom() {
+ Message m;
+ m.addPayload(boost::shared_ptr<Delay>(new Delay(boost::posix_time::from_time_t(0))));
+ m.addPayload(boost::shared_ptr<Delay>(new Delay(boost::posix_time::from_time_t(1), JID("foo1@bar.com"))));
+ m.addPayload(boost::shared_ptr<Delay>(new Delay(boost::posix_time::from_time_t(2), JID("foo2@bar.com"))));
+ m.addPayload(boost::shared_ptr<Delay>(new Delay(boost::posix_time::from_time_t(3), JID("foo3@bar.com"))));
+
+ boost::optional<boost::posix_time::ptime> timestamp = m.getTimestampFrom(JID("foo2@bar.com"));
+
+ CPPUNIT_ASSERT(timestamp);
+ CPPUNIT_ASSERT_EQUAL(std::string("1970-Jan-01 00:00:02"), boost::posix_time::to_simple_string(*timestamp));
+ }
+
+ void testGetTimestampFrom_Fallsback() {
+ Message m;
+ m.addPayload(boost::shared_ptr<Delay>(new Delay(boost::posix_time::from_time_t(1), JID("foo1@bar.com"))));
+ m.addPayload(boost::shared_ptr<Delay>(new Delay(boost::posix_time::from_time_t(3), JID("foo3@bar.com"))));
+
+ boost::optional<boost::posix_time::ptime> timestamp = m.getTimestampFrom(JID("foo2@bar.com"));
+
+ CPPUNIT_ASSERT(timestamp);
+ CPPUNIT_ASSERT_EQUAL(std::string("1970-Jan-01 00:00:01"), boost::posix_time::to_simple_string(*timestamp));
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(StanzaTest);