diff --git a/src/command.c b/src/command.c index 240220c6..cdb0c384 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" @@ -63,7 +64,6 @@ static gboolean _cmd_quit(const char * const inp, struct cmd_help_t help); static gboolean _cmd_help(const char * const inp, struct cmd_help_t help); static gboolean _cmd_prefs(const char * const inp, struct cmd_help_t help); static gboolean _cmd_who(const char * const inp, struct cmd_help_t help); -static gboolean _cmd_ros(const char * const inp, struct cmd_help_t help); static gboolean _cmd_connect(const char * const inp, struct cmd_help_t help); static gboolean _cmd_msg(const char * const inp, struct cmd_help_t help); static gboolean _cmd_tiny(const char * const inp, struct cmd_help_t help); @@ -153,21 +153,14 @@ static struct cmd_t main_commands[] = "Example : /tiny http://www.google.com", NULL } } }, - { "/ros", - _cmd_ros, - { "/ros", "List all contacts.", - { "/ros", - "----", - "List all contact currently on the chat hosts roster.", - "See /who for a more useful list of contacts who are currently online.", - NULL } } }, - { "/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", @@ -560,19 +553,6 @@ _cmd_prefs(const char * const inp, struct cmd_help_t help) return TRUE; } -static gboolean -_cmd_ros(const char * const inp, struct cmd_help_t help) -{ - jabber_conn_status_t conn_status = jabber_get_connection_status(); - - if (conn_status != JABBER_CONNECTED) - cons_show("You are not currently connected."); - else - jabber_roster_request(); - - return TRUE; -} - static gboolean _cmd_who(const char * const inp, struct cmd_help_t help) { @@ -581,8 +561,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; 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/input_win.c b/src/input_win.c index be030f29..308d4046 100644 --- a/src/input_win.c +++ b/src/input_win.c @@ -110,7 +110,7 @@ inp_clear(void) void inp_non_block(void) { - wtimeout(inp_win, 500); + wtimeout(inp_win, 20); } void diff --git a/src/jabber.c b/src/jabber.c index b51d5f68..da606132 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -301,6 +301,7 @@ _connection_handler(xmpp_conn_t * const conn, jabber_conn.conn_status = JABBER_CONNECTED; jabber_conn.presence = PRESENCE_ONLINE; + jabber_roster_request(); } else { // received close stream response from server after disconnect diff --git a/src/profanity.c b/src/profanity.c index e134d2f0..1a56f0cb 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -55,10 +55,12 @@ prof_run(const int disable_tls, char *log_level) GTimer *timer = g_timer_new(); gboolean cmd_result = TRUE; + char inp[INP_WIN_MAX]; + int size = 0; + while(cmd_result == TRUE) { int ch = ERR; - char inp[INP_WIN_MAX]; - int size = 0; + size = 0; while(ch != '\n') { @@ -159,7 +161,7 @@ prof_handle_contact_online(char *contact, char *show, char *status) void prof_handle_contact_offline(char *contact, char *show, char *status) { - gboolean result = contact_list_remove(contact); + gboolean result = contact_list_add(contact, "offline", status); if (result) { win_contact_offline(contact, show, status); } @@ -169,19 +171,15 @@ prof_handle_contact_offline(char *contact, char *show, char *status) void prof_handle_roster(GSList *roster) { - cons_show("Roster:"); while (roster != NULL) { jabber_roster_entry *entry = roster->data; - if (entry->name != NULL) { - cons_show("%s (%s)", entry->name, entry->jid); - - } else { - cons_show("%s", entry->jid); + + // if contact not in contact list add them as offline + if (find_contact(entry->jid) == NULL) { + contact_list_add(entry->jid, "offline", NULL); } roster = g_slist_next(roster); - - win_page_off(); } g_slist_free_full(roster, (GDestroyNotify)_free_roster_entry); diff --git a/src/status_bar.c b/src/status_bar.c index 3a22d3db..d9ae4aee 100644 --- a/src/status_bar.c +++ b/src/status_bar.c @@ -74,7 +74,6 @@ status_bar_refresh(void) if (elapsed >= 60000000) { dirty = TRUE; - g_date_time_unref(now_time); last_time = g_date_time_new_now_local(); } @@ -84,6 +83,8 @@ status_bar_refresh(void) inp_put_back(); dirty = FALSE; } + + g_date_time_unref(now_time); } void diff --git a/src/ui.h b/src/ui.h index 08c6bee9..df1eab66 100644 --- a/src/ui.h +++ b/src/ui.h @@ -107,7 +107,7 @@ void cons_bad_command(const char * const cmd); void cons_show(const char * const cmd, ...); void cons_bad_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 void status_bar_refresh(void); diff --git a/src/windows.c b/src/windows.c index 6bdc17d1..0c249b9a 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,33 @@ 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 = NULL; - 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); + win = _wins[win_index].win; + + if (strcmp(p_contact_show(contact), "offline") == 0) { + const char const *show = p_contact_show(contact); + const char const *status = p_contact_status(contact); + _show_status_string(win, to, show, status, "--", "offline"); + } + } else { + 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 @@ -554,17 +573,15 @@ cons_help(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; while(curr) { PContact contact = curr->data; - _win_show_time(_cons_win); const char *show = p_contact_show(contact); + + _win_show_time(_cons_win); if (strcmp(show, "online") == 0) { wattron(_cons_win, COLOUR_ONLINE); @@ -891,7 +908,7 @@ _show_status_string(WINDOW *win, const char * const from, const char * const default_show) { _win_show_time(win); - + if (show != NULL) { if (strcmp(show, "away") == 0) { wattron(win, COLOUR_AWAY); @@ -901,6 +918,10 @@ _show_status_string(WINDOW *win, const char * const from, wattron(win, COLOUR_DND); } else if (strcmp(show, "xa") == 0) { wattron(win, COLOUR_XA); + } else if (strcmp(show, "online") == 0) { + wattron(win, COLOUR_ONLINE); + } else { + wattron(win, COLOUR_OFFLINE); } } else if (strcmp(default_show, "online") == 0) { wattron(win, COLOUR_ONLINE); @@ -919,8 +940,8 @@ _show_status_string(WINDOW *win, const char * const from, wprintw(win, ", \"%s\"", status); wprintw(win, "\n"); - - if (show != NULL) { + + if (show != NULL) { if (strcmp(show, "away") == 0) { wattroff(win, COLOUR_AWAY); } else if (strcmp(show, "chat") == 0) { @@ -929,6 +950,10 @@ _show_status_string(WINDOW *win, const char * const from, wattroff(win, COLOUR_DND); } else if (strcmp(show, "xa") == 0) { wattroff(win, COLOUR_XA); + } else if (strcmp(show, "online") == 0) { + wattroff(win, COLOUR_ONLINE); + } else { + wattroff(win, COLOUR_OFFLINE); } } else if (strcmp(default_show, "online") == 0) { wattroff(win, COLOUR_ONLINE);