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
parent84cc4e93c5e3f68d055cbddf8072025d91c44a23 (diff)
downloadswift-contrib-3fa0d466150981d33f535108190f1e9744fb3e09.zip
swift-contrib-3fa0d466150981d33f535108190f1e9744fb3e09.tar.bz2
Handling of sessions with contacts which become unavailable
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp2
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp2
-rw-r--r--Swift/Controllers/UIInterfaces/ChatWindow.h2
-rw-r--r--Swift/Controllers/WhiteboardManager.cpp6
-rw-r--r--Swift/QtUI/QtChatView.cpp2
-rw-r--r--Swift/QtUI/QtChatWindow.cpp2
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp2
-rw-r--r--Swiften/Client/Client.cpp2
-rw-r--r--Swiften/Whiteboard/WhiteboardSession.cpp4
-rw-r--r--Swiften/Whiteboard/WhiteboardSession.h3
-rw-r--r--Swiften/Whiteboard/WhiteboardSessionManager.cpp29
-rw-r--r--Swiften/Whiteboard/WhiteboardSessionManager.h10
12 files changed, 41 insertions, 25 deletions
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index 3c87fc6..1435293 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -112,7 +112,7 @@ ChatsManager::ChatsManager(
ftOverview_->onNewFileTransferController.connect(boost::bind(&ChatsManager::handleNewFileTransferController, this, _1));
whiteboardManager_->onSessionRequest.connect(boost::bind(&ChatsManager::handleWhiteboardSessionRequest, this, _1, _2));
whiteboardManager_->onRequestAccepted.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardAccepted));
- whiteboardManager_->onSessionTerminate.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardCanceled));
+ whiteboardManager_->onSessionTerminate.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardTerminated));
whiteboardManager_->onRequestRejected.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardRejected));
roster_->onJIDAdded.connect(boost::bind(&ChatsManager::handleJIDAddedToRoster, this, _1));
roster_->onJIDRemoved.connect(boost::bind(&ChatsManager::handleJIDRemovedFromRoster, this, _1));
diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
index 1ac1e72..2823e83 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
@@ -104,7 +104,7 @@ public:
ftManager_ = new DummyFileTransferManager();
ftOverview_ = new FileTransferOverview(ftManager_);
avatarManager_ = new NullAvatarManager();
- wbSessionManager_ = new WhiteboardSessionManager(iqRouter_, presenceOracle_, entityCapsManager_);
+ wbSessionManager_ = new WhiteboardSessionManager(iqRouter_, stanzaChannel_, presenceOracle_, entityCapsManager_);
wbManager_ = new WhiteboardManager(whiteboardWindowFactory_, uiEventStream_, nickResolver_, avatarManager_, wbSessionManager_);
mocks_->ExpectCall(chatListWindowFactory_, ChatListWindowFactory::createChatListWindow).With(uiEventStream_).Return(chatListWindow_);
diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h
index 1c6edd6..7426364 100644
--- a/Swift/Controllers/UIInterfaces/ChatWindow.h
+++ b/Swift/Controllers/UIInterfaces/ChatWindow.h
@@ -36,7 +36,7 @@ namespace Swift {
enum OccupantAction {Kick, Ban, MakeModerator, MakeParticipant, MakeVisitor, AddContact};
enum RoomAction {ChangeSubject, Configure, Affiliations, Destroy, Invite};
enum FileTransferState {WaitingForAccept, Negotiating, Transferring, Canceled, Finished, FTFailed};
- enum WhiteboardSessionState {WhiteboardAccepted, WhiteboardCanceled, WhiteboardTerminated, WhiteboardRejected};
+ enum WhiteboardSessionState {WhiteboardAccepted, WhiteboardTerminated, WhiteboardRejected};
ChatWindow() {}
virtual ~ChatWindow() {};
diff --git a/Swift/Controllers/WhiteboardManager.cpp b/Swift/Controllers/WhiteboardManager.cpp
index 2b6c448..632aef6 100644
--- a/Swift/Controllers/WhiteboardManager.cpp
+++ b/Swift/Controllers/WhiteboardManager.cpp
@@ -79,8 +79,7 @@ namespace Swift {
void WhiteboardManager::requestSession(const JID& contact) {
WhiteboardSession::ref session = whiteboardSessionManager_->requestSession(contact);
- session->onSessionTerminateReceived.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1));
- session->onSessionCancelled.connect(boost::bind(&WhiteboardManager::handleSessionCancel, this, _1));
+ session->onSessionTerminated.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1));
session->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccept, this, _1));
session->onRequestRejected.connect(boost::bind(&WhiteboardManager::handleRequestReject, this, _1));
@@ -101,8 +100,7 @@ namespace Swift {
}
void WhiteboardManager::handleIncomingSession(IncomingWhiteboardSession::ref session) {
- session->onSessionTerminateReceived.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1));
- session->onSessionCancelled.connect(boost::bind(&WhiteboardManager::handleSessionCancel, this, _1));
+ session->onSessionTerminated.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1));
session->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccept, this, _1));
WhiteboardWindow* window = findWhiteboardWindow(session->getTo());
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp
index 2f9a6e7..75374be 100644
--- a/Swift/QtUI/QtChatView.cpp
+++ b/Swift/QtUI/QtChatView.cpp
@@ -367,7 +367,7 @@ void QtChatView::setWhiteboardSessionStatus(QString id, const ChatWindow::Whiteb
if (state == ChatWindow::WhiteboardAccepted) {
newInnerHTML = tr("Started whiteboard chat") + "<br/>" +
QtChatWindow::buildChatWindowButton(tr("Show whiteboard"), QtChatWindow::ButtonWhiteboardShowWindow, id);
- } else if (state == ChatWindow::WhiteboardCanceled) {
+ } else if (state == ChatWindow::WhiteboardTerminated) {
newInnerHTML = tr("Whiteboard chat has been canceled");
} else if (state == ChatWindow::WhiteboardRejected) {
newInnerHTML = tr("Whiteboard chat request has been rejected");
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index bf06abd..0dc53a6 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -668,7 +668,7 @@ void QtChatWindow::handleHTMLButtonClicked(QString id, QString encodedArgument1,
}
else if (id.startsWith(ButtonWhiteboardSessionCancel)) {
QString id = arg1;
- messageLog_->setWhiteboardSessionStatus(QString::fromStdString(Q2PSTRING(id)), ChatWindow::WhiteboardCanceled);
+ messageLog_->setWhiteboardSessionStatus(QString::fromStdString(Q2PSTRING(id)), ChatWindow::WhiteboardTerminated);
onWhiteboardSessionCancel();
}
else if (id.startsWith(ButtonWhiteboardShowWindow)) {
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
index eb22904..e6c9889 100644
--- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
@@ -221,7 +221,7 @@ namespace Swift {
graphicsView->setIDPrefix(P2QSTRING(whiteboardSession_->getClientID()));
whiteboardSession_->onOperationReceived.connect(boost::bind(&QtWhiteboardWindow::handleWhiteboardOperationReceive, this, _1));
whiteboardSession_->onRequestAccepted.connect(boost::bind(&QWidget::show, this));
- whiteboardSession_->onSessionTerminateReceived.connect(boost::bind(&QtWhiteboardWindow::handleSessionTerminate, this));
+ whiteboardSession_->onSessionTerminated.connect(boost::bind(&QtWhiteboardWindow::handleSessionTerminate, this));
}
void QtWhiteboardWindow::activateWindow() {
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp
index a631590..6860a12 100644
--- a/Swiften/Client/Client.cpp
+++ b/Swiften/Client/Client.cpp
@@ -70,7 +70,7 @@ Client::Client(const JID& jid, const SafeString& password, NetworkFactories* net
jingleSessionManager = new JingleSessionManager(getIQRouter());
fileTransferManager = NULL;
- whiteboardSessionManager = new WhiteboardSessionManager(getIQRouter(), presenceOracle, getEntityCapsProvider());
+ whiteboardSessionManager = new WhiteboardSessionManager(getIQRouter(), getStanzaChannel(), presenceOracle, getEntityCapsProvider());
}
Client::~Client() {
diff --git a/Swiften/Whiteboard/WhiteboardSession.cpp b/Swiften/Whiteboard/WhiteboardSession.cpp
index 92865e3..10b5e51 100644
--- a/Swiften/Whiteboard/WhiteboardSession.cpp
+++ b/Swiften/Whiteboard/WhiteboardSession.cpp
@@ -28,7 +28,7 @@ namespace Swift {
onRequestAccepted(toJID_);
return;
case WhiteboardPayload::SessionTerminate:
- onSessionTerminateReceived(toJID_);
+ onSessionTerminated(toJID_);
return;
//handled elsewhere
@@ -55,7 +55,7 @@ namespace Swift {
boost::shared_ptr<WhiteboardPayload> payload = boost::make_shared<WhiteboardPayload>(WhiteboardPayload::SessionTerminate);
boost::shared_ptr<GenericRequest<WhiteboardPayload> > request = boost::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_);
request->send();
- onSessionCancelled(toJID_);
+ onSessionTerminated(toJID_);
}
const JID& WhiteboardSession::getTo() const {
diff --git a/Swiften/Whiteboard/WhiteboardSession.h b/Swiften/Whiteboard/WhiteboardSession.h
index 1b5d93f..7f0ccd3 100644
--- a/Swiften/Whiteboard/WhiteboardSession.h
+++ b/Swiften/Whiteboard/WhiteboardSession.h
@@ -37,9 +37,8 @@ namespace Swift {
public:
boost::signal< void(const WhiteboardElement::ref element)> onElementReceived;
boost::signal< void(const WhiteboardOperation::ref operation)> onOperationReceived;
- boost::signal< void(const JID& contact)> onSessionTerminateReceived;
+ boost::signal< void(const JID& contact)> onSessionTerminated;
boost::signal< void(const JID& contact)> onRequestAccepted;
- boost::signal< void(const JID& contact)> onSessionCancelled;
boost::signal< void(const JID& contact)> onRequestRejected;
private:
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();
+ }
+ }
+ }
}
diff --git a/Swiften/Whiteboard/WhiteboardSessionManager.h b/Swiften/Whiteboard/WhiteboardSessionManager.h
index faccb97..f696eb8 100644
--- a/Swiften/Whiteboard/WhiteboardSessionManager.h
+++ b/Swiften/Whiteboard/WhiteboardSessionManager.h
@@ -10,6 +10,7 @@
#include <Swiften/Queries/IQRouter.h>
#include <Swiften/JID/JID.h>
+#include <Swiften/Client/StanzaChannel.h>
#include <Swiften/Base/boost_bsignals.h>
#include <Swiften/Whiteboard/WhiteboardSession.h>
#include <Swiften/Whiteboard/IncomingWhiteboardSession.h>
@@ -24,28 +25,27 @@ namespace Swift {
class WhiteboardSessionManager {
friend class WhiteboardResponder;
public:
- WhiteboardSessionManager(IQRouter* router, PresenceOracle* presenceOracle, EntityCapsProvider* capsProvider);
+ WhiteboardSessionManager(IQRouter* router, StanzaChannel* stanzaChannel, PresenceOracle* presenceOracle, EntityCapsProvider* capsProvider);
~WhiteboardSessionManager();
WhiteboardSession::ref getSession(const JID& to);
WhiteboardSession::ref requestSession(const JID& to);
public:
- /*boost::signal< void (const JID&, bool senderIsSelf)> onSessionRequest;
- boost::signal< void (const JID&)> onSessionTerminate;
- boost::signal< void (const JID&)> onRequestAccepted;
- boost::signal< void (const JID&)> onRequestRejected;*/
boost::signal< void (IncomingWhiteboardSession::ref)> onSessionRequest;
private:
JID getFullJID(const JID& bareJID);
OutgoingWhiteboardSession::ref createOutgoingSession(const JID& to);
void handleIncomingSession(IncomingWhiteboardSession::ref session);
+ void handlePresenceReceived(Presence::ref presence);
+ void handleAvailableChanged(bool available);
void deleteSessionEntry(const JID& contact);
private:
std::map<JID, boost::shared_ptr<WhiteboardSession> > sessions_;
IQRouter* router_;
+ StanzaChannel* stanzaChannel_;
PresenceOracle* presenceOracle_;
EntityCapsProvider* capsProvider_;
WhiteboardResponder* responder;