Files
@ e062a79b1f8e
Branch filter:
Location: libtransport.git/src/abstractbuddy.cpp
e062a79b1f8e
3.8 KiB
text/x-c++hdr
Store also jid in db...
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 | /**
* 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 "transport/abstractbuddy.h"
#include "transport/rostermanager.h"
#include "transport/user.h"
#include "transport/transport.h"
namespace Transport {
AbstractBuddy::AbstractBuddy(RosterManager *rosterManager, long id) : m_id(id), m_online(false), m_subscription("ask"), m_flags(BUDDY_NO_FLAG), m_rosterManager(rosterManager){
m_rosterManager->setBuddy(this);
}
AbstractBuddy::~AbstractBuddy() {
m_rosterManager->unsetBuddy(this);
}
void AbstractBuddy::generateJID() {
m_jid = Swift::JID();
m_jid = Swift::JID(getSafeName(), m_rosterManager->getUser()->getComponent()->getJID().toString(), "bot");
}
void AbstractBuddy::setID(long id) {
m_id = id;
}
long AbstractBuddy::getID() {
return m_id;
}
void AbstractBuddy::setFlags(BuddyFlag flags) {
m_flags = flags;
generateJID();
}
BuddyFlag AbstractBuddy::getFlags() {
return m_flags;
}
const Swift::JID &AbstractBuddy::getJID(const std::string &hostname) {
if (!m_jid.isValid()) {
generateJID();
}
return m_jid;
}
void AbstractBuddy::setOnline() {
m_online = true;
}
void AbstractBuddy::setOffline() {
m_online = false;
m_lastPresence = Swift::Presence::ref();
}
bool AbstractBuddy::isOnline() {
return m_online;
}
void AbstractBuddy::setSubscription(const std::string &subscription) {
m_subscription = subscription;
}
const std::string &AbstractBuddy::getSubscription() {
return m_subscription;
}
Swift::Presence::ref AbstractBuddy::generatePresenceStanza(int features, bool only_new) {
std::string alias = getAlias();
std::string name = getSafeName();
Swift::StatusShow s;
std::string statusMessage;
if (!getStatus(s, statusMessage))
return Swift::Presence::ref();
Swift::Presence::ref presence = Swift::Presence::create();
// presence->setFrom(getJID());
presence->setType(Swift::Presence::Available);
if (!statusMessage.empty())
presence->setStatus(statusMessage);
if (s.getType() == Swift::StatusShow::None)
presence->setType(Swift::Presence::Unavailable);
presence->setShow(s.getType());
if (presence->getType() != Swift::Presence::Unavailable) {
// caps
// presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::CapsInfo (CONFIG().caps)));
if (features & 0/*TRANSPORT_FEATURE_AVATARS*/) {
presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::VCardUpdate (getIconHash())));
}
}
if (only_new) {
if (m_lastPresence)
m_lastPresence->setTo(Swift::JID(""));
if (m_lastPresence == presence) {
return Swift::Presence::ref();
}
m_lastPresence = presence;
}
return presence;
}
std::string AbstractBuddy::getSafeName() {
if (m_jid.isValid()) {
return m_jid.getNode();
}
std::string name = getName();
// Transport::instance()->protocol()->prepareUsername(name, purple_buddy_get_account(m_buddy));
if (getFlags() & BUDDY_JID_ESCAPING) {
name = Swift::JID::getEscapedNode(name);
}
else {
if (name.find_last_of("@") != std::string::npos) {
name.replace(name.find_last_of("@"), 1, "%");
}
}
// if (name.empty()) {
// Log("SpectrumBuddy::getSafeName", "Name is EMPTY! Previous was " << getName() << ".");
// }
return name;
}
}
|