mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Added argument to /who command to specify status
This commit is contained in:
parent
dcf5e9ef16
commit
9e23060986
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "contact.h"
|
||||||
#include "contact_list.h"
|
#include "contact_list.h"
|
||||||
#include "chat_log.h"
|
#include "chat_log.h"
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
@ -558,8 +559,69 @@ _cmd_who(const char * const inp, struct cmd_help_t help)
|
|||||||
if (conn_status != JABBER_CONNECTED) {
|
if (conn_status != JABBER_CONNECTED) {
|
||||||
cons_show("You are not currently connected.");
|
cons_show("You are not currently connected.");
|
||||||
} else {
|
} else {
|
||||||
GSList *list = get_contact_list();
|
// copy input
|
||||||
cons_show_online_contacts(list);
|
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;
|
return TRUE;
|
||||||
|
2
src/ui.h
2
src/ui.h
@ -107,7 +107,7 @@ void cons_bad_command(const char * const cmd);
|
|||||||
void cons_show(const char * const cmd, ...);
|
void cons_show(const char * const cmd, ...);
|
||||||
void cons_bad_show(const char * const cmd);
|
void cons_bad_show(const char * const cmd);
|
||||||
void cons_highlight_show(const char * const cmd);
|
void cons_highlight_show(const char * const cmd);
|
||||||
void cons_show_online_contacts(GSList * list);
|
void cons_show_contacts(GSList * list);
|
||||||
|
|
||||||
// status bar actions
|
// status bar actions
|
||||||
void status_bar_refresh(void);
|
void status_bar_refresh(void);
|
||||||
|
@ -554,55 +554,50 @@ cons_help(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cons_show_online_contacts(GSList *list)
|
cons_show_contacts(GSList *list)
|
||||||
{
|
{
|
||||||
_win_show_time(_cons_win);
|
|
||||||
wprintw(_cons_win, "Online contacts:\n");
|
|
||||||
|
|
||||||
GSList *curr = list;
|
GSList *curr = list;
|
||||||
|
|
||||||
while(curr) {
|
while(curr) {
|
||||||
PContact contact = curr->data;
|
PContact contact = curr->data;
|
||||||
const char *show = p_contact_show(contact);
|
const char *show = p_contact_show(contact);
|
||||||
|
|
||||||
if (strcmp(show, "offline") != 0) {
|
_win_show_time(_cons_win);
|
||||||
_win_show_time(_cons_win);
|
|
||||||
|
|
||||||
if (strcmp(show, "online") == 0) {
|
if (strcmp(show, "online") == 0) {
|
||||||
wattron(_cons_win, COLOUR_ONLINE);
|
wattron(_cons_win, COLOUR_ONLINE);
|
||||||
} else if (strcmp(show, "away") == 0) {
|
} else if (strcmp(show, "away") == 0) {
|
||||||
wattron(_cons_win, COLOUR_AWAY);
|
wattron(_cons_win, COLOUR_AWAY);
|
||||||
} else if (strcmp(show, "chat") == 0) {
|
} else if (strcmp(show, "chat") == 0) {
|
||||||
wattron(_cons_win, COLOUR_CHAT);
|
wattron(_cons_win, COLOUR_CHAT);
|
||||||
} else if (strcmp(show, "dnd") == 0) {
|
} else if (strcmp(show, "dnd") == 0) {
|
||||||
wattron(_cons_win, COLOUR_DND);
|
wattron(_cons_win, COLOUR_DND);
|
||||||
} else if (strcmp(show, "xa") == 0) {
|
} else if (strcmp(show, "xa") == 0) {
|
||||||
wattron(_cons_win, COLOUR_XA);
|
wattron(_cons_win, COLOUR_XA);
|
||||||
} else {
|
} else {
|
||||||
wattron(_cons_win, COLOUR_OFFLINE);
|
wattron(_cons_win, COLOUR_OFFLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
wprintw(_cons_win, "%s", p_contact_name(contact));
|
wprintw(_cons_win, "%s", p_contact_name(contact));
|
||||||
wprintw(_cons_win, " is %s", show);
|
wprintw(_cons_win, " is %s", show);
|
||||||
|
|
||||||
if (p_contact_status(contact))
|
if (p_contact_status(contact))
|
||||||
wprintw(_cons_win, ", \"%s\"", p_contact_status(contact));
|
wprintw(_cons_win, ", \"%s\"", p_contact_status(contact));
|
||||||
|
|
||||||
wprintw(_cons_win, "\n");
|
wprintw(_cons_win, "\n");
|
||||||
|
|
||||||
if (strcmp(show, "online") == 0) {
|
if (strcmp(show, "online") == 0) {
|
||||||
wattroff(_cons_win, COLOUR_ONLINE);
|
wattroff(_cons_win, COLOUR_ONLINE);
|
||||||
} else if (strcmp(show, "away") == 0) {
|
} else if (strcmp(show, "away") == 0) {
|
||||||
wattroff(_cons_win, COLOUR_AWAY);
|
wattroff(_cons_win, COLOUR_AWAY);
|
||||||
} else if (strcmp(show, "chat") == 0) {
|
} else if (strcmp(show, "chat") == 0) {
|
||||||
wattroff(_cons_win, COLOUR_CHAT);
|
wattroff(_cons_win, COLOUR_CHAT);
|
||||||
} else if (strcmp(show, "dnd") == 0) {
|
} else if (strcmp(show, "dnd") == 0) {
|
||||||
wattroff(_cons_win, COLOUR_DND);
|
wattroff(_cons_win, COLOUR_DND);
|
||||||
} else if (strcmp(show, "xa") == 0) {
|
} else if (strcmp(show, "xa") == 0) {
|
||||||
wattroff(_cons_win, COLOUR_XA);
|
wattroff(_cons_win, COLOUR_XA);
|
||||||
} else {
|
} else {
|
||||||
wattroff(_cons_win, COLOUR_OFFLINE);
|
wattroff(_cons_win, COLOUR_OFFLINE);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
curr = g_slist_next(curr);
|
curr = g_slist_next(curr);
|
||||||
|
Loading…
Reference in New Issue
Block a user