Changeset - 62f3fbf99c88
[Not reviewed]
0 3 0
Jan Kaluza - 14 years ago 2011-04-06 14:32:03
hanzz.k@gmail.com
Buddy::JIDToLegacyName
3 files changed with 18 insertions and 2 deletions:
0 comments (0 inline, 0 general)
include/transport/buddy.h
Show inline comments
 
@@ -108,37 +108,39 @@ class Buddy {
 
		/// 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;
 
};
 

	
 
}
src/buddy.cpp
Show inline comments
 
@@ -132,25 +132,39 @@ std::string Buddy::getSafeName() {
 
	}
 
	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;
 
}
 

	
 
void Buddy::buddyChanged() {
 
	Swift::Presence::ref presence = generatePresenceStanza(255);
 
	if (presence) {
 
		m_rosterManager->getUser()->getComponent()->getStanzaChannel()->sendPresence(presence);
 
	}
 
}
 

	
 
std::string Buddy::JIDToLegacyName(const Swift::JID &jid) {
 
	std::string name;
 
	if (jid.getUnescapedNode() == jid.getNode()) {
 
		name = jid.getNode();
 
		if (name.find_last_of("%") != std::string::npos) {
 
			name.replace(name.find_last_of("%"), 1, "@");
 
		}
 
	}
 
	else {
 
		name = jid.getUnescapedNode();
 
	}
 
	return name;
 
}
 

	
 
}
src/rostermanager.cpp
Show inline comments
 
@@ -99,28 +99,28 @@ void RosterManager::handleBuddyRosterPushResponse(Swift::ErrorPayload::ref error
 
Buddy *RosterManager::getBuddy(const std::string &name) {
 
	return m_buddies[name];
 
}
 

	
 
void RosterManager::sendRIE() {
 
	m_RIETimer->stop();
 

	
 
	Swift::RosterItemExchangePayload::ref payload = Swift::RosterItemExchangePayload::ref(new Swift::RosterItemExchangePayload());
 
	for (std::map<std::string, Buddy *>::const_iterator it = m_buddies.begin(); it != m_buddies.end(); it++) {
 
		Buddy *buddy = (*it).second;
 
		Swift::RosterItemExchangePayload::Item item;
 
		item.jid = buddy->getJID().toBare();
 
		item.name = buddy->getAlias();
 
		item.action = Swift::RosterItemExchangePayload::Add;
 
		item.groups = buddy->getGroups();
 

	
 
		payload->addItem(item);
 
	}
 

	
 
	boost::shared_ptr<Swift::GenericRequest<Swift::RosterItemExchangePayload> > request(new Swift::GenericRequest<Swift::RosterItemExchangePayload>(Swift::IQ::Set, m_user->getJID(), payload, m_component->getIQRouter()));
 
	request->send();
 
}
 

	
 
void RosterManager::handleSubscription(Swift::Presence::ref presence) {
 
	></i>
 
	std::string legacyName = Buddy::JIDToLegacyName(presence->getTo());
 
}
 

	
 
}
 
\ No newline at end of file
 
}
0 comments (0 inline, 0 general)