summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Presence')
-rw-r--r--Swiften/Presence/DirectedPresenceSender.cpp12
-rw-r--r--Swiften/Presence/DirectedPresenceSender.h8
2 files changed, 11 insertions, 9 deletions
diff --git a/Swiften/Presence/DirectedPresenceSender.cpp b/Swiften/Presence/DirectedPresenceSender.cpp
index ec0bd3f..c6cddbd 100644
--- a/Swiften/Presence/DirectedPresenceSender.cpp
+++ b/Swiften/Presence/DirectedPresenceSender.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -31,10 +31,10 @@ void DirectedPresenceSender::sendPresence(boost::shared_ptr<Presence> presence)
}
/**
- * Gets either the last broadcast presence, or an empty stanza if none has been sent.
+ * Gets the last broadcast presence, if none has been send the returned optional is not set.
*/
-boost::shared_ptr<Presence> DirectedPresenceSender::getLastSentUndirectedPresence() {
- boost::shared_ptr<Presence> presenceCopy(lastSentUndirectedPresence ? new Presence(*lastSentUndirectedPresence) : new Presence());
+boost::optional<Presence::ref> DirectedPresenceSender::getLastSentUndirectedPresence() const {
+ boost::optional<Presence::ref> presenceCopy = lastSentUndirectedPresence ? boost::optional<Presence::ref>((*lastSentUndirectedPresence)->clone()) : boost::optional<Presence::ref>();
return presenceCopy;
}
@@ -46,8 +46,8 @@ boost::shared_ptr<Presence> DirectedPresenceSender::getLastSentUndirectedPresenc
void DirectedPresenceSender::addDirectedPresenceReceiver(const JID& jid, SendPresence sendPresence) {
directedPresenceReceivers.insert(jid);
if (sendPresence == AndSendPresence && sender->isAvailable()) {
- if (lastSentUndirectedPresence && lastSentUndirectedPresence->getType() == Presence::Available) {
- boost::shared_ptr<Presence> presenceCopy(new Presence(*lastSentUndirectedPresence));
+ if (lastSentUndirectedPresence && (*lastSentUndirectedPresence)->getType() == Presence::Available) {
+ boost::shared_ptr<Presence> presenceCopy((*lastSentUndirectedPresence)->clone());
presenceCopy->setTo(jid);
sender->sendPresence(presenceCopy);
}
diff --git a/Swiften/Presence/DirectedPresenceSender.h b/Swiften/Presence/DirectedPresenceSender.h
index 0eb16a4..511e177 100644
--- a/Swiften/Presence/DirectedPresenceSender.h
+++ b/Swiften/Presence/DirectedPresenceSender.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -8,6 +8,8 @@
#include <set>
+#include <boost/optional.hpp>
+
#include <Swiften/Elements/Presence.h>
#include <Swiften/Presence/PresenceSender.h>
#include <Swiften/Base/API.h>
@@ -23,12 +25,12 @@ namespace Swift {
void sendPresence(Presence::ref);
- Presence::ref getLastSentUndirectedPresence();
+ boost::optional<Presence::ref> getLastSentUndirectedPresence() const;
bool isAvailable() const;
private:
- Presence::ref lastSentUndirectedPresence;
+ boost::optional<Presence::ref> lastSentUndirectedPresence;
PresenceSender* sender;
std::set<JID> directedPresenceReceivers;
};