Mercurial > pidgin
changeset 6843:549a0bbbf73d
[gaim-migrate @ 7388]
pre-compute the priority contact so we don't waste much effort looking it up
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sun, 14 Sep 2003 22:17:55 +0000 |
parents | bd433a45a463 |
children | ffc40208c1e9 |
files | src/blist.c src/blist.h |
diffstat | 2 files changed, 46 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/blist.c Sun Sep 14 22:00:11 2003 +0000 +++ b/src/blist.c Sun Sep 14 22:17:55 2003 +0000 @@ -104,6 +104,43 @@ } } +static GaimContact *gaim_buddy_get_contact(GaimBuddy *buddy) +{ + return (GaimContact*)((GaimBlistNode*)buddy)->parent; +} + +static void gaim_contact_compute_priority_buddy(GaimContact *contact) { + GaimBlistNode *bnode; + + for(bnode = ((GaimBlistNode*)contact)->child; bnode; bnode = bnode->next) { + GaimBuddy *buddy; + if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) + continue; + buddy = (GaimBuddy*)bnode; + if(!gaim_account_is_connected(buddy->account)) + continue; + + if(!contact->priority) { + contact->priority = buddy; + } else if(GAIM_BUDDY_IS_ONLINE(buddy)) { + if(!GAIM_BUDDY_IS_ONLINE(contact->priority)) { + contact->priority = buddy; + } else if(!(buddy->uc & UC_UNAVAILABLE) && !buddy->idle && + (contact->priority->uc & UC_UNAVAILABLE || + contact->priority->idle)) { + contact->priority = buddy; + } else if(!buddy->idle && contact->priority->idle) { + contact->priority = buddy; + } else if(contact->priority->uc & UC_UNAVAILABLE && + contact->priority->idle && (!(buddy->uc & UC_UNAVAILABLE) || + !buddy->idle)) { + contact->priority = buddy; + } + } + } +} + + /***************************************************************************** * Public API functions * *****************************************************************************/ @@ -178,6 +215,7 @@ } buddy->uc = status; + gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); if (ops) ops->update(gaimbuddylist, (GaimBlistNode*)buddy); } @@ -195,6 +233,7 @@ } buddy->timer = 0; + gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); if (ops) ops->update(gaimbuddylist, (GaimBlistNode*)buddy); @@ -235,6 +274,7 @@ buddy->timer = g_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy); } + gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); if (ops) ops->update(gaimbuddylist, (GaimBlistNode*)buddy); } @@ -244,6 +284,7 @@ { struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; buddy->idle = idle; + gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); if (ops) ops->update(gaimbuddylist, (GaimBlistNode*)buddy); } @@ -650,6 +691,7 @@ g_hash_table_replace(gaimbuddylist->buddies, hb, buddy); + gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); if (ops) ops->update(gaimbuddylist, (GaimBlistNode*)buddy); if (save) @@ -1015,32 +1057,7 @@ } GaimBuddy *gaim_contact_get_priority_buddy(GaimContact *contact) { - GaimBuddy *top = NULL; - GaimBlistNode *bnode; - - for(bnode = ((GaimBlistNode*)contact)->child; bnode; bnode = bnode->next) { - GaimBuddy *buddy; - if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) - continue; - buddy = (GaimBuddy*)bnode; - if(!top && gaim_account_is_connected(buddy->account)) { - top = buddy; - } else if(GAIM_BUDDY_IS_ONLINE(buddy)) { - if(!GAIM_BUDDY_IS_ONLINE(top)) { - top = buddy; - } else if(!(buddy->uc & UC_UNAVAILABLE) && !buddy->idle && - (top->uc & UC_UNAVAILABLE || top->idle)) { - top = buddy; - } else if(!buddy->idle && top->idle) { - top = buddy; - } else if(top->uc & UC_UNAVAILABLE && top->idle && - (!(buddy->uc & UC_UNAVAILABLE) || !buddy->idle)) { - top = buddy; - } - } - } - - return top; + return contact->priority; } const char *gaim_get_buddy_alias_only(GaimBuddy *b) { @@ -1275,6 +1292,7 @@ ops->update(gaimbuddylist, bnode); } } + gaim_contact_compute_priority_buddy((GaimContact*)cnode); ops->update(gaimbuddylist, cnode); } else if(GAIM_BLIST_NODE_IS_CHAT(cnode) && ((GaimBlistChat*)cnode)->account == account) { @@ -1324,6 +1342,7 @@ ops->remove(gaimbuddylist, bnode); } } + gaim_contact_compute_priority_buddy((GaimContact*)cnode); } else if(GAIM_BLIST_NODE_IS_CHAT(cnode) && ((GaimBlistChat*)cnode)->account == account) { ((GaimGroup*)gnode)->currentsize--;
--- a/src/blist.h Sun Sep 14 22:00:11 2003 +0000 +++ b/src/blist.h Sun Sep 14 22:17:55 2003 +0000 @@ -110,6 +110,7 @@ int totalsize; /**< The number of buddies in this contact */ int currentsize; /**< The number of buddies in this contact corresponding to online accounts */ int online; /**< The number of buddies in this contact who are currently online */ + GaimBuddy *priority; /**< The "top" buddy for this contact */ };