summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-12-26 23:00:53 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-12-26 23:00:53 (GMT)
commit4d89c280976426c9e29ee9235b296afc4d38a7cd (patch)
tree5175891eebfc5cc05e64dc5e92ab5a1befcc85a2 /Swift
parentc3bda61b09597a7944fbc382366bcdf998540e82 (diff)
downloadswift-4d89c280976426c9e29ee9235b296afc4d38a7cd.zip
swift-4d89c280976426c9e29ee9235b296afc4d38a7cd.tar.bz2
Fix segfault at launch due to argument reversal.
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/ChatsManager.cpp2
-rw-r--r--Swift/Controllers/ChatsManager.h2
-rw-r--r--Swift/Controllers/UnitTest/ChatsManagerTest.cpp6
3 files changed, 5 insertions, 5 deletions
diff --git a/Swift/Controllers/ChatsManager.cpp b/Swift/Controllers/ChatsManager.cpp
index fe8efb3..2863a14 100644
--- a/Swift/Controllers/ChatsManager.cpp
+++ b/Swift/Controllers/ChatsManager.cpp
@@ -1,92 +1,92 @@
#include "Swift/Controllers/ChatsManager.h"
#include <boost/bind.hpp>
#include "Swiften/Client/Client.h"
#include "Swift/Controllers/ChatController.h"
#include "Swift/Controllers/EventController.h"
#include "Swift/Controllers/MUCController.h"
#include "Swiften/Presence/PresenceSender.h"
namespace Swift {
typedef std::pair<JID, ChatController*> JIDChatControllerPair;
typedef std::pair<JID, MUCController*> JIDMUCControllerPair;
ChatsManager::ChatsManager(JID jid, StanzaChannel* stanzaChannel, IQRouter* iqRouter, EventController* eventController, ChatWindowFactory* chatWindowFactory, TreeWidgetFactory* treeWidgetFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, boost::shared_ptr<DiscoInfo> serverDiscoInfo, PresenceSender* presenceSender) : jid_(jid) {
eventController_ = eventController;
stanzaChannel_ = stanzaChannel;
iqRouter_ = iqRouter;
chatWindowFactory_ = chatWindowFactory;
treeWidgetFactory_ = treeWidgetFactory;
nickResolver_ = nickResolver;
presenceOracle_ = presenceOracle;
avatarManager_ = NULL;
serverDiscoInfo_ = serverDiscoInfo;
presenceSender_ = presenceSender;
presenceOracle_->onPresenceChange.connect(boost::bind(&ChatsManager::handlePresenceChange, this, _1, _2));
}
ChatsManager::~ChatsManager() {
foreach (JIDChatControllerPair controllerPair, chatControllers_) {
delete controllerPair.second;
}
foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
delete controllerPair.second;
}
}
/**
* If a resource goes offline, release bound chatdialog to that resource.
*/
-void ChatsManager::handlePresenceChange(boost::shared_ptr<Presence> /*oldPresence*/, boost::shared_ptr<Presence> newPresence) {
+void ChatsManager::handlePresenceChange(boost::shared_ptr<Presence> newPresence, boost::shared_ptr<Presence> /*lastPresence*/) {
if (newPresence->getType() != Presence::Unavailable) return;
JID fullJID(newPresence->getFrom());
std::map<JID, ChatController*>::iterator it = chatControllers_.find(fullJID);
if (it == chatControllers_.end()) return;
JID bareJID(fullJID.toBare());
//It doesn't make sense to have two unbound dialogs.
if (chatControllers_.find(bareJID) != chatControllers_.end()) return;
rebindControllerJID(fullJID, bareJID);
}
void ChatsManager::setAvatarManager(AvatarManager* avatarManager) {
avatarManager_ = avatarManager;
}
// void ChatsManager::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) {
// {
// boost::shared_ptr<RequestChatUIEvent> event = boost::dynamic_pointer_cast<RequestChatUIEvent>(rawEvent);
// if (event != NULL) {
// handleChatRequest(event->getContact());
// return;
// }
// }
// {
// boost::shared_ptr<JoinMUCUIEvent> event = boost::dynamic_pointer_cast<JoinMUCUIEvent>(rawEvent);
// if (event != NULL) {
// handleJoinMUCRequest(event->getRoom(), event->getNick());
// }
// }
// }
void ChatsManager::setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info) {
foreach (JIDChatControllerPair pair, chatControllers_) {
pair.second->setAvailableServerFeatures(info);
}
foreach (JIDMUCControllerPair pair, mucControllers_) {
pair.second->setAvailableServerFeatures(info);
}
}
void ChatsManager::setEnabled(bool enabled) {
foreach (JIDChatControllerPair controllerPair, chatControllers_) {
//printf("Setting enabled on %d to %d\n", controllerPair.second, enabled);
controllerPair.second->setEnabled(enabled);
}
foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
controllerPair.second->setEnabled(enabled);
}
diff --git a/Swift/Controllers/ChatsManager.h b/Swift/Controllers/ChatsManager.h
index 260bd1d..dd80d95 100644
--- a/Swift/Controllers/ChatsManager.h
+++ b/Swift/Controllers/ChatsManager.h
@@ -1,56 +1,56 @@
#pragma once
#include <map>
#include <boost/shared_ptr.hpp>
#include "Swiften/Base/String.h"
#include "Swiften/Elements/DiscoInfo.h"
#include "Swiften/Elements/Message.h"
#include "Swiften/Elements/Presence.h"
#include "Swiften/JID/JID.h"
#include "Swiften/MUC/MUCRegistry.h"
namespace Swift {
class EventController;
class ChatController;
class MUCController;
class ChatWindowFactory;
class TreeWidgetFactory;
class NickResolver;
class PresenceOracle;
class AvatarManager;
class StanzaChannel;
class IQRouter;
class PresenceSender;
class ChatsManager : public MUCRegistry {
public:
ChatsManager(JID jid, StanzaChannel* stanzaChannel, IQRouter* iqRouter, EventController* eventController, ChatWindowFactory* chatWindowFactory, TreeWidgetFactory* treeWidgetFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, boost::shared_ptr<DiscoInfo> serverDiscoInfo, PresenceSender* presenceSender);
~ChatsManager();
void setAvatarManager(AvatarManager* avatarManager);
void setEnabled(bool enabled);
void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info);
void handleIncomingMessage(boost::shared_ptr<Message> message);
void handleChatRequest(const String& contact);
void handleJoinMUCRequest(const JID& muc, const String& nick);
private:
void rebindControllerJID(const JID& from, const JID& to);
- void handlePresenceChange(boost::shared_ptr<Presence> oldPresence, boost::shared_ptr<Presence> newPresence);
+ void handlePresenceChange(boost::shared_ptr<Presence> newPresence, boost::shared_ptr<Presence> lastPresence);
ChatController* getChatController(const JID &contact);
virtual bool isMUC(const JID& muc) const;
std::map<JID, MUCController*> mucControllers_;
std::map<JID, ChatController*> chatControllers_;
EventController* eventController_;
JID jid_;
StanzaChannel* stanzaChannel_;
IQRouter* iqRouter_;;
ChatWindowFactory* chatWindowFactory_;
TreeWidgetFactory* treeWidgetFactory_;
NickResolver* nickResolver_;
PresenceOracle* presenceOracle_;
AvatarManager* avatarManager_;
PresenceSender* presenceSender_;
boost::shared_ptr<DiscoInfo> serverDiscoInfo_;
};
}
diff --git a/Swift/Controllers/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/UnitTest/ChatsManagerTest.cpp
index 9df244f..0dfc52b 100644
--- a/Swift/Controllers/UnitTest/ChatsManagerTest.cpp
+++ b/Swift/Controllers/UnitTest/ChatsManagerTest.cpp
@@ -131,139 +131,139 @@ public:
boost::shared_ptr<Message> message(new Message());
message->setFrom(JID(fullJIDString));
String body("This is a legible message. mjuga3089gm8G(*>M)@*(");
message->setBody(body);
manager_->handleIncomingMessage(message);
CPPUNIT_ASSERT_EQUAL(body, window->lastMessageBody_);
}
void testSecondWindow() {
String messageJIDString1("testling1@test.com");
ChatWindow* window1 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString1)).Return(window1);
manager_->handleChatRequest(messageJIDString1);
String messageJIDString2("testling2@test.com");
ChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString2)).Return(window2);
manager_->handleChatRequest(messageJIDString2);
}
/** Complete cycle.
Create unbound window.
Bind it.
Unbind it.
Rebind it.
*/
void testUnbindRebind() {
String bareJIDString("testling@test.com");
String fullJIDString1("testling@test.com/resource1");
String fullJIDString2("testling@test.com/resource2");
MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(bareJIDString)).Return(window);
manager_->handleChatRequest(bareJIDString);
boost::shared_ptr<Message> message1(new Message());
message1->setFrom(JID(fullJIDString1));
String messageBody1("This is a legible message.");
message1->setBody(messageBody1);
manager_->handleIncomingMessage(message1);
CPPUNIT_ASSERT_EQUAL(messageBody1, window->lastMessageBody_);
boost::shared_ptr<Presence> jid1Online(new Presence());
jid1Online->setFrom(JID(fullJIDString1));
boost::shared_ptr<Presence> jid1Offline(new Presence());
jid1Offline->setFrom(JID(fullJIDString1));
jid1Offline->setType(Presence::Unavailable);
- presenceOracle_->onPresenceChange(jid1Online, jid1Offline);
+ presenceOracle_->onPresenceChange(jid1Offline, jid1Online);
boost::shared_ptr<Message> message2(new Message());
message2->setFrom(JID(fullJIDString2));
String messageBody2("This is another legible message.");
message2->setBody(messageBody2);
manager_->handleIncomingMessage(message2);
CPPUNIT_ASSERT_EQUAL(messageBody2, window->lastMessageBody_);
}
/**
Test that a second window isn't unbound where there's already an unbound one.
Bind 1
Bind 2
Unbind 1
Unbind 2 (but it doesn't)
Sent to bound 2
Rebind 1
*/
void testNoDuplicateUnbind() {
JID messageJID1("testling@test.com/resource1");
MockChatWindow* window1 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID1).Return(window1);
boost::shared_ptr<Message> message1(new Message());
message1->setFrom(messageJID1);
message1->setBody("This is a legible message1.");
manager_->handleIncomingMessage(message1);
JID messageJID2("testling@test.com/resource2");
MockChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID2).Return(window2);
boost::shared_ptr<Message> message2(new Message());
message2->setFrom(messageJID2);
message2->setBody("This is a legible message2.");
manager_->handleIncomingMessage(message2);
boost::shared_ptr<Presence> jid1Online(new Presence());
jid1Online->setFrom(JID(messageJID1));
boost::shared_ptr<Presence> jid1Offline(new Presence());
jid1Offline->setFrom(JID(messageJID1));
jid1Offline->setType(Presence::Unavailable);
- presenceOracle_->onPresenceChange(jid1Online, jid1Offline);
+ presenceOracle_->onPresenceChange(jid1Offline, jid1Online);
boost::shared_ptr<Presence> jid2Online(new Presence());
jid2Online->setFrom(JID(messageJID2));
boost::shared_ptr<Presence> jid2Offline(new Presence());
jid2Offline->setFrom(JID(messageJID2));
jid2Offline->setType(Presence::Unavailable);
- presenceOracle_->onPresenceChange(jid2Online, jid2Offline);
+ presenceOracle_->onPresenceChange(jid2Offline, jid2Online);
JID messageJID3("testling@test.com/resource3");
boost::shared_ptr<Message> message3(new Message());
message3->setFrom(messageJID3);
String body3("This is a legible message3.");
message3->setBody(body3);
manager_->handleIncomingMessage(message3);
CPPUNIT_ASSERT_EQUAL(body3, window1->lastMessageBody_);
boost::shared_ptr<Message> message2b(new Message());
message2b->setFrom(messageJID2);
String body2b("This is a legible message2b.");
message2b->setBody(body2b);
manager_->handleIncomingMessage(message2b);
CPPUNIT_ASSERT_EQUAL(body2b, window2->lastMessageBody_);
}
private:
JID jid_;
ChatsManager* manager_;
StanzaChannel* stanzaChannel_;
IQChannel* iqChannel_;
IQRouter* iqRouter_;
EventController* eventController_;
ChatWindowFactory* chatWindowFactory_;
TreeWidgetFactory* treeWidgetFactory_;
NickResolver* nickResolver_;
PresenceOracle* presenceOracle_;
AvatarManager* avatarManager_;
boost::shared_ptr<DiscoInfo> serverDiscoInfo_;
boost::shared_ptr<XMPPRoster> xmppRoster_;
PresenceSender* presenceSender_;
MockRepository* mocks_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(ChatsManagerTest);