summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Piekos <mateuszpiekos@gmail.com>2012-08-08 11:43:56 (GMT)
committerMateusz Piekos <mateuszpiekos@gmail.com>2012-08-08 11:43:56 (GMT)
commit3fa0d466150981d33f535108190f1e9744fb3e09 (patch)
tree1f41ed407741e3e9719dedce8b8405ea18c4c78d /Swiften/Whiteboard/WhiteboardSessionManager.cpp
parent84cc4e93c5e3f68d055cbddf8072025d91c44a23 (diff)
downloadswift-contrib-3fa0d466150981d33f535108190f1e9744fb3e09.zip
swift-contrib-3fa0d466150981d33f535108190f1e9744fb3e09.tar.bz2
Handling of sessions with contacts which become unavailable
Diffstat (limited to 'Swiften/Whiteboard/WhiteboardSessionManager.cpp')
-rw-r--r--Swiften/Whiteboard/WhiteboardSessionManager.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/Swiften/Whiteboard/WhiteboardSessionManager.cpp b/Swiften/Whiteboard/WhiteboardSessionManager.cpp
index 88771e7..c8e9a6a 100644
--- a/Swiften/Whiteboard/WhiteboardSessionManager.cpp
+++ b/Swiften/Whiteboard/WhiteboardSessionManager.cpp
@@ -16,9 +16,11 @@
#include "Swiften/Disco/EntityCapsProvider.h"
namespace Swift {
- WhiteboardSessionManager::WhiteboardSessionManager(IQRouter* router, PresenceOracle* presenceOracle, EntityCapsProvider* capsProvider) : router_(router), presenceOracle_(presenceOracle), capsProvider_(capsProvider) {
+ WhiteboardSessionManager::WhiteboardSessionManager(IQRouter* router, StanzaChannel* stanzaChannel, PresenceOracle* presenceOracle, EntityCapsProvider* capsProvider) : router_(router), stanzaChannel_(stanzaChannel), presenceOracle_(presenceOracle), capsProvider_(capsProvider) {
responder = new WhiteboardResponder(this, router);
responder->start();
+ stanzaChannel_->onPresenceReceived.connect(boost::bind(&WhiteboardSessionManager::handlePresenceReceived, this, _1));
+ stanzaChannel_->onAvailableChanged.connect(boost::bind(&WhiteboardSessionManager::handleAvailableChanged, this, _1));
}
WhiteboardSessionManager::~WhiteboardSessionManager() {
@@ -40,8 +42,7 @@ namespace Swift {
}
OutgoingWhiteboardSession::ref session = boost::make_shared<OutgoingWhiteboardSession>(fullJID, router_);
sessions_[fullJID] = session;
- session->onSessionTerminateReceived.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
- session->onSessionCancelled.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
+ session->onSessionTerminated.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
session->onRequestRejected.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
return session;
}
@@ -59,8 +60,7 @@ namespace Swift {
void WhiteboardSessionManager::handleIncomingSession(IncomingWhiteboardSession::ref session) {
sessions_[session->getTo()] = session;
- session->onSessionTerminateReceived.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
- session->onSessionCancelled.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
+ session->onSessionTerminated.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
onSessionRequest(session);
}
@@ -89,4 +89,23 @@ namespace Swift {
void WhiteboardSessionManager::deleteSessionEntry(const JID& contact) {
sessions_.erase(contact);
}
+
+ void WhiteboardSessionManager::handlePresenceReceived(Presence::ref presence) {
+ if (!presence->isAvailable()) {
+ WhiteboardSession::ref session = getSession(presence->getFrom());
+ if (session) {
+ session->cancel();
+ }
+ }
+ }
+
+ void WhiteboardSessionManager::handleAvailableChanged(bool available) {
+ if (!available) {
+ std::map<JID, WhiteboardSession::ref> sessionsCopy = sessions_;
+ std::map<JID, WhiteboardSession::ref>::iterator it;
+ for (it = sessionsCopy.begin(); it != sessionsCopy.end(); ++it) {
+ it->second->cancel();
+ }
+ }
+ }
}