summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-10-22 12:07:23 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-10-22 15:27:06 (GMT)
commit991f0774c006a2c9a0998090dae4729059cc72b6 (patch)
tree1c396b2c3e1700cc80c2ddabad4c55492ebb74e3
parent077a1cf938d007874c2915b5fd703d4776bb25cd (diff)
downloadswift-contrib-991f0774c006a2c9a0998090dae4729059cc72b6.zip
swift-contrib-991f0774c006a2c9a0998090dae4729059cc72b6.tar.bz2
Minor fixes to MUCs.
Resolves: #626 Resolves: #632 Release-Notes: Notices will now be generated if someone says your nick in the MUC in any variant of capitalisation, and will not be generated if it was you that said it.
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp4
-rw-r--r--Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp120
-rw-r--r--Swift/Controllers/XMPPEvents/MessageEvent.h2
-rw-r--r--Swift/QtUI/QtMainWindow.h2
-rw-r--r--Swiften/Elements/MUCUserPayload.h3
5 files changed, 126 insertions, 5 deletions
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index 9cf235e..8b9f3fa 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -228,13 +228,13 @@ JID MUCController::nickToJID(const String& nick) {
}
bool MUCController::messageTargetsMe(boost::shared_ptr<Message> message) {
- return message->getBody().contains(nick_);
+ return message->getBody().getLowerCase().contains(nick_.getLowerCase());
}
void MUCController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) {
clearPresenceQueue();
boost::shared_ptr<Message> message = messageEvent->getStanza();
- if (joined_ && messageTargetsMe(message) && !message->getPayload<Delay>()) {
+ if (joined_ && messageEvent->getStanza()->getFrom().getResource() != nick_ && messageTargetsMe(message) && !message->getPayload<Delay>()) {
eventController_->handleIncomingEvent(messageEvent);
if (messageEvent->isReadable()) {
chatWindow_->flash();
diff --git a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
index fbc6901..aeae562 100644
--- a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
@@ -6,8 +6,23 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
+#include "3rdParty/hippomocks.h"
+#include "Swift/Controllers/XMPPEvents/EventController.h"
+#include "Swiften/Presence/PresenceSender.h"
+#include "Swiften/Avatars/NullAvatarManager.h"
#include "Swift/Controllers/Chat/MUCController.h"
+#include "Swift/Controllers/UIInterfaces/ChatWindow.h"
+#include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h"
+#include "Swift/Controllers/NickResolver.h"
+#include "Swiften/Roster/XMPPRoster.h"
+#include "Swift/Controllers/UIEvents/UIEventStream.h"
+#include "Swift/Controllers/UnitTest/MockChatWindow.h"
+#include "Swiften/Client/DummyStanzaChannel.h"
+#include "Swiften/Queries/DummyIQChannel.h"
+#include "Swiften/Presence/PresenceOracle.h"
+#include "Swiften/Network/TimerFactory.h"
+#include "Swiften/Elements/MUCUserPayload.h"
using namespace Swift;
@@ -17,15 +32,102 @@ class MUCControllerTest : public CppUnit::TestFixture
CPPUNIT_TEST(testJoinPartStringContructionSimple);
CPPUNIT_TEST(testJoinPartStringContructionMixed);
CPPUNIT_TEST(testAppendToJoinParts);
+ CPPUNIT_TEST(testAddressedToSelf);
+ CPPUNIT_TEST(testNotAddressedToSelf);
+ CPPUNIT_TEST(testAddressedToSelfBySelf);
CPPUNIT_TEST_SUITE_END();
public:
MUCControllerTest() {};
void setUp() {
+ self_ = JID("girl@wonderland.lit/rabbithole");
+ muc_ = JID("teaparty@rooms.wonderland.lit");
+ nick_ = "aLiCe";
+ mocks_ = new MockRepository();
+ stanzaChannel_ = new DummyStanzaChannel();
+ iqChannel_ = new DummyIQChannel();
+ iqRouter_ = new IQRouter(iqChannel_);
+ eventController_ = new EventController();
+ chatWindowFactory_ = mocks_->InterfaceMock<ChatWindowFactory>();
+ presenceOracle_ = new PresenceOracle(stanzaChannel_);
+ presenceSender_ = new PresenceSender(stanzaChannel_);
+ uiEventStream_ = new UIEventStream();
+ avatarManager_ = new NullAvatarManager();
+ TimerFactory* timerFactory = NULL;
+ window_ = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(muc_, uiEventStream_).Return(window_);
+ controller_ = new MUCController (self_, muc_, nick_, stanzaChannel_, presenceSender_,
+ iqRouter_, chatWindowFactory_, presenceOracle_, avatarManager_, uiEventStream_, false, timerFactory, eventController_);
};
void tearDown() {
+ delete controller_;
+ delete eventController_;
+ delete presenceOracle_;
+ delete mocks_;
+ delete uiEventStream_;
+ delete stanzaChannel_;
+ delete presenceSender_;
+ delete iqRouter_;
+ delete iqChannel_;
+ delete avatarManager_;
+ }
+
+ void finishJoin() {
+ Presence::ref presence(new Presence());
+ presence->setFrom(JID(muc_.toString() + "/" + nick_));
+ MUCUserPayload::ref status(new MUCUserPayload());
+ MUCUserPayload::StatusCode code;
+ code.code = 110;
+ status->addStatusCode(code);
+ presence->addPayload(status);
+ stanzaChannel_->onPresenceReceived(presence);
+ }
+
+ void testAddressedToSelf() {
+ finishJoin();
+ Message::ref message(new Message());
+
+ message = Message::ref(new Message());
+ message->setFrom(JID(muc_.toString() + "/otherperson"));
+ message->setBody(nick_ + ": hi there");
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)1, eventController_->getEvents().size());
+
+ message->setFrom(JID(muc_.toString() + "/other"));
+ message->setBody("Hi there " + nick_);
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)2, eventController_->getEvents().size());
+
+ message = Message::ref(new Message());
+ message->setFrom(JID(muc_.toString() + "/other2"));
+ message->setBody("Hi " + nick_.getLowerCase());
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)3, eventController_->getEvents().size());
+ }
+
+ void testNotAddressedToSelf() {
+ finishJoin();
+ Message::ref message(new Message());
+ message->setFrom(JID(muc_.toString() + "/other3"));
+ message->setBody("Hi there Hatter");
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)0, eventController_->getEvents().size());
+ }
+
+ void testAddressedToSelfBySelf() {
+ finishJoin();
+ Message::ref message(new Message());
+ message->setFrom(JID(muc_.toString() + "/" + nick_));
+ message->setBody("Hi there " + nick_);
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)0, eventController_->getEvents().size());
}
void checkEqual(const std::vector<NickJoinPart>& expected, const std::vector<NickJoinPart>& actual) {
@@ -95,6 +197,24 @@ public:
list.push_back(NickJoinPart("Ernie", JoinThenPart));
CPPUNIT_ASSERT_EQUAL(String("Kev joined then left the room, Remko has left the room, Bert left then rejoined the room and Ernie joined then left the room."), MUCController::generateJoinPartString(list));
}
+
+private:
+ JID self_;
+ JID muc_;
+ String nick_;
+ StanzaChannel* stanzaChannel_;
+ IQChannel* iqChannel_;
+ IQRouter* iqRouter_;
+ EventController* eventController_;
+ ChatWindowFactory* chatWindowFactory_;
+ MUCController* controller_;
+// NickResolver* nickResolver_;
+ PresenceOracle* presenceOracle_;
+ AvatarManager* avatarManager_;
+ PresenceSender* presenceSender_;
+ MockRepository* mocks_;
+ UIEventStream* uiEventStream_;
+ MockChatWindow* window_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(MUCControllerTest);
diff --git a/Swift/Controllers/XMPPEvents/MessageEvent.h b/Swift/Controllers/XMPPEvents/MessageEvent.h
index 313ad78..cd902ad 100644
--- a/Swift/Controllers/XMPPEvents/MessageEvent.h
+++ b/Swift/Controllers/XMPPEvents/MessageEvent.h
@@ -16,7 +16,7 @@
#include "Swiften/Elements/Message.h"
namespace Swift {
- class MessageEvent : public StanzaEvent {
+ class MessageEvent : public StanzaEvent, public Shared<MessageEvent> {
public:
MessageEvent(boost::shared_ptr<Message> stanza) : stanza_(stanza){};
diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h
index b61a84d..ac325bd 100644
--- a/Swift/QtUI/QtMainWindow.h
+++ b/Swift/QtUI/QtMainWindow.h
@@ -41,7 +41,7 @@ namespace Swift {
void setMyName(const String& name);
void setMyAvatarPath(const String& path);
void setMyStatusText(const String& status);
- void setMyStatusType(const StatusShow::Type type);
+ void setMyStatusType(StatusShow::Type type);
QtEventWindow* getEventWindow();
QtChatListWindow* getChatListWindow();
void setRosterModel(Roster* roster);
diff --git a/Swiften/Elements/MUCUserPayload.h b/Swiften/Elements/MUCUserPayload.h
index 3032b9f..8635176 100644
--- a/Swiften/Elements/MUCUserPayload.h
+++ b/Swiften/Elements/MUCUserPayload.h
@@ -10,11 +10,12 @@
#include "Swiften/JID/JID.h"
#include "Swiften/Base/String.h"
+#include "Swiften/Base/Shared.h"
#include "Swiften/Elements/Payload.h"
#include "Swiften/MUC/MUCOccupant.h"
namespace Swift {
- class MUCUserPayload : public Payload {
+ class MUCUserPayload : public Payload, public Shared<MUCUserPayload> {
public:
struct Item {
Item() : affiliation(MUCOccupant::NoAffiliation), role(MUCOccupant::NoRole) {}