Files
@ 457d19d1ec41
Branch filter:
Location: libtransport.git/src/conversation.cpp - annotation
457d19d1ec41
3.8 KiB
text/x-c++hdr
Working join/rename
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 | 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 c8006a0ebab6 943dc1925b7c 76c678dd6f1d 76c678dd6f1d b5c026470f07 76c678dd6f1d 76c678dd6f1d 76c678dd6f1d 2add374fbd61 943dc1925b7c 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 0a33a3100eb9 2add374fbd61 0a33a3100eb9 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 0a33a3100eb9 2add374fbd61 0a33a3100eb9 943dc1925b7c 943dc1925b7c 943dc1925b7c 943dc1925b7c 943dc1925b7c 943dc1925b7c 0a33a3100eb9 0a33a3100eb9 76c678dd6f1d 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 2add374fbd61 0a33a3100eb9 0a33a3100eb9 457d19d1ec41 6699a898fbec 6699a898fbec 6699a898fbec 6699a898fbec 0a33a3100eb9 0a33a3100eb9 0a33a3100eb9 0a33a3100eb9 0a33a3100eb9 0a33a3100eb9 0a33a3100eb9 0a33a3100eb9 0a33a3100eb9 0a33a3100eb9 76c678dd6f1d 457d19d1ec41 457d19d1ec41 457d19d1ec41 457d19d1ec41 457d19d1ec41 457d19d1ec41 457d19d1ec41 457d19d1ec41 457d19d1ec41 457d19d1ec41 0a33a3100eb9 0a33a3100eb9 0a33a3100eb9 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->setConversation(this);
m_muc = isMUC;
}
Conversation::~Conversation() {
m_conversationManager->unsetConversation(this);
}
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);
}
if (message->getType() != Swift::Message::Groupchat) {
message->setTo(m_conversationManager->getUser()->getJID().toBare());
// normal message
if (nickname.empty()) {
Buddy *buddy = m_conversationManager->getUser()->getRosterManager()->getBuddy(m_legacyName);
if (buddy) {
std::cout << m_legacyName << " 222222\n";
message->setFrom(buddy->getJID());
}
else {
std::cout << m_legacyName << " 1111111\n";
// TODO: escape from and setFrom
}
}
// PM message
else {
if (m_room.empty()) {
message->setFrom(Swift::JID(nickname, m_conversationManager->getComponent()->getJID().toBare(), "user"));
}
else {
message->setFrom(Swift::JID(m_room, m_conversationManager->getComponent()->getJID().toBare(), nickname));
}
}
m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
}
else {
message->setTo(m_conversationManager->getUser()->getJID().toString());
message->setFrom(Swift::JID(m_legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname));
m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
}
}
void Conversation::handleParticipantChanged(const std::string &nick, int flag, const std::string &newname) {
std::string nickname = nick;
if (nickname.find("@") == 0) {
nickname = nickname.substr(1);
}
Swift::Presence::ref presence = Swift::Presence::create();
presence->setFrom(Swift::JID(m_legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname));
presence->setTo(m_conversationManager->getUser()->getJID().toString());
presence->setType(Swift::Presence::Available);
Swift::MUCUserPayload *p = new Swift::MUCUserPayload ();
if (m_nickname == nickname) {
Swift::MUCUserPayload::StatusCode c;
c.code = 110;
p->addStatusCode(c);
}
Swift::MUCUserPayload::Item item(Swift::MUCOccupant::Member, Swift::MUCOccupant::Participant);
if (!newname.empty()) {
item.nick = newname;
Swift::MUCUserPayload::StatusCode c;
c.code = 303;
p->addStatusCode(c);
}
p->addItem(item);
presence->addPayload(boost::shared_ptr<Swift::Payload>(p));
m_conversationManager->getComponent()->getStanzaChannel()->sendPresence(presence);
}
}
|