diff --git a/include/transport/Conversation.h b/include/transport/Conversation.h index d5374ec9..ee48d82e 100644 --- a/include/transport/Conversation.h +++ b/include/transport/Conversation.h @@ -98,9 +98,7 @@ class Conversation { m_jids.clear(); } - void removeJID(const Swift::JID &jid) { - m_jids.remove(jid); - } + void removeJID(const Swift::JID &jid); const std::list &getJIDs() { return m_jids; diff --git a/libtransport/Conversation.cpp b/libtransport/Conversation.cpp index 1907eb83..34de156c 100644 --- a/libtransport/Conversation.cpp +++ b/libtransport/Conversation.cpp @@ -360,6 +360,10 @@ void Conversation::handleRawPresence(Swift::Presence::ref presence) { m_participants[presence->getFrom().getResource()].presence = presence; } +void Conversation::removeJID(const Swift::JID &jid) { + m_jids.remove(jid); +} + void Conversation::handleParticipantChanged(const std::string &nick, Conversation::ParticipantFlag flag, int status, const std::string &statusMessage, const std::string &newname, const std::string &iconhash, const std::string &alias) { Swift::Presence::ref presence = generatePresence(alias.empty() ? nick : alias, flag, status, statusMessage, newname, iconhash); diff --git a/libtransport/ConversationManager.cpp b/libtransport/ConversationManager.cpp index 13ac150d..24678466 100644 --- a/libtransport/ConversationManager.cpp +++ b/libtransport/ConversationManager.cpp @@ -103,8 +103,20 @@ void ConversationManager::resetResources() { } void ConversationManager::removeJID(const Swift::JID &jid) { + std::vector toRemove; for (std::map::const_iterator it = m_convs.begin(); it != m_convs.end(); it++) { (*it).second->removeJID(jid); + if (it->second->getJIDs().empty()) { + toRemove.push_back(it->first); + } + } + + if (m_user->getUserSetting("stay_connected") != "1") { + while(!toRemove.empty()) { + LOG4CXX_INFO(logger, m_user->getJID().toString() << ": Leaving room " << toRemove.back() << "."); + m_user->leaveRoom(toRemove.back()); + toRemove.pop_back(); + } } }