diff --git a/src/command.c b/src/command.c index 5c42417d..421a5585 100644 --- a/src/command.c +++ b/src/command.c @@ -777,10 +777,9 @@ cmd_reset_autocomplete() if (nick_ac != NULL) { p_autocomplete_reset(nick_ac); } - } else { - p_autocomplete_reset(who_ac); } + p_autocomplete_reset(who_ac); p_autocomplete_reset(prefs_ac); p_autocomplete_reset(log_ac); p_autocomplete_reset(commands_ac); @@ -1429,7 +1428,81 @@ _cmd_who(gchar **args, struct cmd_help_t help) } else { if (win_current_is_groupchat()) { char *room = win_current_get_recipient(); - win_show_room_roster(room); + GList *list = muc_get_roster(room); + + // no arg, show all contacts + if (presence == NULL) { + win_show_room_roster(room, list, NULL); + + // available + } else if (strcmp("available", presence) == 0) { + GList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + const char * const contact_presence = (p_contact_presence(contact)); + if ((strcmp(contact_presence, "online") == 0) + || (strcmp(contact_presence, "chat") == 0)) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } + + win_show_room_roster(room, filtered, "available"); + + // unavailable + } else if (strcmp("unavailable", presence) == 0) { + GList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + const char * const contact_presence = (p_contact_presence(contact)); + if ((strcmp(contact_presence, "offline") == 0) + || (strcmp(contact_presence, "away") == 0) + || (strcmp(contact_presence, "dnd") == 0) + || (strcmp(contact_presence, "xa") == 0)) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } + + win_show_room_roster(room, filtered, "unavailable"); + + // online, show all status that indicate online + } else if (strcmp("online", presence) == 0) { + GList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + const char * const contact_presence = (p_contact_presence(contact)); + if ((strcmp(contact_presence, "online") == 0) + || (strcmp(contact_presence, "away") == 0) + || (strcmp(contact_presence, "dnd") == 0) + || (strcmp(contact_presence, "xa") == 0) + || (strcmp(contact_presence, "chat") == 0)) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } + + win_show_room_roster(room, filtered, "online"); + + // show specific status + } else { + GList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + if (strcmp(p_contact_presence(contact), presence) == 0) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } + + win_show_room_roster(room, filtered, presence); + } + + // not in groupchat window } else { GSList *list = get_contact_list(); diff --git a/src/profanity.c b/src/profanity.c index 8ed5d812..8e214421 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -297,7 +297,8 @@ void prof_handle_room_roster_complete(const char * const room) { muc_set_roster_received(room); - win_show_room_roster(room); + GList *roster = muc_get_roster(room); + win_show_room_roster(room, roster, NULL); win_current_page_off(); } diff --git a/src/ui.h b/src/ui.h index 32f34484..1b7a4e99 100644 --- a/src/ui.h +++ b/src/ui.h @@ -115,7 +115,7 @@ void win_show_outgoing_msg(const char * const from, const char * const to, void win_new_chat_win(const char * const to); void win_join_chat(Jid *jid); -void win_show_room_roster(const char * const room); +void win_show_room_roster(const char * const room, GList *roster, const char * const presence); void win_show_room_history(const char * const room_jid, const char * const nick, GTimeVal tv_stamp, const char * const message); void win_show_room_message(const char * const room_jid, const char * const nick, diff --git a/src/windows.c b/src/windows.c index c60e872c..5659cc20 100644 --- a/src/windows.c +++ b/src/windows.c @@ -810,21 +810,27 @@ win_join_chat(Jid *jid) } void -win_show_room_roster(const char * const room) +win_show_room_roster(const char * const room, GList *roster, const char * const presence) { int win_index = _find_prof_win_index(room); WINDOW *win = windows[win_index]->win; - GList *roster = muc_get_roster(room); - _win_show_time(win, '!'); if ((roster == NULL) || (g_list_length(roster) == 0)) { wattron(win, COLOUR_ROOMINFO); - wprintw(win, "Room is empty.\n"); + if (presence == NULL) { + wprintw(win, "Room is empty.\n"); + } else { + wprintw(win, "No participants are %s.\n", presence); + } wattroff(win, COLOUR_ROOMINFO); } else { wattron(win, COLOUR_ROOMINFO); - wprintw(win, "Participants: "); + if (presence == NULL) { + wprintw(win, "Participants: "); + } else { + wprintw(win, "Participants (%s): ", presence); + } wattroff(win, COLOUR_ROOMINFO); wattron(win, COLOUR_ONLINE);