diff --git a/src/command.c b/src/command.c index 45f4f00c..cdb0c384 100644 --- a/src/command.c +++ b/src/command.c @@ -155,10 +155,12 @@ static struct cmd_t main_commands[] = { "/who", _cmd_who, - { "/who", "Find out who is online.", - { "/who", - "----", - "Show the list of all online contacts with their current status message.", + { "/who [status]", "Show contacts with chosen status.", + { "/who [status]", + "-------------", + "Show contacts with the specified status, no status shows all contacts.", + "Possible statuses are: online, offline, away, dnd, xa, chat.", + "online includes: chat, dnd, away, xa.", NULL } } }, { "/close", diff --git a/src/contact_list.c b/src/contact_list.c index 328b8d04..22a52659 100644 --- a/src/contact_list.c +++ b/src/contact_list.c @@ -20,6 +20,8 @@ * */ +#include + #include "contact.h" #include "prof_autocomplete.h" @@ -70,3 +72,19 @@ find_contact(char *search_str) { return p_autocomplete_complete(ac, search_str); } + +PContact +contact_list_get_contact(const char const *jid) +{ + GSList *contacts = get_contact_list(); + + while (contacts != NULL) { + PContact contact = contacts->data; + if (strcmp(p_contact_name(contact), jid) == 0) { + return contact; + } + contacts = g_slist_next(contacts); + } + + return NULL; +} diff --git a/src/contact_list.h b/src/contact_list.h index 4790a286..7d89b88c 100644 --- a/src/contact_list.h +++ b/src/contact_list.h @@ -25,6 +25,8 @@ #include +#include "contact.h" + void contact_list_init(void); void contact_list_clear(void); void reset_search_attempts(void); @@ -33,5 +35,6 @@ gboolean contact_list_add(const char * const name, const char * const show, gboolean contact_list_remove(const char * const name); GSList * get_contact_list(void); char * find_contact(char *search_str); +PContact contact_list_get_contact(const char const *jid); #endif diff --git a/src/windows.c b/src/windows.c index 724a904f..872a3617 100644 --- a/src/windows.c +++ b/src/windows.c @@ -38,6 +38,7 @@ #include "command.h" #include "contact.h" +#include "contact_list.h" #include "log.h" #include "preferences.h" #include "ui.h" @@ -357,15 +358,23 @@ void win_show_outgoing_msg(const char * const from, const char * const to, const char * const message) { - int win_index = _find_prof_win_index(to); - if (win_index == NUM_WINS) - win_index = _new_prof_win(to); + // if the contact is offline, show a message + PContact contact = contact_list_get_contact(to); + + if (contact == NULL) { + cons_show("%s is not one of your contacts."); + } else { + int win_index = _find_prof_win_index(to); - WINDOW *win = _wins[win_index].win; - _win_show_time(win); - _win_show_user(win, from, 0); - _win_show_message(win, message); - _win_switch_if_active(win_index); + if (win_index == NUM_WINS) + win_index = _new_prof_win(to); + + WINDOW *win = _wins[win_index].win; + _win_show_time(win); + _win_show_user(win, from, 0); + _win_show_message(win, message); + _win_switch_if_active(win_index); + } } void