Files
@ 150afaed9002
Branch filter:
Location: libtransport.git/src/conversation.cpp - annotation
150afaed9002
7.3 KiB
text/x-c++hdr
Removed m_modes and m_away and introduced IRCBuddy in communi backend
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d b5c026470f07 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d b5c026470f07 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 943dc1925b7c 76c678dd6f1d 1a11965611f7 943dc1925b7c 5b89dae8ca9a 8b6973539f23 76c678dd6f1d 76c678dd6f1d b5c026470f07 76c678dd6f1d 76c678dd6f1d 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 3ff7f9249074 3ff7f9249074 3ff7f9249074 3ff7f9249074 4717bd007185 4717bd007185 4717bd007185 4717bd007185 4717bd007185 8c529dbabbbc 8c529dbabbbc 8c529dbabbbc 8c529dbabbbc 8c529dbabbbc 2add374fbd61 943dc1925b7c 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 5b89dae8ca9a ff3adaa3f33f ff3adaa3f33f ff3adaa3f33f ff3adaa3f33f ff3adaa3f33f 0a33a3100eb9 5b89dae8ca9a 2add374fbd61 ff3adaa3f33f 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 df3276119498 df3276119498 df3276119498 df3276119498 df3276119498 df3276119498 df3276119498 df3276119498 df3276119498 df3276119498 df3276119498 2add374fbd61 0a33a3100eb9 2add374fbd61 0a33a3100eb9 943dc1925b7c ff3adaa3f33f 943dc1925b7c 943dc1925b7c ff3adaa3f33f 943dc1925b7c 0a33a3100eb9 0a33a3100eb9 76c678dd6f1d 2add374fbd61 8c529dbabbbc 8c529dbabbbc 8c529dbabbbc 8c529dbabbbc e14d3c30e92e e14d3c30e92e e14d3c30e92e e14d3c30e92e e14d3c30e92e 88607aff3c0b 88607aff3c0b 88607aff3c0b 8b6973539f23 8b6973539f23 8b6973539f23 8b6973539f23 8b6973539f23 88607aff3c0b 88607aff3c0b 2add374fbd61 0a33a3100eb9 0a33a3100eb9 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 6699a898fbec 0a33a3100eb9 8c529dbabbbc 8c529dbabbbc 8c529dbabbbc 8c529dbabbbc 8c529dbabbbc 8c529dbabbbc 8c529dbabbbc 0a33a3100eb9 0a33a3100eb9 8e03fbec4701 8e03fbec4701 8e03fbec4701 8e03fbec4701 8e03fbec4701 99d1c435b90f 8e03fbec4701 99d1c435b90f 99d1c435b90f 8e03fbec4701 8e03fbec4701 0a33a3100eb9 0a33a3100eb9 0a33a3100eb9 0a33a3100eb9 0a33a3100eb9 8b6973539f23 76c678dd6f1d 457d19d1ec41 8e03fbec4701 19786b3bb708 19786b3bb708 19786b3bb708 19786b3bb708 8e03fbec4701 8e03fbec4701 19786b3bb708 19786b3bb708 8e03fbec4701 8e03fbec4701 457d19d1ec41 457d19d1ec41 457d19d1ec41 457d19d1ec41 457d19d1ec41 8e03fbec4701 457d19d1ec41 457d19d1ec41 457d19d1ec41 0a33a3100eb9 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 1055c577d2d3 88607aff3c0b 88607aff3c0b 88607aff3c0b 88607aff3c0b 8e03fbec4701 8e03fbec4701 8e03fbec4701 8b6973539f23 8b6973539f23 8b6973539f23 8b6973539f23 8b6973539f23 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d | /**
* 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>
#include "transport/conversation.h"
#include "transport/conversationmanager.h"
#include "transport/user.h"
#include "transport/transport.h"
#include "transport/buddy.h"
#include "transport/rostermanager.h"
namespace Transport {
Conversation::Conversation(ConversationManager *conversationManager, const std::string &legacyName, bool isMUC) : m_conversationManager(conversationManager) {
m_legacyName = legacyName;
// m_conversationManager->addConversation(this);
m_muc = isMUC;
m_jid = m_conversationManager->getUser()->getJID().toBare();
m_sentInitialPresence = false;
}
Conversation::~Conversation() {
}
void Conversation::destroyRoom() {
if (m_muc) {
Swift::Presence::ref presence = Swift::Presence::create();
std::string legacyName = m_legacyName;
if (legacyName.find_last_of("@") != std::string::npos) {
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
}
presence->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), m_nickname));
presence->setTo(m_jid);
presence->setType(Swift::Presence::Unavailable);
Swift::MUCItem item;
item.affiliation = Swift::MUCOccupant::NoAffiliation;
item.role = Swift::MUCOccupant::NoRole;
Swift::MUCUserPayload *p = new Swift::MUCUserPayload ();
p->addItem(item);
Swift::MUCUserPayload::StatusCode c;
c.code = 332;
p->addStatusCode(c);
presence->addPayload(boost::shared_ptr<Swift::Payload>(p));
m_conversationManager->getComponent()->getStanzaChannel()->sendPresence(presence);
}
}
void Conversation::setRoom(const std::string &room) {
m_room = room;
m_legacyName = m_room + "/" + m_legacyName;
}
void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, const std::string &nickname) {
if (m_muc) {
message->setType(Swift::Message::Groupchat);
}
else {
message->setType(Swift::Message::Chat);
}
std::string n = nickname;
if (n.empty() && !m_room.empty() && !m_muc) {
n = m_nickname;
}
if (message->getType() != Swift::Message::Groupchat) {
message->setTo(m_jid);
// normal message
if (n.empty()) {
Buddy *buddy = m_conversationManager->getUser()->getRosterManager()->getBuddy(m_legacyName);
if (buddy) {
message->setFrom(buddy->getJID());
}
else {
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"));
}
}
// PM message
else {
if (m_room.empty()) {
message->setFrom(Swift::JID(n, m_conversationManager->getComponent()->getJID().toBare(), "user"));
}
else {
message->setFrom(Swift::JID(m_room, m_conversationManager->getComponent()->getJID().toBare(), n));
}
}
m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
}
else {
std::string legacyName = m_legacyName;
if (legacyName.find_last_of("@") != std::string::npos) {
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
}
std::string n = nickname;
if (n.empty()) {
n = " ";
}
BOOST_FOREACH(const Swift::JID &jid, m_jids) {
message->setTo(jid);
message->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), n));
// Subject has to be sent after our own presence (the one with code 110)
if (!message->getSubject().empty() && m_sentInitialPresence == false) {
m_subject = message;
return;
}
m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
}
}
}
void Conversation::sendParticipants(const Swift::JID &to) {
for (std::map<std::string, Participant>::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;
if (m_muc) {
if (legacyName.find_last_of("@") != std::string::npos) {
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
}
}
presence->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname));
presence->setType(Swift::Presence::Available);
if (!statusMessage.empty())
presence->setStatus(statusMessage);
Swift::StatusShow s((Swift::StatusShow::Type) status);
if (s.getType() == Swift::StatusShow::None) {
presence->setType(Swift::Presence::Unavailable);
}
presence->setShow(s.getType());
Swift::MUCUserPayload *p = new Swift::MUCUserPayload ();
if (m_nickname == nickname) {
Swift::MUCUserPayload::StatusCode c;
c.code = 110;
p->addStatusCode(c);
m_sentInitialPresence = true;
}
Swift::MUCItem item;
item.affiliation = Swift::MUCOccupant::Member;
item.role = Swift::MUCOccupant::Participant;
if (flag & Moderator) {
item.affiliation = Swift::MUCOccupant::Admin;
item.role = Swift::MUCOccupant::Moderator;
}
if (!newname.empty()) {
item.nick = newname;
Swift::MUCUserPayload::StatusCode c;
c.code = 303;
p->addStatusCode(c);
presence->setType(Swift::Presence::Unavailable);
}
p->addItem(item);
presence->addPayload(boost::shared_ptr<Swift::Payload>(p));
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);
}
if (m_sentInitialPresence && m_subject) {
m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(m_subject);
m_subject.reset();
}
}
}
|