diff --git a/src/rostermanager.cpp b/src/rostermanager.cpp index fd3dd35a8f6e1c2af163ac77dad327591234b16d..261b7b0cd439e37aa82eb0f43e2e37600c3f3963 100644 --- a/src/rostermanager.cpp +++ b/src/rostermanager.cpp @@ -48,10 +48,10 @@ RosterManager::~RosterManager() { m_setBuddyTimer->stop(); m_RIETimer->stop(); if (m_rosterStorage) { - for (std::map::const_iterator it = m_buddies.begin(); it != m_buddies.end(); it++) { - Buddy *buddy = (*it).second; - m_rosterStorage->storeBuddy(buddy); - } +// for (std::map::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); } }