Added argument to /who command to specify status

This commit is contained in:
James Booth
2012-10-04 22:48:41 +01:00
parent dcf5e9ef16
commit 9e23060986
3 changed files with 99 additions and 42 deletions

View File

@@ -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;