comparison mcabber/src/roster.c @ 662:4111ff4cdd15

Do not loose the unread_message flag when disconnecting from the server
author Mikael Berthe <mikael@lilotux.net>
date Mon, 09 Jan 2006 19:40:29 +0100
parents b243d3b3ff1b
children 2b87065270f3
comparison
equal deleted inserted replaced
661:4674e92a3e01 662:4111ff4cdd15
78 /* ### Variables ### */ 78 /* ### Variables ### */
79 79
80 static int hide_offline_buddies; 80 static int hide_offline_buddies;
81 static GSList *groups; 81 static GSList *groups;
82 static GSList *unread_list; 82 static GSList *unread_list;
83 static GHashTable *unread_jids;
83 GList *buddylist; 84 GList *buddylist;
84 GList *current_buddy; 85 GList *current_buddy;
85 GList *alternate_buddy; 86 GList *alternate_buddy;
87
88 void unread_jid_add(const char *jid);
89 int unread_jid_del(const char *jid);
86 90
87 91
88 /* ### Resources functions ### */ 92 /* ### Resources functions ### */
89 93
90 static void free_all_resources(GSList **reslist) 94 static void free_all_resources(GSList **reslist)
311 p = strstr(str, "/"); 315 p = strstr(str, "/");
312 if (p) *p = '\0'; 316 if (p) *p = '\0';
313 roster_usr->name = g_strdup(str); 317 roster_usr->name = g_strdup(str);
314 g_free(str); 318 g_free(str);
315 } 319 }
320 if (unread_jid_del(jid)) {
321 roster_usr->flags |= ROSTER_FLAG_MSG;
322 // Append the roster_usr to unread_list
323 unread_list = g_slist_append(unread_list, roster_usr);
324 }
316 roster_usr->type = type; 325 roster_usr->type = type;
317 roster_usr->subscription = esub; 326 roster_usr->subscription = esub;
318 roster_usr->list = slist; // (my_group SList element) 327 roster_usr->list = slist; // (my_group SList element)
319 // #4 Insert node (sorted) 328 // #4 Insert node (sorted)
320 my_group->list = g_slist_insert_sorted(my_group->list, roster_usr, 329 my_group->list = g_slist_insert_sorted(my_group->list, roster_usr,
337 roster_usr = (roster*)sl_user->data; 346 roster_usr = (roster*)sl_user->data;
338 347
339 // Remove (if present) from unread messages list 348 // Remove (if present) from unread messages list
340 node = g_slist_find(unread_list, roster_usr); 349 node = g_slist_find(unread_list, roster_usr);
341 if (node) unread_list = g_slist_delete_link(unread_list, node); 350 if (node) unread_list = g_slist_delete_link(unread_list, node);
351 // If there is a pending unread message, keep track of it
352 if (roster_usr->flags & ROSTER_FLAG_MSG)
353 unread_jid_add(roster_usr->jid);
342 354
343 // Let's free memory (jid, name, status message) 355 // Let's free memory (jid, name, status message)
344 if (roster_usr->jid) g_free((gchar*)roster_usr->jid); 356 if (roster_usr->jid) g_free((gchar*)roster_usr->jid);
345 if (roster_usr->name) g_free((gchar*)roster_usr->name); 357 if (roster_usr->name) g_free((gchar*)roster_usr->name);
346 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname); 358 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname);
377 roster *roster_grp = (roster*)sl_grp->data; 389 roster *roster_grp = (roster*)sl_grp->data;
378 GSList *sl_usr = roster_grp->list; 390 GSList *sl_usr = roster_grp->list;
379 // Walk through this group users 391 // Walk through this group users
380 while (sl_usr) { 392 while (sl_usr) {
381 roster *roster_usr = (roster*)sl_usr->data; 393 roster *roster_usr = (roster*)sl_usr->data;
394 // If there is a pending unread message, keep track of it
395 if (roster_usr->flags & ROSTER_FLAG_MSG)
396 unread_jid_add(roster_usr->jid);
382 // Free name and jid 397 // Free name and jid
383 if (roster_usr->jid) g_free((gchar*)roster_usr->jid); 398 if (roster_usr->jid) g_free((gchar*)roster_usr->jid);
384 if (roster_usr->name) g_free((gchar*)roster_usr->name); 399 if (roster_usr->name) g_free((gchar*)roster_usr->name);
385 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname); 400 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname);
386 if (roster_usr->topic) g_free((gchar*)roster_usr->topic); 401 if (roster_usr->topic) g_free((gchar*)roster_usr->topic);
1186 if (next_unread) 1201 if (next_unread)
1187 return next_unread->data; 1202 return next_unread->data;
1188 return unread_list->data; 1203 return unread_list->data;
1189 } 1204 }
1190 1205
1206
1207 /* ### "unread_jids" functions ###
1208 *
1209 * The unread_jids hash table is used to keep track of the buddies with
1210 * unread messages when a disconnection occurs.
1211 * When removing a buddy with an unread message from the roster, the
1212 * jid should be added to the unread_jids table. When adding a buddy to
1213 * the roster, we check if (s)he had a pending unread message.
1214 */
1215
1216 // unread_jid_add(jid)
1217 // Add jid to the unread_jids hash table
1218 void unread_jid_add(const char *jid)
1219 {
1220 if (!unread_jids) {
1221 // Initialize unread_jids hash table
1222 unread_jids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
1223 }
1224 // The 2nd unread_jids is an arbitrary non-null pointer:
1225 g_hash_table_insert(unread_jids, g_strdup(jid), unread_jids);
1226 }
1227
1228 // unread_jid_del(jid)
1229 // Return TRUE if jid is found in the table (and remove it), FALSE if not
1230 int unread_jid_del(const char *jid)
1231 {
1232 if (!unread_jids)
1233 return FALSE;
1234 return g_hash_table_remove(unread_jids, jid);
1235 }
1236
1191 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ 1237 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */