diff --git a/include/Swiften/Server/ServerStanzaChannel.cpp b/include/Swiften/Server/ServerStanzaChannel.cpp index bfa33db43dde894195ae3accfed5852a096c9a29..4ac5acc83a06c3c403b692e244b408af3fb32cd7 100644 --- a/include/Swiften/Server/ServerStanzaChannel.cpp +++ b/include/Swiften/Server/ServerStanzaChannel.cpp @@ -29,6 +29,7 @@ namespace { } void ServerStanzaChannel::addSession(boost::shared_ptr session) { + std::cout << "ADDING SESSION\n"; sessions[session->getRemoteJID().toBare().toString()].push_back(session); session->onSessionFinished.connect(boost::bind(&ServerStanzaChannel::handleSessionFinished, this, _1, session)); session->onElementReceived.connect(boost::bind(&ServerStanzaChannel::handleElement, this, _1, session)); @@ -53,20 +54,30 @@ void ServerStanzaChannel::sendPresence(boost::shared_ptr presence) { send(presence); } -void ServerStanzaChannel::finishSession(const JID& to, boost::shared_ptr element) { +void ServerStanzaChannel::finishSession(const JID& to, boost::shared_ptr element, bool last) { std::vector > candidateSessions; for (std::list >::const_iterator i = sessions[to.toBare().toString()].begin(); i != sessions[to.toBare().toString()].end(); ++i) { - if (element) { - (*i)->sendElement(element); - } candidateSessions.push_back(*i); } for (std::vector >::const_iterator i = candidateSessions.begin(); i != candidateSessions.end(); ++i) { - + removeSession(*i); + if (element) { + (*i)->sendElement(element); + } + + if (last && (*i)->getRemoteJID().isValid()) { + Swift::Presence::ref presence = Swift::Presence::create(); + presence->setFrom((*i)->getRemoteJID()); + presence->setType(Swift::Presence::Unavailable); + onPresenceReceived(presence); + } + (*i)->finishSession(); - sessions[to.toBare().toString()].remove(*i); std::cout << "FINISH SESSION " << sessions[to.toBare().toString()].size() << "\n"; + if (last) { + break; + } } } @@ -109,10 +120,12 @@ void ServerStanzaChannel::send(boost::shared_ptr stanza) { void ServerStanzaChannel::handleSessionFinished(const boost::optional&, const boost::shared_ptr& session) { removeSession(session); - Swift::Presence::ref presence = Swift::Presence::create(); - presence->setFrom(session->getRemoteJID()); - presence->setType(Swift::Presence::Unavailable); - onPresenceReceived(presence); +// if (!session->initiatedFinish()) { + Swift::Presence::ref presence = Swift::Presence::create(); + presence->setFrom(session->getRemoteJID()); + presence->setType(Swift::Presence::Unavailable); + onPresenceReceived(presence); +// } } void ServerStanzaChannel::handleElement(boost::shared_ptr element, const boost::shared_ptr& session) {