From 5fbf966b9ce62dd905159fcd9eaa4b2d3187eae6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 11 Jan 2013 01:35:25 +0000 Subject: [PATCH] Check nick exists when private messaging Show nick part of jid in private messaging --- src/command.c | 41 +++++++++++++++++++++++++++++++++-------- src/windows.c | 15 ++++++++++----- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/command.c b/src/command.c index 9310c7d9..c8b078f5 100644 --- a/src/command.c +++ b/src/command.c @@ -1532,19 +1532,44 @@ _cmd_msg(gchar **args, struct cmd_help_t help) return TRUE; } - if (msg != NULL) { - jabber_send(msg, usr); - win_show_outgoing_msg("me", usr, msg); + if (win_current_is_groupchat()) { + char *room_name = win_current_get_recipient(); + if (room_nick_in_roster(room_name, usr)) { + GString *full_jid = g_string_new(room_name); + g_string_append(full_jid, "/"); + g_string_append(full_jid, usr); - if (prefs_get_chlog()) { - const char *jid = jabber_get_jid(); - chat_log_chat(jid, usr, msg, PROF_OUT_LOG, NULL); + jabber_send(msg, full_jid->str); + win_show_outgoing_msg("me", full_jid->str, msg); + + if (prefs_get_chlog()) { + const char *jid = jabber_get_jid(); + chat_log_chat(jid, full_jid->str, msg, PROF_OUT_LOG, NULL); + } + + g_string_free(full_jid, TRUE); + + } else { + cons_show("No such nick \"%s\" in room %s.", usr, room_name); } return TRUE; + } else { - win_new_chat_win(usr); - return TRUE; + if (msg != NULL) { + jabber_send(msg, usr); + win_show_outgoing_msg("me", usr, msg); + + if (prefs_get_chlog()) { + const char *jid = jabber_get_jid(); + chat_log_chat(jid, usr, msg, PROF_OUT_LOG, NULL); + } + + return TRUE; + } else { + win_new_chat_win(usr); + return TRUE; + } } } diff --git a/src/windows.c b/src/windows.c index addae801..f4fb9c0b 100644 --- a/src/windows.c +++ b/src/windows.c @@ -326,11 +326,14 @@ void ui_show_incoming_msg(const char * const from, const char * const message, GTimeVal *tv_stamp, gboolean priv) { + char *display_from; win_type_t win_type; if (priv) { win_type = WIN_PRIVATE; + display_from = room_get_nick_from_full_jid(from); } else { win_type = WIN_CHAT; + display_from = strdup(from); } int win_index = _find_prof_win_index(from); @@ -390,12 +393,12 @@ ui_show_incoming_msg(const char * const from, const char * const message, if (strncmp(message, "/me ", 4) == 0) { wattron(win, COLOUR_THEM); - wprintw(win, "*%s ", from); + wprintw(win, "*%s ", display_from); wprintw(win, message + 4); wprintw(win, "\n"); wattroff(win, COLOUR_THEM); } else { - _win_show_user(win, from, 1); + _win_show_user(win, display_from, 1); _win_show_message(win, message); } title_bar_set_typing(FALSE); @@ -429,12 +432,12 @@ ui_show_incoming_msg(const char * const from, const char * const message, if (strncmp(message, "/me ", 4) == 0) { wattron(win, COLOUR_THEM); - wprintw(win, "*%s ", from); + wprintw(win, "*%s ", display_from); wprintw(win, message + 4); wprintw(win, "\n"); wattroff(win, COLOUR_THEM); } else { - _win_show_user(win, from, 1); + _win_show_user(win, display_from, 1); _win_show_message(win, message); } } @@ -443,7 +446,9 @@ ui_show_incoming_msg(const char * const from, const char * const message, if (prefs_get_beep()) beep(); if (prefs_get_notify_message()) - _notify_message(from); + _notify_message(display_from); + + g_free(display_from); } void