1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Pass offline filter to roster list functions

This commit is contained in:
James Booth 2015-11-18 00:25:35 +00:00
parent 2260e3bd6f
commit b373cbcfc0
4 changed files with 31 additions and 17 deletions

View File

@ -1320,7 +1320,7 @@ _who_roster(ProfWin *window, const char *const command, gchar **args)
cons_show(""); cons_show("");
GSList *list = NULL; GSList *list = NULL;
if (group) { if (group) {
list = roster_get_group(group, ROSTER_ORD_NAME); list = roster_get_group(group, ROSTER_ORD_NAME, TRUE);
if (list == NULL) { if (list == NULL) {
cons_show("No such group: %s.", group); cons_show("No such group: %s.", group);
return; return;
@ -1628,7 +1628,7 @@ cmd_group(ProfWin *window, const char *const command, gchar **args)
return TRUE; return TRUE;
} }
GSList *list = roster_get_group(group, ROSTER_ORD_NAME); GSList *list = roster_get_group(group, ROSTER_ORD_NAME, TRUE);
cons_show_roster_group(group, list); cons_show_roster_group(group, list);
return TRUE; return TRUE;
} }

View File

@ -455,7 +455,7 @@ roster_fulljid_autocomplete(const char *const search_str)
} }
GSList* GSList*
roster_get_nogroup(roster_ord_t order) roster_get_nogroup(roster_ord_t order, gboolean include_offline)
{ {
GSList *result = NULL; GSList *result = NULL;
GHashTableIter iter; GHashTableIter iter;
@ -471,6 +471,12 @@ roster_get_nogroup(roster_ord_t order)
g_hash_table_iter_init(&iter, contacts); g_hash_table_iter_init(&iter, contacts);
while (g_hash_table_iter_next(&iter, &key, &value)) { while (g_hash_table_iter_next(&iter, &key, &value)) {
PContact contact = value;
const char *presence = p_contact_presence(contact);
if (!include_offline && (g_strcmp0(presence, "offline") == 0)) {
continue;
}
GSList *groups = p_contact_groups(value); GSList *groups = p_contact_groups(value);
if (groups == NULL) { if (groups == NULL) {
result = g_slist_insert_sorted(result, value, cmp_func); result = g_slist_insert_sorted(result, value, cmp_func);
@ -482,7 +488,7 @@ roster_get_nogroup(roster_ord_t order)
} }
GSList* GSList*
roster_get_group(const char *const group, roster_ord_t order) roster_get_group(const char *const group, roster_ord_t order, gboolean include_offline)
{ {
GSList *result = NULL; GSList *result = NULL;
GHashTableIter iter; GHashTableIter iter;
@ -498,6 +504,12 @@ roster_get_group(const char *const group, roster_ord_t order)
g_hash_table_iter_init(&iter, contacts); g_hash_table_iter_init(&iter, contacts);
while (g_hash_table_iter_next(&iter, &key, &value)) { while (g_hash_table_iter_next(&iter, &key, &value)) {
PContact contact = value;
const char *presence = p_contact_presence(contact);
if (!include_offline && (g_strcmp0(presence, "offline") == 0)) {
continue;
}
GSList *groups = p_contact_groups(value); GSList *groups = p_contact_groups(value);
while (groups) { while (groups) {
if (strcmp(groups->data, group) == 0) { if (strcmp(groups->data, group) == 0) {

View File

@ -64,12 +64,12 @@ GSList* roster_get_contacts_online(void);
gboolean roster_has_pending_subscriptions(void); gboolean roster_has_pending_subscriptions(void);
char* roster_contact_autocomplete(const char *const search_str); char* roster_contact_autocomplete(const char *const search_str);
char* roster_fulljid_autocomplete(const char *const search_str); char* roster_fulljid_autocomplete(const char *const search_str);
GSList* roster_get_group(const char *const group, roster_ord_t order); GSList* roster_get_group(const char *const group, roster_ord_t order, gboolean include_offline);
GSList* roster_get_groups(void); GSList* roster_get_groups(void);
char* roster_group_autocomplete(const char *const search_str); char* roster_group_autocomplete(const char *const search_str);
char* roster_barejid_autocomplete(const char *const search_str); char* roster_barejid_autocomplete(const char *const search_str);
GSList* roster_get_contacts_by_presence(const char *const presence); GSList* roster_get_contacts_by_presence(const char *const presence);
GSList* roster_get_nogroup(roster_ord_t order); GSList* roster_get_nogroup(roster_ord_t order, gboolean include_offline);
char* roster_get_msg_display_name(const char *const barejid, const char *const resource); char* roster_get_msg_display_name(const char *const barejid, const char *const resource);
#endif #endif

View File

@ -160,23 +160,24 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese
static void static void
_rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group)
{ {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
GString *title = g_string_new(" -");
g_string_append(title, group);
win_printline_nowrap(layout->subwin, title->str);
g_string_free(title, TRUE);
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
GSList *contacts = NULL; GSList *contacts = NULL;
char *order = prefs_get_string(PREF_ROSTER_ORDER); char *order = prefs_get_string(PREF_ROSTER_ORDER);
gboolean offline = prefs_get_boolean(PREF_ROSTER_OFFLINE);
if (g_strcmp0(order, "presence") == 0) { if (g_strcmp0(order, "presence") == 0) {
contacts = roster_get_group(group, ROSTER_ORD_PRESENCE); contacts = roster_get_group(group, ROSTER_ORD_PRESENCE, offline);
} else { } else {
contacts = roster_get_group(group, ROSTER_ORD_NAME); contacts = roster_get_group(group, ROSTER_ORD_NAME, offline);
} }
if (contacts) { if (contacts) {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
GString *title = g_string_new(" -");
g_string_append(title, group);
win_printline_nowrap(layout->subwin, title->str);
g_string_free(title, TRUE);
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
GSList *curr_contact = contacts; GSList *curr_contact = contacts;
while (curr_contact) { while (curr_contact) {
PContact contact = curr_contact->data; PContact contact = curr_contact->data;
@ -193,10 +194,11 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout)
GSList *contacts = NULL; GSList *contacts = NULL;
char *order = prefs_get_string(PREF_ROSTER_ORDER); char *order = prefs_get_string(PREF_ROSTER_ORDER);
gboolean offline = prefs_get_boolean(PREF_ROSTER_OFFLINE);
if (g_strcmp0(order, "presence") == 0) { if (g_strcmp0(order, "presence") == 0) {
contacts = roster_get_nogroup(ROSTER_ORD_PRESENCE); contacts = roster_get_nogroup(ROSTER_ORD_PRESENCE, offline);
} else { } else {
contacts = roster_get_nogroup(ROSTER_ORD_NAME); contacts = roster_get_nogroup(ROSTER_ORD_NAME, offline);
} }
if (contacts) { if (contacts) {