comparison src/blist.c @ 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 f76e26a0e6a9
children 8ab95f4c9800
comparison
equal deleted inserted replaced
6842:bd433a45a463 6843:549a0bbbf73d
102 } 102 }
103 } 103 }
104 } 104 }
105 } 105 }
106 106
107 static GaimContact *gaim_buddy_get_contact(GaimBuddy *buddy)
108 {
109 return (GaimContact*)((GaimBlistNode*)buddy)->parent;
110 }
111
112 static void gaim_contact_compute_priority_buddy(GaimContact *contact) {
113 GaimBlistNode *bnode;
114
115 for(bnode = ((GaimBlistNode*)contact)->child; bnode; bnode = bnode->next) {
116 GaimBuddy *buddy;
117 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
118 continue;
119 buddy = (GaimBuddy*)bnode;
120 if(!gaim_account_is_connected(buddy->account))
121 continue;
122
123 if(!contact->priority) {
124 contact->priority = buddy;
125 } else if(GAIM_BUDDY_IS_ONLINE(buddy)) {
126 if(!GAIM_BUDDY_IS_ONLINE(contact->priority)) {
127 contact->priority = buddy;
128 } else if(!(buddy->uc & UC_UNAVAILABLE) && !buddy->idle &&
129 (contact->priority->uc & UC_UNAVAILABLE ||
130 contact->priority->idle)) {
131 contact->priority = buddy;
132 } else if(!buddy->idle && contact->priority->idle) {
133 contact->priority = buddy;
134 } else if(contact->priority->uc & UC_UNAVAILABLE &&
135 contact->priority->idle && (!(buddy->uc & UC_UNAVAILABLE) ||
136 !buddy->idle)) {
137 contact->priority = buddy;
138 }
139 }
140 }
141 }
142
143
107 /***************************************************************************** 144 /*****************************************************************************
108 * Public API functions * 145 * Public API functions *
109 *****************************************************************************/ 146 *****************************************************************************/
110 147
111 struct gaim_buddy_list *gaim_blist_new() 148 struct gaim_buddy_list *gaim_blist_new()
176 else 213 else
177 gaim_signal_emit(gaim_blist_get_handle(), "buddy-back", buddy); 214 gaim_signal_emit(gaim_blist_get_handle(), "buddy-back", buddy);
178 } 215 }
179 216
180 buddy->uc = status; 217 buddy->uc = status;
218 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy));
181 if (ops) 219 if (ops)
182 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); 220 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
183 } 221 }
184 222
185 static gboolean presence_update_timeout_cb(GaimBuddy *buddy) { 223 static gboolean presence_update_timeout_cb(GaimBuddy *buddy) {
193 } else if(buddy->present == GAIM_BUDDY_SIGNING_OFF) { 231 } else if(buddy->present == GAIM_BUDDY_SIGNING_OFF) {
194 buddy->present = GAIM_BUDDY_OFFLINE; 232 buddy->present = GAIM_BUDDY_OFFLINE;
195 } 233 }
196 234
197 buddy->timer = 0; 235 buddy->timer = 0;
236 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy));
198 237
199 if (ops) 238 if (ops)
200 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); 239 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
201 240
202 if (conv) { 241 if (conv) {
233 if(buddy->timer > 0) 272 if(buddy->timer > 0)
234 g_source_remove(buddy->timer); 273 g_source_remove(buddy->timer);
235 buddy->timer = g_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy); 274 buddy->timer = g_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy);
236 } 275 }
237 276
277 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy));
238 if (ops) 278 if (ops)
239 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); 279 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
240 } 280 }
241 281
242 282
243 void gaim_blist_update_buddy_idle (GaimBuddy *buddy, int idle) 283 void gaim_blist_update_buddy_idle (GaimBuddy *buddy, int idle)
244 { 284 {
245 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; 285 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
246 buddy->idle = idle; 286 buddy->idle = idle;
287 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy));
247 if (ops) 288 if (ops)
248 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); 289 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
249 } 290 }
250 291
251 void gaim_blist_update_buddy_evil (GaimBuddy *buddy, int warning) 292 void gaim_blist_update_buddy_evil (GaimBuddy *buddy, int warning)
648 hb->account = buddy->account; 689 hb->account = buddy->account;
649 hb->group = ((GaimBlistNode*)buddy)->parent->parent; 690 hb->group = ((GaimBlistNode*)buddy)->parent->parent;
650 691
651 g_hash_table_replace(gaimbuddylist->buddies, hb, buddy); 692 g_hash_table_replace(gaimbuddylist->buddies, hb, buddy);
652 693
694 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy));
653 if (ops) 695 if (ops)
654 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); 696 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
655 if (save) 697 if (save)
656 gaim_blist_save(); 698 gaim_blist_save();
657 } 699 }
1013 g_free(group->name); 1055 g_free(group->name);
1014 g_free(group); 1056 g_free(group);
1015 } 1057 }
1016 1058
1017 GaimBuddy *gaim_contact_get_priority_buddy(GaimContact *contact) { 1059 GaimBuddy *gaim_contact_get_priority_buddy(GaimContact *contact) {
1018 GaimBuddy *top = NULL; 1060 return contact->priority;
1019 GaimBlistNode *bnode;
1020
1021 for(bnode = ((GaimBlistNode*)contact)->child; bnode; bnode = bnode->next) {
1022 GaimBuddy *buddy;
1023 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
1024 continue;
1025 buddy = (GaimBuddy*)bnode;
1026 if(!top && gaim_account_is_connected(buddy->account)) {
1027 top = buddy;
1028 } else if(GAIM_BUDDY_IS_ONLINE(buddy)) {
1029 if(!GAIM_BUDDY_IS_ONLINE(top)) {
1030 top = buddy;
1031 } else if(!(buddy->uc & UC_UNAVAILABLE) && !buddy->idle &&
1032 (top->uc & UC_UNAVAILABLE || top->idle)) {
1033 top = buddy;
1034 } else if(!buddy->idle && top->idle) {
1035 top = buddy;
1036 } else if(top->uc & UC_UNAVAILABLE && top->idle &&
1037 (!(buddy->uc & UC_UNAVAILABLE) || !buddy->idle)) {
1038 top = buddy;
1039 }
1040 }
1041 }
1042
1043 return top;
1044 } 1061 }
1045 1062
1046 const char *gaim_get_buddy_alias_only(GaimBuddy *b) { 1063 const char *gaim_get_buddy_alias_only(GaimBuddy *b) {
1047 if(!b) 1064 if(!b)
1048 return NULL; 1065 return NULL;
1273 ((GaimGroup*)gnode)->online++; 1290 ((GaimGroup*)gnode)->online++;
1274 } 1291 }
1275 ops->update(gaimbuddylist, bnode); 1292 ops->update(gaimbuddylist, bnode);
1276 } 1293 }
1277 } 1294 }
1295 gaim_contact_compute_priority_buddy((GaimContact*)cnode);
1278 ops->update(gaimbuddylist, cnode); 1296 ops->update(gaimbuddylist, cnode);
1279 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode) && 1297 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode) &&
1280 ((GaimBlistChat*)cnode)->account == account) { 1298 ((GaimBlistChat*)cnode)->account == account) {
1281 ((GaimGroup *)gnode)->online++; 1299 ((GaimGroup *)gnode)->online++;
1282 ((GaimGroup *)gnode)->currentsize++; 1300 ((GaimGroup *)gnode)->currentsize++;
1322 1340
1323 if(ops) 1341 if(ops)
1324 ops->remove(gaimbuddylist, bnode); 1342 ops->remove(gaimbuddylist, bnode);
1325 } 1343 }
1326 } 1344 }
1345 gaim_contact_compute_priority_buddy((GaimContact*)cnode);
1327 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode) && 1346 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode) &&
1328 ((GaimBlistChat*)cnode)->account == account) { 1347 ((GaimBlistChat*)cnode)->account == account) {
1329 ((GaimGroup*)gnode)->currentsize--; 1348 ((GaimGroup*)gnode)->currentsize--;
1330 ((GaimGroup*)gnode)->online--; 1349 ((GaimGroup*)gnode)->online--;
1331 if(ops) 1350 if(ops)