mcabber/src/roster.c
changeset 1437 071c8170b7de
parent 1431 486809ccffc0
child 1438 c5d937d5530b
equal deleted inserted replaced
1436:6fb141142388 1437:071c8170b7de
    22 #include <string.h>
    22 #include <string.h>
    23 
    23 
    24 #include "roster.h"
    24 #include "roster.h"
    25 #include "utils.h"
    25 #include "utils.h"
    26 
    26 
       
    27 extern void hlog_save_state(void);
    27 
    28 
    28 char *strrole[] = {   /* Should match enum in roster.h */
    29 char *strrole[] = {   /* Should match enum in roster.h */
    29   "none",
    30   "none",
    30   "moderator",
    31   "moderator",
    31   "participant",
    32   "participant",
   116 GList *current_buddy;
   117 GList *current_buddy;
   117 GList *alternate_buddy;
   118 GList *alternate_buddy;
   118 
   119 
   119 static roster roster_special;
   120 static roster roster_special;
   120 
   121 
   121 void unread_jid_add(const char *jid);
   122 static int  unread_jid_del(const char *jid);
   122 int  unread_jid_del(const char *jid);
       
   123 
   123 
   124 #define DFILTER_ALL     63
   124 #define DFILTER_ALL     63
   125 #define DFILTER_ONLINE  62
   125 #define DFILTER_ONLINE  62
   126 
   126 
   127 
   127 
   588 void roster_msg_setflag(const char *jid, guint special, guint value)
   588 void roster_msg_setflag(const char *jid, guint special, guint value)
   589 {
   589 {
   590   GSList *sl_user;
   590   GSList *sl_user;
   591   roster *roster_usr, *roster_grp;
   591   roster *roster_usr, *roster_grp;
   592   int new_roster_item = FALSE;
   592   int new_roster_item = FALSE;
       
   593   guint unread_list_modified = FALSE;
   593 
   594 
   594   if (special) {
   595   if (special) {
   595     //sl_user = roster_find(jid, namesearch, ROSTER_TYPE_SPECIAL);
   596     //sl_user = roster_find(jid, namesearch, ROSTER_TYPE_SPECIAL);
   596     //if (!sl_user) return;
   597     //if (!sl_user) return;
   597     //roster_usr = (roster*)sl_user->data;
   598     //roster_usr = (roster*)sl_user->data;
   620   }
   621   }
   621 
   622 
   622   roster_usr = (roster*)sl_user->data;
   623   roster_usr = (roster*)sl_user->data;
   623   roster_grp = (roster*)roster_usr->list->data;
   624   roster_grp = (roster*)roster_usr->list->data;
   624   if (value) {
   625   if (value) {
       
   626     if (!(roster_usr->flags & ROSTER_FLAG_MSG))
       
   627       unread_list_modified = TRUE;
   625     // Message flag is TRUE.  This is easy, we just have to set both flags
   628     // Message flag is TRUE.  This is easy, we just have to set both flags
   626     // to TRUE...
   629     // to TRUE...
   627     roster_usr->flags |= ROSTER_FLAG_MSG;
   630     roster_usr->flags |= ROSTER_FLAG_MSG;
   628     roster_grp->flags |= ROSTER_FLAG_MSG; // group
   631     roster_grp->flags |= ROSTER_FLAG_MSG; // group
   629     // Append the roster_usr to unread_list, but avoid duplicates
   632     // Append the roster_usr to unread_list, but avoid duplicates
   630     if (!g_slist_find(unread_list, roster_usr))
   633     if (!g_slist_find(unread_list, roster_usr))
   631       unread_list = g_slist_append(unread_list, roster_usr);
   634       unread_list = g_slist_append(unread_list, roster_usr);
   632   } else {
   635   } else {
   633     // Message flag is FALSE.
   636     // Message flag is FALSE.
   634     guint msg = FALSE;
   637     guint msg = FALSE;
       
   638     if (roster_usr->flags & ROSTER_FLAG_MSG)
       
   639       unread_list_modified = TRUE;
   635     roster_usr->flags &= ~ROSTER_FLAG_MSG;
   640     roster_usr->flags &= ~ROSTER_FLAG_MSG;
   636     if (unread_list) {
   641     if (unread_list) {
   637       GSList *node = g_slist_find(unread_list, roster_usr);
   642       GSList *node = g_slist_find(unread_list, roster_usr);
   638       if (node) unread_list = g_slist_delete_link(unread_list, node);
   643       if (node) unread_list = g_slist_delete_link(unread_list, node);
   639     }
   644     }
   658       // ROSTER_FLAG_MSG should already be set...
   663       // ROSTER_FLAG_MSG should already be set...
   659   }
   664   }
   660 
   665 
   661   if (buddylist && (new_roster_item || !g_list_find(buddylist, roster_usr)))
   666   if (buddylist && (new_roster_item || !g_list_find(buddylist, roster_usr)))
   662     buddylist_build();
   667     buddylist_build();
       
   668 
       
   669   if (unread_list_modified)
       
   670     hlog_save_state();
   663 }
   671 }
   664 
   672 
   665 const char *roster_getname(const char *jid)
   673 const char *roster_getname(const char *jid)
   666 {
   674 {
   667   GSList *sl_user;
   675   GSList *sl_user;
  1539   g_hash_table_insert(unread_jids, g_strdup(jid), unread_jids);
  1547   g_hash_table_insert(unread_jids, g_strdup(jid), unread_jids);
  1540 }
  1548 }
  1541 
  1549 
  1542 //  unread_jid_del(jid)
  1550 //  unread_jid_del(jid)
  1543 // Return TRUE if jid is found in the table (and remove it), FALSE if not
  1551 // Return TRUE if jid is found in the table (and remove it), FALSE if not
  1544 int unread_jid_del(const char *jid)
  1552 static int unread_jid_del(const char *jid)
  1545 {
  1553 {
  1546   if (!unread_jids)
  1554   if (!unread_jids)
  1547     return FALSE;
  1555     return FALSE;
  1548   return g_hash_table_remove(unread_jids, jid);
  1556   return g_hash_table_remove(unread_jids, jid);
  1549 }
  1557 }
  1550 
  1558 
       
  1559 //  unread_jid_get_list()
       
  1560 // Return the JID list.
       
  1561 // The content of the list should not be modified or freed.
       
  1562 // The caller should call g_list_free() after use.
       
  1563 GList *unread_jid_get_list(void)
       
  1564 {
       
  1565   if (!unread_jids)
       
  1566     return NULL;
       
  1567   return g_hash_table_get_keys(unread_jids);
       
  1568 }
       
  1569 
  1551 /* vim: set expandtab cindent cinoptions=>2\:2(0:  For Vim users... */
  1570 /* vim: set expandtab cindent cinoptions=>2\:2(0:  For Vim users... */