From 846d3f848a62de321a9f5e7bb554ab449e43e68d Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 30 Nov 2012 00:19:03 +0000 Subject: [PATCH] Allow /msg with no message, to open a chat window with a contact --- src/command.c | 36 +++++++++++++++++++++--------------- src/ui.h | 1 + src/windows.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/command.c b/src/command.c index 8b4cd556..7a7e900b 100644 --- a/src/command.c +++ b/src/command.c @@ -220,18 +220,15 @@ static struct cmd_t main_commands[] = NULL } } }, { "/msg", - _cmd_msg, parse_args_with_freetext, 2, 2, - { "/msg user@host mesg", "Send mesg to user.", - { "/msg user@host mesg", - "-------------------", - "Send a message to the user specified.", - "Use tab completion to autocomplete online contacts.", - "If there is no current chat with the recipient, a new chat window", - "will be opened, and highlighted in the status bar at the bottom.", - "pressing the corresponding F key will take you to that window.", - "This command can be called from any window, including chat with other users.", + _cmd_msg, parse_args_with_freetext, 1, 2, + { "/msg user@host [message]", "Start chat window with user.", + { "/msg user@host [message]", + "------------------------", + "Open a chat window with user@host and send the message if one is supplied.", + "Use tab completion to autocomplete conacts from the roster.", "", - "Example : /msg boothj5@gmail.com Hey, here's a message!", + "Example : /msg myfriend@server.com Hey, here's a message!", + "Example : /msg otherfriend@server.com", NULL } } }, { "/info", @@ -1402,9 +1399,15 @@ _cmd_msg(gchar **args, struct cmd_help_t help) if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); - } else if (ui_windows_full()) { + return TRUE; + } + + if (ui_windows_full()) { cons_bad_show("Windows all used, close a window and try again."); - } else { + return TRUE; + } + + if (msg != NULL) { jabber_send(msg, usr); win_show_outgoing_msg("me", usr, msg); @@ -1412,9 +1415,12 @@ _cmd_msg(gchar **args, struct cmd_help_t help) const char *jid = jabber_get_jid(); chat_log_chat(jid, usr, msg, OUT, NULL); } - } - return TRUE; + return TRUE; + } else { + win_new_chat_win(usr); + return TRUE; + } } static gboolean diff --git a/src/ui.h b/src/ui.h index b6ec9085..0edcb2ab 100644 --- a/src/ui.h +++ b/src/ui.h @@ -107,6 +107,7 @@ void win_show_gone(const char * const from); void win_show_system_msg(const char * const from, const char *message); void win_show_outgoing_msg(const char * const from, const char * const to, const char * const message); +void win_new_chat_win(const char * const to); void win_join_chat(const char * const room, const char * const nick); void win_show_room_roster(const char * const room); diff --git a/src/windows.c b/src/windows.c index f2d2cebe..9ef29d88 100644 --- a/src/windows.c +++ b/src/windows.c @@ -637,6 +637,39 @@ win_show_gone(const char * const from) } } +void +win_new_chat_win(const char * const to) +{ + // if the contact is offline, show a message + PContact contact = contact_list_get_contact(to); + int win_index = _find_prof_win_index(to); + WINDOW *win = NULL; + + // create new window + if (win_index == NUM_WINS) { + win_index = _new_prof_win(to, WIN_CHAT); + win = windows[win_index]->win; + + if (prefs_get_chlog() && prefs_get_history()) { + _win_show_history(win, win_index, to); + } + + if (contact != NULL) { + if (strcmp(p_contact_presence(contact), "offline") == 0) { + const char const *show = p_contact_presence(contact); + const char const *status = p_contact_status(contact); + _show_status_string(win, to, show, status, "--", "offline"); + } + } + + // use existing window + } else { + win = windows[win_index]->win; + } + + ui_switch_win(win_index); +} + void win_show_outgoing_msg(const char * const from, const char * const to, const char * const message)