comparison mcabber/mcabber/roster.c @ 1809:eef8c9fff727

Hopefully fix issue with hook-unread-list-change
author Mikael Berthe <mikael@lilotux.net>
date Sun, 21 Mar 2010 18:12:34 +0100
parents 9daf6b3f30d6
children e6d355e50d7a
comparison
equal deleted inserted replaced
1808:7a1c40549291 1809:eef8c9fff727
586 roster_usr = (roster*)sl_user->data; 586 roster_usr = (roster*)sl_user->data;
587 if (value) 587 if (value)
588 roster_usr->flags |= flags; 588 roster_usr->flags |= flags;
589 else 589 else
590 roster_usr->flags &= ~flags; 590 roster_usr->flags &= ~flags;
591 }
592
593 // roster_unread_count()
594 guint roster_unread_count(void)
595 {
596 guint unread_count = 0;
597 #ifdef MODULES_ENABLE
598 gpointer unread_ptr, first_unread;
599 guint muc_unread = 0, muc_attention = 0;
600 guint attention_count = 0;
601
602 unread_ptr = first_unread = unread_msg(NULL);
603 if (first_unread) {
604 do {
605 guint type = buddy_gettype(unread_ptr);
606 unread_count++;
607
608 if (type & ROSTER_TYPE_ROOM) {
609 muc_unread++;
610 if (buddy_getuiprio(unread_ptr) >= ROSTER_UI_PRIO_MUC_HL_MESSAGE)
611 muc_attention++;
612 } else {
613 if (buddy_getuiprio(unread_ptr) >= ROSTER_UI_PRIO_ATTENTION_MESSAGE)
614 attention_count++;
615 }
616 unread_ptr = unread_msg(unread_ptr);
617 } while (unread_ptr && unread_ptr != first_unread);
618 }
619
620 {
621 gchar *str_unread = g_strdup_printf("%u", unread_count);
622 gchar *str_attention = g_strdup_printf("%u", attention_count);
623 gchar *str_muc_unread = g_strdup_printf("%u", muc_unread);
624 gchar *str_muc_attention = g_strdup_printf("%u", muc_attention);
625 hk_arg_t args[] = {
626 { "unread", str_unread }, // All unread
627 { "attention", str_attention }, // Attention (private)
628 { "muc_unread", str_muc_unread }, // MUC unread
629 { "muc_attention", str_muc_attention }, // MUC attention (highlight)
630 { NULL, NULL },
631 };
632 hk_run_handlers(HOOK_UNREAD_LIST_CHANGE, args);
633 g_free(str_unread);
634 g_free(str_attention);
635 g_free(str_muc_unread);
636 g_free(str_muc_attention);
637 }
638 #endif
639 return unread_count;
591 } 640 }
592 641
593 // roster_msg_setflag() 642 // roster_msg_setflag()
594 // Set the ROSTER_FLAG_MSG to the given value for the given jid. 643 // Set the ROSTER_FLAG_MSG to the given value for the given jid.
595 // It will update the buddy's group message flag. 644 // It will update the buddy's group message flag.
689 if (unread_list_modified) { 738 if (unread_list_modified) {
690 guint unread_count; 739 guint unread_count;
691 hlog_save_state(); 740 hlog_save_state();
692 741
693 #ifdef MODULES_ENABLE 742 #ifdef MODULES_ENABLE
694 { 743 unread_count = roster_unread_count();
695 gpointer unread_ptr, first_unread;
696 guint muc_unread = 0, muc_attention = 0;
697 guint attention_count = 0;
698 unread_count = 0;
699
700 unread_ptr = first_unread = unread_msg(NULL);
701 if (first_unread) {
702 do {
703 guint type = buddy_gettype(unread_ptr);
704 unread_count++;
705
706 if (type & ROSTER_TYPE_ROOM) {
707 muc_unread++;
708 if (buddy_getuiprio(unread_ptr) >= ROSTER_UI_PRIO_MUC_HL_MESSAGE)
709 muc_attention++;
710 } else {
711 if (buddy_getuiprio(unread_ptr) >= ROSTER_UI_PRIO_ATTENTION_MESSAGE)
712 attention_count++;
713 }
714 unread_ptr = unread_msg(unread_ptr);
715 } while (unread_ptr && unread_ptr != first_unread);
716 }
717
718 {
719 gchar *str_unread = g_strdup_printf("%u", unread_count);
720 gchar *str_attention = g_strdup_printf("%u", attention_count);
721 gchar *str_muc_unread = g_strdup_printf("%u", muc_unread);
722 gchar *str_muc_attention = g_strdup_printf("%u", muc_attention);
723 hk_arg_t args[] = {
724 { "unread", str_unread }, // All unread
725 { "attention", str_attention }, // Attention (private)
726 { "muc_unread", str_muc_unread }, // MUC unread
727 { "muc_attention", str_muc_attention }, // MUC attention (highlight)
728 { NULL, NULL },
729 };
730 hk_run_handlers(HOOK_UNREAD_LIST_CHANGE, args);
731 g_free(str_unread);
732 g_free(str_attention);
733 g_free(str_muc_unread);
734 g_free(str_muc_attention);
735 }
736 }
737 #else 744 #else
738 unread_count = g_slist_length(unread_list); 745 unread_count = g_slist_length(unread_list);
739 #endif 746 #endif
740 747
741 /* Call external command */ 748 /* Call external command */
772 newval = value; 779 newval = value;
773 780
774 roster_usr->ui_prio = newval; 781 roster_usr->ui_prio = newval;
775 unread_list = g_slist_sort(unread_list, 782 unread_list = g_slist_sort(unread_list,
776 (GCompareFunc)&_roster_compare_uiprio); 783 (GCompareFunc)&_roster_compare_uiprio);
784 roster_unread_count();
777 } 785 }
778 786
779 guint roster_getuiprio(const char *jid, guint special) 787 guint roster_getuiprio(const char *jid, guint special)
780 { 788 {
781 roster *roster_usr; 789 roster *roster_usr;