Store buddies if they change and don't store unchanged buddies on logout

This commit is contained in:
HanzZ 2011-06-05 11:58:10 +02:00
parent 96fb9b61e8
commit b63c1d0aad
4 changed files with 14 additions and 7 deletions

View file

@ -268,7 +268,7 @@ static void buddyListNewNode(PurpleBlistNode *node) {
// np->handleBuddyChanged(np->m_accounts[account], purple_buddy_get_name(buddy), getAlias(buddy), getGroups(buddy)[0], (int) status.getType(), message, getIconHash(buddy));
// }
void buddyListUpdate(PurpleBuddyList *list, PurpleBlistNode *node) {
static void buddyListUpdate(PurpleBuddyList *list, PurpleBlistNode *node) {
if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
return;
PurpleBuddy *buddy = (PurpleBuddy *) node;

View file

@ -107,6 +107,8 @@ class Buddy {
void handleVCardReceived(const std::string &id, const Swift::JID &to, Swift::VCard::ref vcard);
boost::signal<void ()> onBuddyChanged;
virtual void getVCard(const std::string &id, const Swift::JID &to) = 0;
/// Returns legacy network username of this buddy. (for example UIN for ICQ,

View file

@ -151,6 +151,7 @@ void Buddy::buddyChanged() {
if (presence) {
m_rosterManager->getUser()->getComponent()->getStanzaChannel()->sendPresence(presence);
}
onBuddyChanged();
}
void Buddy::handleVCardReceived(const std::string &id, const Swift::JID &to, Swift::VCard::ref vcard) {

View file

@ -48,10 +48,10 @@ RosterManager::~RosterManager() {
m_setBuddyTimer->stop();
m_RIETimer->stop();
if (m_rosterStorage) {
for (std::map<std::string, Buddy *>::const_iterator it = m_buddies.begin(); it != m_buddies.end(); it++) {
Buddy *buddy = (*it).second;
m_rosterStorage->storeBuddy(buddy);
}
// for (std::map<std::string, Buddy *>::const_iterator it = m_buddies.begin(); it != m_buddies.end(); it++) {
// Buddy *buddy = (*it).second;
// m_rosterStorage->storeBuddy(buddy);
// }
m_rosterStorage->storeBuddies();
}
@ -86,6 +86,10 @@ void RosterManager::sendBuddyRosterPush(Buddy *buddy) {
void RosterManager::setBuddyCallback(Buddy *buddy) {
m_setBuddyTimer->onTick.disconnect(boost::bind(&RosterManager::setBuddyCallback, this, buddy));
if (m_rosterStorage) {
buddy->onBuddyChanged.connect(boost::bind(&RosterStorage::storeBuddy, m_rosterStorage, buddy));
}
std::cout << "ADDING " << buddy->getName() << "\n";
m_buddies[buddy->getName()] = buddy;
onBuddySet(buddy);
@ -151,8 +155,7 @@ void RosterManager::handleSubscription(Swift::Presence::ref presence) {
void RosterManager::setStorageBackend(StorageBackend *storageBackend) {
if (m_rosterStorage) {
m_rosterStorage->storeBuddies();
delete m_rosterStorage;
return;
}
m_rosterStorage = new RosterStorage(m_user, storageBackend);
@ -163,6 +166,7 @@ void RosterManager::setStorageBackend(StorageBackend *storageBackend) {
Buddy *buddy = m_component->getFactory()->createBuddy(this, *it);
std::cout << "CREATING BUDDY FROM DATABASE CACHE " << buddy->getName() << "\n";
m_buddies[buddy->getName()] = buddy;
buddy->onBuddyChanged.connect(boost::bind(&RosterStorage::storeBuddy, m_rosterStorage, buddy));
onBuddySet(buddy);
}
}