2011-04-01 23:54:29 +02:00
|
|
|
/**
|
|
|
|
* XMPP - libpurple transport
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2015-11-18 14:05:57 +01:00
|
|
|
#include "transport/Conversation.h"
|
|
|
|
#include "transport/ConversationManager.h"
|
|
|
|
#include "transport/User.h"
|
|
|
|
#include "transport/Transport.h"
|
|
|
|
#include "transport/Buddy.h"
|
|
|
|
#include "transport/RosterManager.h"
|
|
|
|
#include "transport/Frontend.h"
|
|
|
|
#include "transport/Config.h"
|
2015-11-25 16:02:23 +01:00
|
|
|
#include "transport/Logging.h"
|
2011-04-01 23:54:29 +02:00
|
|
|
|
2013-01-23 11:29:43 +01:00
|
|
|
#include "Swiften/Elements/MUCItem.h"
|
|
|
|
#include "Swiften/Elements/MUCOccupant.h"
|
|
|
|
#include "Swiften/Elements/MUCUserPayload.h"
|
|
|
|
#include "Swiften/Elements/Delay.h"
|
2013-01-24 08:35:24 +01:00
|
|
|
#include "Swiften/Elements/MUCPayload.h"
|
2016-02-06 15:50:53 +01:00
|
|
|
#include "Swiften/Elements/VCardUpdate.h"
|
2013-01-23 11:29:43 +01:00
|
|
|
|
2011-04-01 23:54:29 +02:00
|
|
|
namespace Transport {
|
2015-11-25 16:02:23 +01:00
|
|
|
|
|
|
|
DEFINE_LOGGER(logger, "Conversation");
|
2011-04-01 23:54:29 +02:00
|
|
|
|
2011-05-19 00:05:17 +02:00
|
|
|
Conversation::Conversation(ConversationManager *conversationManager, const std::string &legacyName, bool isMUC) : m_conversationManager(conversationManager) {
|
2011-04-01 23:54:29 +02:00
|
|
|
m_legacyName = legacyName;
|
2011-05-19 00:05:17 +02:00
|
|
|
m_muc = isMUC;
|
2011-11-11 11:40:10 +01:00
|
|
|
m_jid = m_conversationManager->getUser()->getJID().toBare();
|
2012-11-27 12:51:19 +01:00
|
|
|
m_sentInitialPresence = false;
|
2013-02-26 15:31:21 +01:00
|
|
|
m_nicknameChanged = false;
|
2016-02-04 15:12:23 +01:00
|
|
|
m_mucEscaping = false;
|
2016-02-10 17:02:06 +01:00
|
|
|
m_sentInitialSubject = false;
|
2013-02-09 11:09:38 +01:00
|
|
|
|
|
|
|
if (CONFIG_BOOL_DEFAULTED(conversationManager->getComponent()->getConfig(), "features.rawxml", false)) {
|
|
|
|
m_sentInitialPresence = true;
|
|
|
|
}
|
2011-04-01 23:54:29 +02:00
|
|
|
}
|
|
|
|
|
2011-04-03 11:39:06 +02:00
|
|
|
Conversation::~Conversation() {
|
2011-04-01 23:54:29 +02:00
|
|
|
}
|
|
|
|
|
2016-02-04 15:12:23 +01:00
|
|
|
void Conversation::setMUCEscaping(bool mucEscaping) {
|
|
|
|
LOG4CXX_INFO(logger, m_jid.toString() << ": Setting MUC escaping to " << mucEscaping);
|
|
|
|
m_mucEscaping = mucEscaping;
|
|
|
|
}
|
|
|
|
|
2012-09-21 13:56:17 +02:00
|
|
|
void Conversation::destroyRoom() {
|
|
|
|
if (m_muc) {
|
|
|
|
Swift::Presence::ref presence = Swift::Presence::create();
|
|
|
|
std::string legacyName = m_legacyName;
|
2016-02-04 15:12:23 +01:00
|
|
|
if (!m_mucEscaping && legacyName.find_last_of("@") != std::string::npos) {
|
2012-09-21 13:56:17 +02:00
|
|
|
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
|
|
|
|
}
|
2016-01-27 10:54:10 +01:00
|
|
|
legacyName = Swift::JID::getEscapedNode(legacyName);
|
2012-09-21 13:56:17 +02:00
|
|
|
presence->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), m_nickname));
|
|
|
|
presence->setType(Swift::Presence::Unavailable);
|
|
|
|
|
|
|
|
Swift::MUCItem item;
|
|
|
|
item.affiliation = Swift::MUCOccupant::NoAffiliation;
|
|
|
|
item.role = Swift::MUCOccupant::NoRole;
|
2012-12-06 10:52:19 +01:00
|
|
|
item.actor = "Transport";
|
|
|
|
item.reason = "Spectrum 2 transport is being shut down.";
|
2012-09-21 13:56:17 +02:00
|
|
|
Swift::MUCUserPayload *p = new Swift::MUCUserPayload ();
|
|
|
|
p->addItem(item);
|
|
|
|
|
2012-09-22 13:40:28 +02:00
|
|
|
Swift::MUCUserPayload::StatusCode c;
|
|
|
|
c.code = 332;
|
|
|
|
p->addStatusCode(c);
|
2012-12-06 10:52:19 +01:00
|
|
|
Swift::MUCUserPayload::StatusCode c2;
|
|
|
|
c2.code = 307;
|
|
|
|
p->addStatusCode(c2);
|
2012-09-22 13:40:28 +02:00
|
|
|
|
2016-09-12 18:20:58 +02:00
|
|
|
presence->addPayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Payload>(p));
|
2012-12-06 10:52:19 +01:00
|
|
|
BOOST_FOREACH(const Swift::JID &jid, m_jids) {
|
|
|
|
presence->setTo(jid);
|
2015-11-16 10:49:10 +01:00
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendPresence(presence);
|
2012-12-06 10:52:19 +01:00
|
|
|
}
|
2012-09-21 13:56:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-25 20:29:58 +02:00
|
|
|
void Conversation::setRoom(const std::string &room) {
|
|
|
|
m_room = room;
|
|
|
|
m_legacyName = m_room + "/" + m_legacyName;
|
|
|
|
}
|
|
|
|
|
2016-09-12 18:20:58 +02:00
|
|
|
void Conversation::cacheMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message) {
|
2013-02-17 17:13:14 +01:00
|
|
|
boost::posix_time::ptime timestamp = boost::posix_time::second_clock::universal_time();
|
2016-09-12 18:20:58 +02:00
|
|
|
SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Delay> delay(SWIFTEN_SHRPTR_NAMESPACE::make_shared<Swift::Delay>());
|
2013-02-17 17:13:14 +01:00
|
|
|
delay->setStamp(timestamp);
|
|
|
|
message->addPayload(delay);
|
|
|
|
m_cachedMessages.push_back(message);
|
|
|
|
if (m_cachedMessages.size() > 100) {
|
|
|
|
m_cachedMessages.pop_front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-12 18:20:58 +02:00
|
|
|
void Conversation::handleRawMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message) {
|
2013-02-09 11:09:38 +01:00
|
|
|
if (message->getType() != Swift::Message::Groupchat) {
|
|
|
|
if (m_conversationManager->getComponent()->inServerMode() && m_conversationManager->getUser()->shouldCacheMessages()) {
|
2013-02-17 17:13:14 +01:00
|
|
|
cacheMessage(message);
|
2013-02-09 11:09:38 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-11-16 10:49:10 +01:00
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendMessage(message);
|
2013-02-09 11:09:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (m_jids.empty()) {
|
2013-02-17 17:13:14 +01:00
|
|
|
cacheMessage(message);
|
2013-02-09 11:09:38 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BOOST_FOREACH(const Swift::JID &jid, m_jids) {
|
|
|
|
message->setTo(jid);
|
|
|
|
// Subject has to be sent after our own presence (the one with code 110)
|
2016-02-10 17:02:06 +01:00
|
|
|
if (!message->getSubject().empty()) {
|
2013-02-09 11:09:38 +01:00
|
|
|
m_subject = message;
|
2016-02-10 17:02:06 +01:00
|
|
|
if (m_sentInitialPresence == false) {
|
2016-02-18 12:25:29 +01:00
|
|
|
LOG4CXX_INFO(logger, m_jid.toString() << ": Caching subject message, initial presence not sent yet.");
|
2016-02-10 17:02:06 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-02-18 12:25:29 +01:00
|
|
|
else {
|
|
|
|
LOG4CXX_INFO(logger, m_jid.toString() << ": Forwarding subject message.");
|
|
|
|
}
|
2013-02-09 11:09:38 +01:00
|
|
|
}
|
2015-11-16 10:49:10 +01:00
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendMessage(message);
|
2013-02-09 11:09:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-12 18:20:58 +02:00
|
|
|
void Conversation::handleMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message, const std::string &nickname) {
|
2011-05-19 00:05:17 +02:00
|
|
|
if (m_muc) {
|
2011-05-18 16:25:52 +02:00
|
|
|
message->setType(Swift::Message::Groupchat);
|
|
|
|
}
|
|
|
|
else {
|
2012-12-18 12:56:38 +01:00
|
|
|
if (message->getType() == Swift::Message::Headline) {
|
|
|
|
if (m_conversationManager->getUser()->getUserSetting("send_headlines") != "1") {
|
2012-12-18 10:59:52 +01:00
|
|
|
message->setType(Swift::Message::Chat);
|
|
|
|
}
|
|
|
|
}
|
2012-12-18 12:56:38 +01:00
|
|
|
else {
|
|
|
|
message->setType(Swift::Message::Chat);
|
|
|
|
}
|
2011-05-18 16:25:52 +02:00
|
|
|
}
|
2011-11-11 11:40:10 +01:00
|
|
|
|
2011-11-24 12:24:26 +01:00
|
|
|
std::string n = nickname;
|
|
|
|
if (n.empty() && !m_room.empty() && !m_muc) {
|
|
|
|
n = m_nickname;
|
|
|
|
}
|
|
|
|
|
2011-05-17 09:44:29 +02:00
|
|
|
if (message->getType() != Swift::Message::Groupchat) {
|
2011-11-11 11:40:10 +01:00
|
|
|
message->setTo(m_jid);
|
2011-05-18 16:25:52 +02:00
|
|
|
// normal message
|
2011-11-24 12:24:26 +01:00
|
|
|
if (n.empty()) {
|
2011-05-18 16:25:52 +02:00
|
|
|
Buddy *buddy = m_conversationManager->getUser()->getRosterManager()->getBuddy(m_legacyName);
|
|
|
|
if (buddy) {
|
|
|
|
message->setFrom(buddy->getJID());
|
|
|
|
}
|
|
|
|
else {
|
2012-10-29 14:08:54 +01:00
|
|
|
std::string name = m_legacyName;
|
|
|
|
if (CONFIG_BOOL_DEFAULTED(m_conversationManager->getComponent()->getConfig(), "service.jid_escaping", true)) {
|
|
|
|
name = Swift::JID::getEscapedNode(m_legacyName);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (name.find_last_of("@") != std::string::npos) {
|
|
|
|
name.replace(name.find_last_of("@"), 1, "%");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
message->setFrom(Swift::JID(name, m_conversationManager->getComponent()->getJID().toBare(), "bot"));
|
2011-05-18 16:25:52 +02:00
|
|
|
}
|
2011-05-17 09:44:29 +02:00
|
|
|
}
|
2011-05-18 16:25:52 +02:00
|
|
|
// PM message
|
2011-05-17 09:44:29 +02:00
|
|
|
else {
|
2011-05-19 00:05:17 +02:00
|
|
|
if (m_room.empty()) {
|
2011-11-24 12:24:26 +01:00
|
|
|
message->setFrom(Swift::JID(n, m_conversationManager->getComponent()->getJID().toBare(), "user"));
|
2011-05-19 00:05:17 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-01-27 18:13:25 +01:00
|
|
|
std::string legacyName = m_room;
|
2016-02-04 15:12:23 +01:00
|
|
|
if (!m_mucEscaping && legacyName.find_last_of("@") != std::string::npos) {
|
2013-01-27 18:13:25 +01:00
|
|
|
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
|
|
|
|
}
|
2016-01-27 10:54:10 +01:00
|
|
|
legacyName = Swift::JID::getEscapedNode(legacyName);
|
2013-01-27 18:13:25 +01:00
|
|
|
message->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), n));
|
2011-05-19 00:05:17 +02:00
|
|
|
}
|
2011-05-17 09:44:29 +02:00
|
|
|
}
|
2011-04-01 23:54:29 +02:00
|
|
|
}
|
2011-05-18 16:25:52 +02:00
|
|
|
else {
|
2011-10-25 20:29:58 +02:00
|
|
|
std::string legacyName = m_legacyName;
|
2016-02-04 15:12:23 +01:00
|
|
|
if (!m_mucEscaping && legacyName.find_last_of("@") != std::string::npos) {
|
2011-10-25 20:29:58 +02:00
|
|
|
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
|
|
|
|
}
|
2016-01-27 10:54:10 +01:00
|
|
|
legacyName = Swift::JID::getEscapedNode(legacyName);
|
2012-07-30 13:52:29 +02:00
|
|
|
|
|
|
|
std::string n = nickname;
|
|
|
|
if (n.empty()) {
|
|
|
|
n = " ";
|
|
|
|
}
|
2012-12-21 09:26:34 +01:00
|
|
|
|
2016-02-08 09:26:34 +01:00
|
|
|
std::map<std::string, Participant>::iterator it = m_participants.find(n);
|
|
|
|
if (it != m_participants.end() && !it->second.alias.empty()) {
|
|
|
|
n = it->second.alias;
|
|
|
|
}
|
|
|
|
|
2012-12-21 09:26:34 +01:00
|
|
|
message->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), n));
|
2015-11-25 16:02:23 +01:00
|
|
|
LOG4CXX_INFO(logger, "MSG FROM " << message->getFrom().toString());
|
2011-05-18 16:25:52 +02:00
|
|
|
}
|
2013-02-09 11:09:38 +01:00
|
|
|
|
|
|
|
handleRawMessage(message);
|
2011-05-17 09:44:29 +02:00
|
|
|
}
|
|
|
|
|
2015-12-07 18:17:04 +01:00
|
|
|
std::string Conversation::getParticipants() {
|
|
|
|
std::string ret;
|
2016-02-08 09:26:34 +01:00
|
|
|
for (std::map<std::string, Participant>::iterator it = m_participants.begin(); it != m_participants.end(); it++) {
|
|
|
|
ret += (*it).second.presence->getFrom().getResource() + ", ";
|
2015-12-07 18:17:04 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-10 17:02:06 +01:00
|
|
|
void Conversation::sendParticipants(const Swift::JID &to, const std::string &nickname) {
|
|
|
|
// When user tries to join this room from another resource using
|
|
|
|
// different nickname than the original one has, we have to rename
|
|
|
|
// him.
|
2016-02-17 17:52:16 +01:00
|
|
|
LOG4CXX_INFO(logger, m_jid.toString() << ": Sending participants to " << to.toString() << ", Nickname:" << nickname << ", Conversation nickname:" << m_nickname);
|
2016-02-10 17:02:06 +01:00
|
|
|
if (m_nickname != nickname && !nickname.empty()) {
|
|
|
|
Swift::Presence::ref presence;
|
|
|
|
std::string tmp = m_nickname;
|
|
|
|
|
|
|
|
// At first connect the user.
|
|
|
|
m_nickname = nickname;
|
|
|
|
presence = generatePresence(nickname, 0, (int) Swift::StatusShow::Online, "", "", "");
|
|
|
|
presence->setTo(to);
|
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendPresence(presence);
|
|
|
|
|
|
|
|
// Now change his nickname to the right one.
|
|
|
|
m_nicknameChanged = true;
|
|
|
|
presence = generatePresence(nickname, 0, (int) Swift::StatusShow::Online, "", tmp, "");
|
|
|
|
presence->setTo(to);
|
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendPresence(presence);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-18 07:34:59 +01:00
|
|
|
// Self presence has to be sent as first.
|
|
|
|
Swift::Presence::ref presence = generatePresence(m_nickname, 0, (int) Swift::StatusShow::Online, "", "", "");
|
|
|
|
presence->setTo(to);
|
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendPresence(presence);
|
|
|
|
|
2016-02-08 09:26:34 +01:00
|
|
|
for (std::map<std::string, Participant>::iterator it = m_participants.begin(); it != m_participants.end(); it++) {
|
|
|
|
(*it).second.presence->setTo(to);
|
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendPresence((*it).second.presence);
|
2012-09-23 09:48:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-21 09:26:34 +01:00
|
|
|
void Conversation::sendCachedMessages(const Swift::JID &to) {
|
2016-09-12 18:20:58 +02:00
|
|
|
for (std::list<SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> >::const_iterator it = m_cachedMessages.begin(); it != m_cachedMessages.end(); it++) {
|
2012-12-21 11:20:05 +01:00
|
|
|
if (to.isValid()) {
|
|
|
|
(*it)->setTo(to);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
(*it)->setTo(m_jid.toBare());
|
|
|
|
}
|
2015-11-16 10:49:10 +01:00
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendMessage(*it);
|
2012-12-21 09:26:34 +01:00
|
|
|
}
|
2013-02-26 09:31:57 +01:00
|
|
|
|
|
|
|
if (m_subject) {
|
|
|
|
if (to.isValid()) {
|
|
|
|
m_subject->setTo(to);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_subject->setTo(m_jid.toBare());
|
|
|
|
}
|
2015-11-16 10:49:10 +01:00
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendMessage(m_subject);
|
2013-02-26 09:31:57 +01:00
|
|
|
}
|
|
|
|
|
2012-12-21 09:26:34 +01:00
|
|
|
m_cachedMessages.clear();
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:50:53 +01:00
|
|
|
Swift::Presence::ref Conversation::generatePresence(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname, const std::string &iconhash) {
|
2011-05-18 15:19:56 +02:00
|
|
|
std::string nickname = nick;
|
2011-05-17 09:44:29 +02:00
|
|
|
Swift::Presence::ref presence = Swift::Presence::create();
|
2011-10-25 20:29:58 +02:00
|
|
|
std::string legacyName = m_legacyName;
|
|
|
|
if (m_muc) {
|
2016-02-04 15:12:23 +01:00
|
|
|
if (!m_mucEscaping && legacyName.find_last_of("@") != std::string::npos) {
|
2011-10-25 20:29:58 +02:00
|
|
|
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
|
|
|
|
}
|
2016-01-27 10:54:10 +01:00
|
|
|
legacyName = Swift::JID::getEscapedNode(legacyName);
|
2011-10-25 20:29:58 +02:00
|
|
|
}
|
|
|
|
presence->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname));
|
2011-05-17 09:44:29 +02:00
|
|
|
presence->setType(Swift::Presence::Available);
|
|
|
|
|
2011-05-19 08:26:09 +02:00
|
|
|
if (!statusMessage.empty())
|
|
|
|
presence->setStatus(statusMessage);
|
|
|
|
|
|
|
|
Swift::StatusShow s((Swift::StatusShow::Type) status);
|
|
|
|
|
2011-06-23 17:23:37 +02:00
|
|
|
if (s.getType() == Swift::StatusShow::None) {
|
2011-05-19 08:26:09 +02:00
|
|
|
presence->setType(Swift::Presence::Unavailable);
|
2011-06-23 17:23:37 +02:00
|
|
|
}
|
|
|
|
|
2011-05-19 08:26:09 +02:00
|
|
|
presence->setShow(s.getType());
|
|
|
|
|
2011-05-17 09:44:29 +02:00
|
|
|
Swift::MUCUserPayload *p = new Swift::MUCUserPayload ();
|
|
|
|
if (m_nickname == nickname) {
|
2013-01-24 08:35:24 +01:00
|
|
|
if (flag & PARTICIPANT_FLAG_CONFLICT) {
|
|
|
|
delete p;
|
|
|
|
presence->setType(Swift::Presence::Error);
|
2016-09-12 18:20:58 +02:00
|
|
|
presence->addPayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Payload>(new Swift::MUCPayload()));
|
|
|
|
presence->addPayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Payload>(new Swift::ErrorPayload(Swift::ErrorPayload::Conflict)));
|
2016-02-28 14:43:59 +01:00
|
|
|
LOG4CXX_INFO(logger, m_jid.toString() << ": Generating error presence: PARTICIPANT_FLAG_CONFLICT");
|
2013-01-24 08:35:24 +01:00
|
|
|
return presence;
|
|
|
|
}
|
|
|
|
else if (flag & PARTICIPANT_FLAG_NOT_AUTHORIZED) {
|
|
|
|
delete p;
|
|
|
|
presence->setType(Swift::Presence::Error);
|
2016-09-12 18:20:58 +02:00
|
|
|
presence->addPayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Payload>(new Swift::MUCPayload()));
|
|
|
|
presence->addPayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Payload>(new Swift::ErrorPayload(Swift::ErrorPayload::NotAuthorized, Swift::ErrorPayload::Auth, statusMessage)));
|
2016-02-28 14:43:59 +01:00
|
|
|
LOG4CXX_INFO(logger, m_jid.toString() << ": Generating error presence: PARTICIPANT_FLAG_NOT_AUTHORIZED");
|
2013-02-12 09:30:24 +01:00
|
|
|
return presence;
|
|
|
|
}
|
|
|
|
else if (flag & PARTICIPANT_FLAG_ROOM_NOT_FOUD) {
|
|
|
|
delete p;
|
|
|
|
presence->setType(Swift::Presence::Error);
|
2016-09-12 18:20:58 +02:00
|
|
|
presence->addPayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Payload>(new Swift::MUCPayload()));
|
|
|
|
presence->addPayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Payload>(new Swift::ErrorPayload(Swift::ErrorPayload::ItemNotFound, Swift::ErrorPayload::Cancel, statusMessage)));
|
2016-02-28 14:43:59 +01:00
|
|
|
LOG4CXX_INFO(logger, m_jid.toString() << ": Generating error presence: PARTICIPANT_FLAG_ROOM_NOT_FOUND");
|
2013-01-24 08:35:24 +01:00
|
|
|
return presence;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Swift::MUCUserPayload::StatusCode c;
|
|
|
|
c.code = 110;
|
|
|
|
p->addStatusCode(c);
|
2013-02-26 15:31:21 +01:00
|
|
|
if (m_nicknameChanged) {
|
|
|
|
Swift::MUCUserPayload::StatusCode c;
|
|
|
|
c.code = 210;
|
|
|
|
p->addStatusCode(c);
|
2016-02-09 08:01:04 +01:00
|
|
|
m_nicknameChanged = false;
|
2013-02-26 15:31:21 +01:00
|
|
|
}
|
2013-01-24 08:35:24 +01:00
|
|
|
m_sentInitialPresence = true;
|
|
|
|
}
|
2011-04-01 23:54:29 +02:00
|
|
|
}
|
2011-05-19 00:33:38 +02:00
|
|
|
|
2013-01-24 08:35:24 +01:00
|
|
|
|
2011-09-26 21:09:41 +02:00
|
|
|
Swift::MUCItem item;
|
|
|
|
|
|
|
|
item.affiliation = Swift::MUCOccupant::Member;
|
|
|
|
item.role = Swift::MUCOccupant::Participant;
|
2011-05-19 08:26:09 +02:00
|
|
|
|
2013-01-23 19:41:56 +01:00
|
|
|
if (flag & PARTICIPANT_FLAG_MODERATOR) {
|
2011-09-26 21:09:41 +02:00
|
|
|
item.affiliation = Swift::MUCOccupant::Admin;
|
|
|
|
item.role = Swift::MUCOccupant::Moderator;
|
2011-05-19 08:26:09 +02:00
|
|
|
}
|
|
|
|
|
2011-05-19 00:33:38 +02:00
|
|
|
if (!newname.empty()) {
|
|
|
|
item.nick = newname;
|
|
|
|
Swift::MUCUserPayload::StatusCode c;
|
|
|
|
c.code = 303;
|
|
|
|
p->addStatusCode(c);
|
2011-05-19 08:26:09 +02:00
|
|
|
presence->setType(Swift::Presence::Unavailable);
|
2011-05-19 00:33:38 +02:00
|
|
|
}
|
2016-02-06 15:50:53 +01:00
|
|
|
|
|
|
|
if (!iconhash.empty()) {
|
2016-09-12 18:20:58 +02:00
|
|
|
presence->addPayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Payload>(new Swift::VCardUpdate (iconhash)));
|
2016-02-06 15:50:53 +01:00
|
|
|
}
|
2013-01-24 08:35:24 +01:00
|
|
|
|
2011-05-19 00:33:38 +02:00
|
|
|
p->addItem(item);
|
2016-09-12 18:20:58 +02:00
|
|
|
presence->addPayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Payload>(p));
|
2012-09-23 09:48:03 +02:00
|
|
|
return presence;
|
|
|
|
}
|
|
|
|
|
2013-02-26 15:43:32 +01:00
|
|
|
|
2013-02-26 15:31:21 +01:00
|
|
|
void Conversation::setNickname(const std::string &nickname) {
|
|
|
|
if (!nickname.empty() && m_nickname != nickname) {
|
|
|
|
m_nicknameChanged = true;
|
|
|
|
}
|
|
|
|
m_nickname = nickname;
|
|
|
|
}
|
|
|
|
|
2013-02-22 09:45:31 +01:00
|
|
|
void Conversation::handleRawPresence(Swift::Presence::ref presence) {
|
|
|
|
// TODO: Detect nickname change.
|
2015-11-16 10:49:10 +01:00
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendPresence(presence);
|
2016-02-08 09:26:34 +01:00
|
|
|
m_participants[presence->getFrom().getResource()].presence = presence;
|
2013-02-22 09:45:31 +01:00
|
|
|
}
|
|
|
|
|
2016-02-08 20:13:43 +01:00
|
|
|
void Conversation::removeJID(const Swift::JID &jid) {
|
2016-02-19 10:24:13 +01:00
|
|
|
if (m_muc) {
|
|
|
|
Swift::Presence::ref presence = generatePresence(m_nickname, 0, Swift::StatusShow::None, "");
|
|
|
|
presence->setTo(jid);
|
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendPresence(presence);
|
|
|
|
}
|
2016-02-08 20:13:43 +01:00
|
|
|
m_jids.remove(jid);
|
|
|
|
}
|
|
|
|
|
2016-02-08 09:26:34 +01:00
|
|
|
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);
|
2012-09-23 09:48:03 +02:00
|
|
|
|
|
|
|
if (presence->getType() == Swift::Presence::Unavailable) {
|
|
|
|
m_participants.erase(nick);
|
|
|
|
}
|
|
|
|
else {
|
2016-02-08 09:26:34 +01:00
|
|
|
m_participants[nick].presence = presence;
|
|
|
|
m_participants[nick].alias = alias;
|
2012-09-23 09:48:03 +02:00
|
|
|
}
|
|
|
|
|
2012-09-22 20:19:19 +02:00
|
|
|
BOOST_FOREACH(const Swift::JID &jid, m_jids) {
|
|
|
|
presence->setTo(jid);
|
2015-11-16 10:49:10 +01:00
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendPresence(presence);
|
2012-09-22 20:19:19 +02:00
|
|
|
}
|
2011-05-19 08:26:09 +02:00
|
|
|
if (!newname.empty()) {
|
2016-02-06 15:50:53 +01:00
|
|
|
handleParticipantChanged(newname, flag, status, statusMessage, "", iconhash);
|
2011-05-19 08:26:09 +02:00
|
|
|
}
|
2012-11-27 12:51:19 +01:00
|
|
|
|
2016-02-10 17:02:06 +01:00
|
|
|
if (m_sentInitialPresence && !m_sentInitialSubject && m_subject) {
|
|
|
|
m_sentInitialSubject = true;
|
2015-11-16 10:49:10 +01:00
|
|
|
m_conversationManager->getComponent()->getFrontend()->sendMessage(m_subject);
|
2012-11-27 12:51:19 +01:00
|
|
|
}
|
2016-01-20 07:36:05 +01:00
|
|
|
|
|
|
|
// We send error presences only to inform user that he is disconnected
|
|
|
|
// from the room. This code must be extended in case we start sending error
|
|
|
|
// presences in other situations.
|
|
|
|
if (presence->getType() == Swift::Presence::Error) {
|
2016-02-28 14:43:59 +01:00
|
|
|
LOG4CXX_INFO(logger, m_jid.toString() << ": Leaving the conversation " << m_legacyName << " because of error.");
|
2016-01-20 07:36:05 +01:00
|
|
|
m_conversationManager->getUser()->leaveRoom(m_legacyName);
|
|
|
|
}
|
2011-04-01 23:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|