Files
@ eaa9d7f3bd43
Branch filter:
Location: libtransport.git/src/abstractbuddy.cpp
eaa9d7f3bd43
2.8 KiB
text/x-c++hdr
AbstractBuddy and SpectrumBuddy
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 | /**
* 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"
AbstractBuddy::AbstractBuddy(long id) : m_id(id), m_online(false), m_subscription("ask"), m_flags(0) {
}
AbstractBuddy::~AbstractBuddy() {
}
void AbstractBuddy::setId(long id) {
m_id = id;
}
long AbstractBuddy::getId() {
return m_id;
}
void AbstractBuddy::setFlags(int flags) {
m_flags = flags;
}
int AbstractBuddy::getFlags() {
return m_flags;
}
Swift::JID AbstractBuddy::getJID(const std::string &hostname) {
return Swift::JID(getSafeName(), hostname, "bot");
}
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;
}
|