From d0699848cf1c99b7343d833232ac6e5e888ba123 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Thu, 16 Aug 2012 12:52:53 +0200 Subject: [PATCH] Join room just once --- src/tests/user.cpp | 21 +++++++++++++++++++++ src/user.cpp | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/src/tests/user.cpp b/src/tests/user.cpp index e070160b..e5df9ee2 100644 --- a/src/tests/user.cpp +++ b/src/tests/user.cpp @@ -132,6 +132,8 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest { } void handlePresenceJoinRoom() { + User *user = userManager->getUser("user@localhost"); + Swift::Presence::ref response = Swift::Presence::create(); response->setTo("#room@localhost/hanzz"); response->setFrom("user@localhost/resource"); @@ -149,6 +151,25 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest { CPPUNIT_ASSERT_EQUAL(std::string("#room"), room); CPPUNIT_ASSERT_EQUAL(std::string("hanzz"), roomNickname); CPPUNIT_ASSERT_EQUAL(std::string("password"), roomPassword); + + room = ""; + roomNickname = ""; + roomPassword = ""; + + // simulate that backend joined the room + TestingConversation *conv = new TestingConversation(user->getConversationManager(), "#room", true); + + received.clear(); + injectPresence(response); + loop->processEvents(); + + // no presence received in server mode, just disco#info + CPPUNIT_ASSERT_EQUAL(1, (int) received.size()); + CPPUNIT_ASSERT(getStanza(received[0])->getPayload()); + + CPPUNIT_ASSERT_EQUAL(std::string(""), room); + CPPUNIT_ASSERT_EQUAL(std::string(""), roomNickname); + CPPUNIT_ASSERT_EQUAL(std::string(""), roomPassword); } void handlePresenceLeaveRoom() { diff --git a/src/user.cpp b/src/user.cpp index cd1ac703..d95ad8a9 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -226,6 +226,11 @@ void User::handlePresence(Swift::Presence::ref presence) { onReadyToConnect(); } std::string room = Buddy::JIDToLegacyName(presence->getTo()); + if (m_conversationManager->getConversation(room) != NULL) { + LOG4CXX_INFO(logger, m_jid.toString() << ": User has already tried to join room " << room << " as " << presence->getTo().getResource()); + return; + } + LOG4CXX_INFO(logger, m_jid.toString() << ": Going to join room " << room << " as " << presence->getTo().getResource()); std::string password = ""; if (presence->getPayload() != NULL) {