From 1aee7ce4bf1958ad81c271cde6ccb5ace0452fe0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 22 Jul 2014 23:17:42 +0100 Subject: [PATCH 1/4] Show message when no contacts with presence for /who --- src/command/commands.c | 120 +++++++++++++++++++++++++++++------------ 1 file changed, 87 insertions(+), 33 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 3e7dffd9..b8d9b96c 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -838,19 +838,23 @@ cmd_who(gchar **args, struct cmd_help_t help) // no arg, show all contacts if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) { if (group != NULL) { - cons_show("%s:", group); + if (list == NULL) { + cons_show("No contacts in group %s.", group); + } else { + cons_show("%s:", group); + cons_show_contacts(list); + } } else { - cons_show("All contacts:"); + if (list == NULL) { + cons_show("You have no contacts."); + } else { + cons_show("All contacts:"); + cons_show_contacts(list); + } } - cons_show_contacts(list); // available } else if (strcmp("available", presence) == 0) { - if (group != NULL) { - cons_show("%s (%s):", group, presence); - } else { - cons_show("Contacts (%s):", presence); - } GSList *filtered = NULL; while (list != NULL) { @@ -861,15 +865,24 @@ cmd_who(gchar **args, struct cmd_help_t help) list = g_slist_next(list); } - cons_show_contacts(filtered); + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } // unavailable } else if (strcmp("unavailable", presence) == 0) { - if (group != NULL) { - cons_show("%s (%s):", group, presence); - } else { - cons_show("Contacts (%s):", presence); - } GSList *filtered = NULL; while (list != NULL) { @@ -880,15 +893,24 @@ cmd_who(gchar **args, struct cmd_help_t help) list = g_slist_next(list); } - cons_show_contacts(filtered); + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } // online, available resources } else if (strcmp("online", presence) == 0) { - if (group != NULL) { - cons_show("%s (%s):", group, presence); - } else { - cons_show("Contacts (%s):", presence); - } GSList *filtered = NULL; while (list != NULL) { @@ -899,15 +921,24 @@ cmd_who(gchar **args, struct cmd_help_t help) list = g_slist_next(list); } - cons_show_contacts(filtered); + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } // offline, no available resources } else if (strcmp("offline", presence) == 0) { - if (group != NULL) { - cons_show("%s (%s):", group, presence); - } else { - cons_show("Contacts (%s):", presence); - } GSList *filtered = NULL; while (list != NULL) { @@ -918,15 +949,24 @@ cmd_who(gchar **args, struct cmd_help_t help) list = g_slist_next(list); } - cons_show_contacts(filtered); + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } // show specific status } else { - if (group != NULL) { - cons_show("%s (%s):", group, presence); - } else { - cons_show("Contacts (%s):", presence); - } GSList *filtered = NULL; while (list != NULL) { @@ -937,7 +977,21 @@ cmd_who(gchar **args, struct cmd_help_t help) list = g_slist_next(list); } - cons_show_contacts(filtered); + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } } } } From 6a1975f65bdbd59575bca75c09d4a14430284b69 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 22 Jul 2014 23:22:50 +0100 Subject: [PATCH 2/4] Added _who_room function --- src/command/commands.c | 164 +++++++++++++++++++++-------------------- 1 file changed, 84 insertions(+), 80 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index b8d9b96c..b6f168b1 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -61,6 +61,7 @@ static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, static int _strtoi(char *str, int *saveptr, int min, int max); static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size); static gint _compare_commands(Command *a, Command *b); +static void _who_room(const char * const presence); extern GHashTable *commands; @@ -711,6 +712,88 @@ cmd_theme(gchar **args, struct cmd_help_t help) return TRUE; } +static void +_who_room(const char * const presence) +{ + char *room = ui_current_recipient(); + GList *list = muc_get_roster(room); + + // no arg, show all contacts + if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) { + ui_room_roster(room, list, NULL); + + // available + } else if (strcmp("available", presence) == 0) { + GList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + if (p_contact_is_available(contact)) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } + + ui_room_roster(room, filtered, "available"); + + // unavailable + } else if (strcmp("unavailable", presence) == 0) { + GList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + if (!p_contact_is_available(contact)) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } + + ui_room_roster(room, filtered, "unavailable"); + + // online, available resources + } else if (strcmp("online", presence) == 0) { + GList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + if (p_contact_has_available_resource(contact)) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } + + ui_room_roster(room, filtered, "online"); + + // offline, no available resources + } else if (strcmp("offline", presence) == 0) { + GList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + if (!p_contact_has_available_resource(contact)) { + filtered = g_list_append(filtered, contact); + } + list = g_list_next(list); + } + + ui_room_roster(room, filtered, "offline"); + + // 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); + } + + ui_room_roster(room, filtered, presence); + } +} + gboolean cmd_who(gchar **args, struct cmd_help_t help) { @@ -739,93 +822,14 @@ cmd_who(gchar **args, struct cmd_help_t help) && (strcmp(presence, "any") != 0)) { cons_show("Usage: %s", help.usage); - // valid arg } else { if (win_type == WIN_MUC) { if (group != NULL) { cons_show("The group argument is not valid when in a chat room."); - return TRUE; - } - - char *room = ui_current_recipient(); - GList *list = muc_get_roster(room); - - // no arg, show all contacts - if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) { - ui_room_roster(room, list, NULL); - - // available - } else if (strcmp("available", presence) == 0) { - GList *filtered = NULL; - - while (list != NULL) { - PContact contact = list->data; - if (p_contact_is_available(contact)) { - filtered = g_list_append(filtered, contact); - } - list = g_list_next(list); - } - - ui_room_roster(room, filtered, "available"); - - // unavailable - } else if (strcmp("unavailable", presence) == 0) { - GList *filtered = NULL; - - while (list != NULL) { - PContact contact = list->data; - if (!p_contact_is_available(contact)) { - filtered = g_list_append(filtered, contact); - } - list = g_list_next(list); - } - - ui_room_roster(room, filtered, "unavailable"); - - // online, available resources - } else if (strcmp("online", presence) == 0) { - GList *filtered = NULL; - - while (list != NULL) { - PContact contact = list->data; - if (p_contact_has_available_resource(contact)) { - filtered = g_list_append(filtered, contact); - } - list = g_list_next(list); - } - - ui_room_roster(room, filtered, "online"); - - // offline, no available resources - } else if (strcmp("offline", presence) == 0) { - GList *filtered = NULL; - - while (list != NULL) { - PContact contact = list->data; - if (!p_contact_has_available_resource(contact)) { - filtered = g_list_append(filtered, contact); - } - list = g_list_next(list); - } - - ui_room_roster(room, filtered, "offline"); - - // 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); - } - - ui_room_roster(room, filtered, presence); + _who_room(presence); } - // not in groupchat window } else { cons_show(""); GSList *list = NULL; From fd1d54088955c181a662f68506a01d79c1770e32 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 22 Jul 2014 23:27:36 +0100 Subject: [PATCH 3/4] Added _who_roster function --- src/command/commands.c | 339 +++++++++++++++++++++-------------------- 1 file changed, 173 insertions(+), 166 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index b6f168b1..49d0557f 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -62,6 +62,7 @@ static int _strtoi(char *str, int *saveptr, int min, int max); static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size); static gint _compare_commands(Command *a, Command *b); static void _who_room(const char * const presence); +static void _who_roster(const char * const group, const char * const presence); extern GHashTable *commands; @@ -794,6 +795,177 @@ _who_room(const char * const presence) } } +static void +_who_roster(const char * const group, const char * const presence) +{ + cons_show(""); + GSList *list = NULL; + if (group != NULL) { + list = roster_get_group(group); + } else { + list = roster_get_contacts(); + } + + // no arg, show all contacts + if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) { + if (group != NULL) { + if (list == NULL) { + cons_show("No contacts in group %s.", group); + } else { + cons_show("%s:", group); + cons_show_contacts(list); + } + } else { + if (list == NULL) { + cons_show("You have no contacts."); + } else { + cons_show("All contacts:"); + cons_show_contacts(list); + } + } + + // available + } else if (strcmp("available", presence) == 0) { + GSList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + if (p_contact_is_available(contact)) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } + + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } + + // unavailable + } else if (strcmp("unavailable", presence) == 0) { + GSList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + if (!p_contact_is_available(contact)) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } + + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } + + // online, available resources + } else if (strcmp("online", presence) == 0) { + GSList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + if (p_contact_has_available_resource(contact)) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } + + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } + + // offline, no available resources + } else if (strcmp("offline", presence) == 0) { + GSList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + if (!p_contact_has_available_resource(contact)) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } + + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } + + // show specific status + } else { + GSList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + if (strcmp(p_contact_presence(contact), presence) == 0) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } + + if (group != NULL) { + if (filtered == NULL) { + cons_show("No contacts in group %s are %s.", group, presence); + } else { + cons_show("%s (%s):", group, presence); + cons_show_contacts(filtered); + } + } else { + if (filtered == NULL) { + cons_show("No contacts are %s.", presence); + } else { + cons_show("Contacts (%s):", presence); + cons_show_contacts(filtered); + } + } + } +} + gboolean cmd_who(gchar **args, struct cmd_help_t help) { @@ -831,172 +1003,7 @@ cmd_who(gchar **args, struct cmd_help_t help) } } else { - cons_show(""); - GSList *list = NULL; - if (group != NULL) { - list = roster_get_group(group); - } else { - list = roster_get_contacts(); - } - - // no arg, show all contacts - if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) { - if (group != NULL) { - if (list == NULL) { - cons_show("No contacts in group %s.", group); - } else { - cons_show("%s:", group); - cons_show_contacts(list); - } - } else { - if (list == NULL) { - cons_show("You have no contacts."); - } else { - cons_show("All contacts:"); - cons_show_contacts(list); - } - } - - // available - } else if (strcmp("available", presence) == 0) { - GSList *filtered = NULL; - - while (list != NULL) { - PContact contact = list->data; - if (p_contact_is_available(contact)) { - filtered = g_slist_append(filtered, contact); - } - list = g_slist_next(list); - } - - if (group != NULL) { - if (filtered == NULL) { - cons_show("No contacts in group %s are %s.", group, presence); - } else { - cons_show("%s (%s):", group, presence); - cons_show_contacts(filtered); - } - } else { - if (filtered == NULL) { - cons_show("No contacts are %s.", presence); - } else { - cons_show("Contacts (%s):", presence); - cons_show_contacts(filtered); - } - } - - // unavailable - } else if (strcmp("unavailable", presence) == 0) { - GSList *filtered = NULL; - - while (list != NULL) { - PContact contact = list->data; - if (!p_contact_is_available(contact)) { - filtered = g_slist_append(filtered, contact); - } - list = g_slist_next(list); - } - - if (group != NULL) { - if (filtered == NULL) { - cons_show("No contacts in group %s are %s.", group, presence); - } else { - cons_show("%s (%s):", group, presence); - cons_show_contacts(filtered); - } - } else { - if (filtered == NULL) { - cons_show("No contacts are %s.", presence); - } else { - cons_show("Contacts (%s):", presence); - cons_show_contacts(filtered); - } - } - - // online, available resources - } else if (strcmp("online", presence) == 0) { - GSList *filtered = NULL; - - while (list != NULL) { - PContact contact = list->data; - if (p_contact_has_available_resource(contact)) { - filtered = g_slist_append(filtered, contact); - } - list = g_slist_next(list); - } - - if (group != NULL) { - if (filtered == NULL) { - cons_show("No contacts in group %s are %s.", group, presence); - } else { - cons_show("%s (%s):", group, presence); - cons_show_contacts(filtered); - } - } else { - if (filtered == NULL) { - cons_show("No contacts are %s.", presence); - } else { - cons_show("Contacts (%s):", presence); - cons_show_contacts(filtered); - } - } - - // offline, no available resources - } else if (strcmp("offline", presence) == 0) { - GSList *filtered = NULL; - - while (list != NULL) { - PContact contact = list->data; - if (!p_contact_has_available_resource(contact)) { - filtered = g_slist_append(filtered, contact); - } - list = g_slist_next(list); - } - - if (group != NULL) { - if (filtered == NULL) { - cons_show("No contacts in group %s are %s.", group, presence); - } else { - cons_show("%s (%s):", group, presence); - cons_show_contacts(filtered); - } - } else { - if (filtered == NULL) { - cons_show("No contacts are %s.", presence); - } else { - cons_show("Contacts (%s):", presence); - cons_show_contacts(filtered); - } - } - - // show specific status - } else { - GSList *filtered = NULL; - - while (list != NULL) { - PContact contact = list->data; - if (strcmp(p_contact_presence(contact), presence) == 0) { - filtered = g_slist_append(filtered, contact); - } - list = g_slist_next(list); - } - - if (group != NULL) { - if (filtered == NULL) { - cons_show("No contacts in group %s are %s.", group, presence); - } else { - cons_show("%s (%s):", group, presence); - cons_show_contacts(filtered); - } - } else { - if (filtered == NULL) { - cons_show("No contacts are %s.", presence); - } else { - cons_show("Contacts (%s):", presence); - cons_show_contacts(filtered); - } - } - } + _who_roster(group, presence); } } } From 9123675c9c203fcf21f86ec49043fa58d63bea5e Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 22 Jul 2014 23:31:14 +0100 Subject: [PATCH 4/4] Show message when no group or empty roster on /who --- src/command/commands.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/command/commands.c b/src/command/commands.c index 49d0557f..be6f4dfb 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -802,8 +802,16 @@ _who_roster(const char * const group, const char * const presence) GSList *list = NULL; if (group != NULL) { list = roster_get_group(group); + if (list == NULL) { + cons_show("No such group: %s.", group); + return; + } } else { list = roster_get_contacts(); + if (list == NULL) { + cons_show("No contacts in roster."); + return; + } } // no arg, show all contacts