Files
@ 62f3fbf99c88
Branch filter:
Location: libtransport.git/include/transport/buddy.h
62f3fbf99c88
4.5 KiB
text/plain
Buddy::JIDToLegacyName
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 | /**
* 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
*/
#pragma once
#include <string>
#include <algorithm>
#include "transport/transport.h"
#include "Swiften/Swiften.h"
namespace Transport {
class RosterManager;
typedef enum { BUDDY_NO_FLAG = 0,
BUDDY_JID_ESCAPING = 2,
BUDDY_IGNORE = 4
} BuddyFlag;
/// Represents one legacy network Buddy.
class Buddy {
public:
/// Constructor.
Buddy(RosterManager *rosterManager, long id);
/// Destructor
virtual ~Buddy();
/// Sets unique ID used to identify this buddy by StorageBackend. This is set
/// by RosterStorage class once the buddy is stored into database or when the
/// buddy is loaded from database.
/// You should not need to set this ID manually.
/// \param id ID
void setID(long id);
/// Returns unique ID used to identify this buddy by StorageBackend.
/// \see Buddy::setID(long)
/// \return ID
long getID();
/// Returns full JID of this buddy.
/// \param hostname hostname used as domain in returned JID
/// \return full JID of this buddy
const Swift::JID &getJID();
/// Generates whole Presennce stanza with current status/show for this buddy.
/// Presence stanza does not containt "to" attribute, it has to be added manually.
/// \param features features used in returned stanza
/// \param only_new if True, this function returns Presence stanza only if it's different
/// than the previously generated one.
/// \return Presence stanza or NULL.
Swift::Presence::ref generatePresenceStanza(int features, bool only_new = false);
/// Marks this buddy as available.
void setOnline();
/// Marks this buddy as offline.
void setOffline();
/// Returns true if this buddy is marked as available/online.
/// \return true if this buddy is marked as available/online.
bool isOnline();
/// Sets current subscription.
/// \param subscription "to", "from", "both", "ask"
void setSubscription(const std::string &subscription);
/// Returns current subscription
/// \return subscription "to", "from", "both", "ask"
const std::string &getSubscription();
/// Sets this buddy's flags.
/// \param flags flags
void setFlags(BuddyFlag flags);
/// Returns this buddy's flags.
/// \param flags flags
BuddyFlag getFlags();
/// Returns RosterManager associated with this buddy
/// \return rosterManager
RosterManager *getRosterManager() { return m_rosterManager; }
/// Returns legacy network username which does not contain unsafe characters,
/// so it can be used in JIDs.
std::string getSafeName();
void buddyChanged();
/// Returns legacy network username of this buddy. (for example UIN for ICQ,
/// JID for Jabber, ...).
/// \return legacy network username
virtual std::string getName() = 0;
/// Returns alias (nickname) of this buddy.
/// \return alias (nickname)
virtual std::string getAlias() = 0;
/// Returns list of groups this buddy is in.
/// \return groups
virtual std::vector<std::string> getGroups() = 0;
/// Returns current legacy network status and statuMessage of this buddy.
/// \param status current status/show is stored here
/// \param statusMessage current status message is stored here
/// \return true if status was stored successfully
virtual bool getStatus(Swift::StatusShow &status, std::string &statusMessage) = 0;
/// Returns SHA-1 hash of buddy icon (avatar) or empty string if there is no avatar
/// for this buddy.
/// \return avatar hash or empty string.
virtual std::string getIconHash() = 0;
static std::string JIDToLegacyName(const Swift::JID &jid);
private:
void generateJID();
long m_id;
bool m_online;
std::string m_subscription;
Swift::Presence::ref m_lastPresence;
Swift::JID m_jid;
BuddyFlag m_flags;
RosterManager *m_rosterManager;
};
}
|