2011-05-11 09:20:35 +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
|
|
|
|
*/
|
|
|
|
|
2015-11-18 14:05:57 +01:00
|
|
|
#include "transport/LocalBuddy.h"
|
|
|
|
#include "transport/User.h"
|
|
|
|
#include "transport/RosterManager.h"
|
|
|
|
#include "transport/Transport.h"
|
2016-02-06 07:57:48 +01:00
|
|
|
#include "transport/Frontend.h"
|
2011-05-11 09:20:35 +02:00
|
|
|
|
|
|
|
namespace Transport {
|
|
|
|
|
2012-08-09 11:21:01 +02:00
|
|
|
LocalBuddy::LocalBuddy(RosterManager *rosterManager, long id, const std::string &name, const std::string &alias, const std::vector<std::string> &groups, BuddyFlag flags) : Buddy(rosterManager, id, flags) {
|
2011-06-09 12:46:49 +02:00
|
|
|
m_status = Swift::StatusShow::None;
|
2012-08-09 11:21:01 +02:00
|
|
|
m_alias = alias;
|
|
|
|
m_name = name;
|
|
|
|
m_groups = groups;
|
|
|
|
try {
|
|
|
|
generateJID();
|
|
|
|
} catch (...) {
|
|
|
|
}
|
2011-05-11 09:20:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LocalBuddy::~LocalBuddy() {
|
|
|
|
}
|
|
|
|
|
2013-01-12 10:09:35 +01:00
|
|
|
void LocalBuddy::setStatus(const Swift::StatusShow &status, const std::string &statusMessage) {
|
|
|
|
bool changed = ((m_status.getType() != status.getType()) || (m_statusMessage != statusMessage));
|
|
|
|
if (changed) {
|
|
|
|
m_status = status;
|
|
|
|
m_statusMessage = statusMessage;
|
|
|
|
sendPresence();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalBuddy::setIconHash(const std::string &iconHash) {
|
|
|
|
bool changed = m_iconHash != iconHash;
|
|
|
|
m_iconHash = iconHash;
|
|
|
|
if (changed) {
|
|
|
|
getRosterManager()->storeBuddy(this);
|
|
|
|
sendPresence();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 07:47:18 +02:00
|
|
|
bool LocalBuddy::setName(const std::string &name) {
|
|
|
|
if (name == m_name) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
std::string oldName = name;
|
|
|
|
m_name = name;
|
|
|
|
try {
|
|
|
|
generateJID();
|
2012-08-07 17:41:13 +02:00
|
|
|
return m_jid.isValid();
|
2012-08-02 07:47:18 +02:00
|
|
|
} catch (...) {
|
|
|
|
m_name = oldName;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-19 21:40:03 +02:00
|
|
|
void LocalBuddy::setAlias(const std::string &alias) {
|
|
|
|
bool changed = m_alias != alias;
|
|
|
|
m_alias = alias;
|
|
|
|
|
|
|
|
if (changed) {
|
2015-11-16 10:49:10 +01:00
|
|
|
getRosterManager()->doUpdateBuddy(this);
|
2011-06-19 21:40:03 +02:00
|
|
|
getRosterManager()->storeBuddy(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-10 18:49:40 +02:00
|
|
|
void LocalBuddy::setGroups(const std::vector<std::string> &groups) {
|
|
|
|
bool changed = m_groups.size() != groups.size();
|
|
|
|
if (!changed) {
|
|
|
|
for (int i = 0; i != m_groups.size(); i++) {
|
|
|
|
if (m_groups[i] != groups[i]) {
|
|
|
|
changed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_groups = groups;
|
|
|
|
if (changed) {
|
2015-11-16 10:49:10 +01:00
|
|
|
getRosterManager()->doUpdateBuddy(this);
|
2012-04-10 18:49:40 +02:00
|
|
|
getRosterManager()->storeBuddy(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 09:45:31 +01:00
|
|
|
bool LocalBuddy::getStatus(Swift::StatusShow &status, std::string &statusMessage) {
|
2016-02-06 07:57:48 +01:00
|
|
|
if (getRosterManager()->getUser()->getComponent()->getFrontend()->isRawXMLEnabled()) {
|
2013-02-22 09:45:31 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
status = m_status;
|
|
|
|
statusMessage = m_statusMessage;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-11 09:20:35 +02:00
|
|
|
}
|