diff options
author | James Booth <boothj5@gmail.com> | 2012-10-04 22:48:41 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-10-04 22:48:41 +0100 |
commit | 9e2306098617dad0683e7024dc9c0695a428a29a (patch) | |
tree | e9f1dc39722a49178e338848a62238598d0cbc63 /src/command.c | |
parent | dcf5e9ef169aba102b9035f05b55e338de2001a8 (diff) | |
download | profani-tty-9e2306098617dad0683e7024dc9c0695a428a29a.tar.gz |
Added argument to /who command to specify status
Diffstat (limited to 'src/command.c')
-rw-r--r-- | src/command.c | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/src/command.c b/src/command.c index 524c6c04..45f4f00c 100644 --- a/src/command.c +++ b/src/command.c @@ -27,6 +27,7 @@ #include "command.h" #include "common.h" +#include "contact.h" #include "contact_list.h" #include "chat_log.h" #include "history.h" @@ -558,8 +559,69 @@ _cmd_who(const char * const inp, struct cmd_help_t help) if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); } else { - GSList *list = get_contact_list(); - cons_show_online_contacts(list); + // copy input + char inp_cpy[strlen(inp) + 1]; + strcpy(inp_cpy, inp); + + // get show + strtok(inp_cpy, " "); + char *show = strtok(NULL, " "); + + // bad arg + if ((show != NULL) + && (strcmp(show, "online") != 0) + && (strcmp(show, "offline") != 0) + && (strcmp(show, "away") != 0) + && (strcmp(show, "chat") != 0) + && (strcmp(show, "xa") != 0) + && (strcmp(show, "dnd") != 0)) { + cons_show("Usage: %s", help.usage); + + // valid arg + } else { + GSList *list = get_contact_list(); + + // no arg, show all contacts + if (show == NULL) { + cons_show("All contacts:"); + cons_show_contacts(list); + + // online, show all status that indicate online + } else if (strcmp("online", show) == 0) { + cons_show("Contacts (%s):", show); + GSList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + const char * const contact_show = (p_contact_show(contact)); + if ((strcmp(contact_show, "online") == 0) + || (strcmp(contact_show, "away") == 0) + || (strcmp(contact_show, "dnd") == 0) + || (strcmp(contact_show, "xa") == 0) + || (strcmp(contact_show, "chat") == 0)) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } + + cons_show_contacts(filtered); + + // show specific status + } else { + cons_show("Contacts (%s):", show); + GSList *filtered = NULL; + + while (list != NULL) { + PContact contact = list->data; + if (strcmp(p_contact_show(contact), show) == 0) { + filtered = g_slist_append(filtered, contact); + } + list = g_slist_next(list); + } + + cons_show_contacts(filtered); + } + } } return TRUE; |