summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-04-20 09:43:31 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-04-23 10:52:55 (GMT)
commit6bd72c67896a20041556519548650590553f47c9 (patch)
tree20f6a3895647ad67adfe29ef688a618bf7c30a6a /Swift
parentbfe07e82cd79d56f1327425ce3e6c8a84908421b (diff)
downloadswift-contrib-6bd72c67896a20041556519548650590553f47c9.zip
swift-contrib-6bd72c67896a20041556519548650590553f47c9.tar.bz2
Add XEP-0203 (Delay) support.
Puts delay warnings in the chat log. Not optional yet.
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp
index 793233e..abd346a 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.cpp
+++ b/Swift/Controllers/Chat/ChatControllerBase.cpp
@@ -6,10 +6,14 @@
#include "Swift/Controllers/Chat/ChatControllerBase.h"
+#include <sstream>
+
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
#include "Swiften/Client/StanzaChannel.h"
+#include "Swiften/Elements/Delay.h"
#include "Swiften/Base/foreach.h"
#include "Swift/Controllers/UIInterfaces/ChatWindow.h"
#include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h"
@@ -69,6 +73,12 @@ void ChatControllerBase::handleSendMessageRequest(const String &body) {
label = boost::optional<SecurityLabel>(chatWindow_->getSelectedSecurityLabel());
}
preSendMessageRequest(message);
+ //FIXME: optional
+ bool useSwiftDelay = true;
+ if (useSwiftDelay) {
+ boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
+ message->addPayload(boost::shared_ptr<Delay>(new Delay(now, selfJID_)));
+ }
stanzaChannel_->sendMessage(message);
postSendMessage(message->getBody());
}
@@ -121,6 +131,13 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> m
return;
}
showChatWindow();
+ boost::shared_ptr<Delay> delayPayload = message->getPayload<Delay>();
+ if (delayPayload) {
+ boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
+ std::ostringstream s;
+ s << "The following message took " << (now - delayPayload->getStamp()).total_milliseconds() << " milliseconds to be delivered.";
+ chatWindow_->addSystemMessage(String(s.str()));
+ }
boost::shared_ptr<SecurityLabel> label = message->getPayload<SecurityLabel>();
boost::optional<SecurityLabel> maybeLabel = label ? boost::optional<SecurityLabel>(*label) : boost::optional<SecurityLabel>();
JID from = message->getFrom();