diff --git a/src/conversation.cpp b/src/conversation.cpp index 22799776a093520225ab9e433267111754adc7b9..f610546131b596b6d51b683c113b6f58cb5ea086 100644 --- a/src/conversation.cpp +++ b/src/conversation.cpp @@ -55,6 +55,10 @@ void Conversation::destroyRoom() { Swift::MUCUserPayload *p = new Swift::MUCUserPayload (); p->addItem(item); + Swift::MUCUserPayload::StatusCode c; + c.code = 332; + p->addStatusCode(c); + presence->addPayload(boost::shared_ptr(p)); m_conversationManager->getComponent()->getStanzaChannel()->sendPresence(presence); } @@ -111,13 +115,23 @@ void Conversation::handleMessage(boost::shared_ptr &message, con if (n.empty()) { n = " "; } - message->setTo(m_jid); - message->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), n)); - m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message); + BOOST_FOREACH(const Swift::JID &jid, m_jids) { + message->setTo(jid); + message->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), n)); + m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message); + } } } -void Conversation::handleParticipantChanged(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname) { +void Conversation::sendParticipants(const Swift::JID &to) { + for (std::map::iterator it = m_participants.begin(); it != m_participants.end(); it++) { + Swift::Presence::ref presence = generatePresence(it->first, it->second.flag, it->second.status, it->second.statusMessage, ""); + presence->setTo(to); + m_conversationManager->getComponent()->getStanzaChannel()->sendPresence(presence); + } +} + +Swift::Presence::ref Conversation::generatePresence(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname) { std::string nickname = nick; Swift::Presence::ref presence = Swift::Presence::create(); std::string legacyName = m_legacyName; @@ -127,7 +141,6 @@ void Conversation::handleParticipantChanged(const std::string &nick, int flag, i } } presence->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname)); - presence->setTo(m_jid); presence->setType(Swift::Presence::Available); if (!statusMessage.empty()) @@ -168,9 +181,29 @@ void Conversation::handleParticipantChanged(const std::string &nick, int flag, i } p->addItem(item); - presence->addPayload(boost::shared_ptr(p)); - m_conversationManager->getComponent()->getStanzaChannel()->sendPresence(presence); + return presence; +} + +void Conversation::handleParticipantChanged(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname) { + Swift::Presence::ref presence = generatePresence(nick, flag, status, statusMessage, newname); + + if (presence->getType() == Swift::Presence::Unavailable) { + m_participants.erase(nick); + } + else { + Participant p; + p.flag = flag; + p.status = status; + p.statusMessage = statusMessage; + m_participants[nick] = p; + } + + + BOOST_FOREACH(const Swift::JID &jid, m_jids) { + presence->setTo(jid); + m_conversationManager->getComponent()->getStanzaChannel()->sendPresence(presence); + } if (!newname.empty()) { handleParticipantChanged(newname, flag, status, statusMessage); }