Merge branch 'node-cache'
This commit is contained in:
commit
9b95452c7d
1 changed files with 60 additions and 2 deletions
|
@ -91,6 +91,14 @@ struct FTData {
|
|||
bool paused;
|
||||
};
|
||||
|
||||
struct NodeCache {
|
||||
PurpleAccount *account;
|
||||
std::map<PurpleBlistNode *, int> nodes;
|
||||
int timer;
|
||||
};
|
||||
|
||||
bool caching = true;
|
||||
|
||||
static void *notify_user_info(PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info);
|
||||
|
||||
static gboolean ft_ui_ready(void *data) {
|
||||
|
@ -357,6 +365,12 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
|||
void handleLogoutRequest(const std::string &user, const std::string &legacyName) {
|
||||
PurpleAccount *account = m_sessions[user];
|
||||
if (account) {
|
||||
if (account->ui_data) {
|
||||
NodeCache *cache = (NodeCache *) account->ui_data;
|
||||
purple_timeout_remove_wrapped(cache->timer);
|
||||
delete cache;
|
||||
account->ui_data = NULL;
|
||||
}
|
||||
if (purple_account_get_int_wrapped(account, "version", 0) != 0) {
|
||||
std::string data = stringOf(purple_account_get_int_wrapped(account, "version", 0));
|
||||
g_file_set_contents ("gfire.cfg", data.c_str(), data.size(), NULL);
|
||||
|
@ -806,12 +820,56 @@ static std::vector<std::string> getGroups(PurpleBuddy *m_buddy) {
|
|||
return groups;
|
||||
}
|
||||
|
||||
static void buddyListNewNode(PurpleBlistNode *node) {
|
||||
void buddyListNewNode(PurpleBlistNode *node);
|
||||
|
||||
static gboolean new_node_cache(void *data) {
|
||||
NodeCache *cache = (NodeCache *) data;
|
||||
caching = false;
|
||||
for (std::map<PurpleBlistNode *, int>::const_iterator it = cache->nodes.begin(); it != cache->nodes.end(); it++) {
|
||||
buddyListNewNode(it->first);
|
||||
}
|
||||
caching = true;
|
||||
|
||||
cache->account->ui_data = NULL;
|
||||
delete cache;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void buddyNodeRemoved(PurpleBuddyList *list, PurpleBlistNode *node) {
|
||||
if (!PURPLE_BLIST_NODE_IS_BUDDY_WRAPPED(node))
|
||||
return;
|
||||
PurpleBuddy *buddy = (PurpleBuddy *) node;
|
||||
PurpleAccount *account = purple_buddy_get_account_wrapped(buddy);
|
||||
|
||||
if (!account->ui_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
NodeCache *cache = (NodeCache *) account->ui_data;
|
||||
cache->nodes.erase(node);
|
||||
}
|
||||
|
||||
void buddyListNewNode(PurpleBlistNode *node) {
|
||||
if (!PURPLE_BLIST_NODE_IS_BUDDY_WRAPPED(node))
|
||||
return;
|
||||
PurpleBuddy *buddy = (PurpleBuddy *) node;
|
||||
PurpleAccount *account = purple_buddy_get_account_wrapped(buddy);
|
||||
|
||||
if (caching) {
|
||||
if (!account->ui_data) {
|
||||
NodeCache *cache = new NodeCache;
|
||||
cache->account = account;
|
||||
cache->timer = purple_timeout_add_wrapped(400, new_node_cache, cache);
|
||||
account->ui_data = (void *) cache;
|
||||
}
|
||||
|
||||
NodeCache *cache = (NodeCache *) account->ui_data;
|
||||
cache->nodes[node] = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> groups = getGroups(buddy);
|
||||
LOG4CXX_INFO(logger, "Buddy updated " << np->m_accounts[account] << " " << purple_buddy_get_name_wrapped(buddy) << " " << getAlias(buddy) << " group (" << groups.size() << ")=" << groups[0]);
|
||||
|
||||
|
@ -904,7 +962,7 @@ static PurpleBlistUiOps blistUiOps =
|
|||
buddyListNewNode,
|
||||
NULL,
|
||||
buddyListUpdate,
|
||||
NULL, //NodeRemoved,
|
||||
buddyNodeRemoved,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, // buddyListAddBuddy,
|
||||
|
|
Loading…
Add table
Reference in a new issue