diff --git a/src/server_events.c b/src/server_events.c index beec7275..051ce1a3 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -54,12 +54,11 @@ handle_error_message(const char *from, const char *err_msg) } void -handle_recipient_not_found(const char *from) +handle_recipient_not_found(const char * const recipient, const char * const err_msg) { - log_info("Removing chat session for %s", from); - ui_handle_recipient_not_found(from); - if (prefs_get_boolean(PREF_STATES)) { - chat_session_set_recipient_supports(from, FALSE); + ui_handle_recipient_not_found(recipient, err_msg); + if (prefs_get_boolean(PREF_STATES) && chat_session_exists(recipient)) { + chat_session_set_recipient_supports(recipient, FALSE); } } diff --git a/src/server_events.h b/src/server_events.h index 34f99c79..794d96dc 100644 --- a/src/server_events.h +++ b/src/server_events.h @@ -75,6 +75,6 @@ void handle_group_remove(const char * const contact, void handle_roster_remove(const char * const barejid); void handle_roster_add(const char * const barejid, const char * const name); void handle_autoping_cancel(void); -void handle_recipient_not_found(const char *from); +void handle_recipient_not_found(const char * const recipient, const char * const err_msg); #endif diff --git a/src/ui/core.c b/src/ui/core.c index 717bf965..54236cfb 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -358,26 +358,33 @@ _ui_handle_error_message(const char * const from, const char * const err_msg) } static void -_ui_handle_recipient_not_found(const char * const from) +_ui_handle_recipient_not_found(const char * const recipient, const char * const err_msg) { - ProfWin *win = wins_get_by_recipient(from); + ProfWin *win = wins_get_by_recipient(recipient); GString *msg = g_string_new(""); - // Message sent to chat room which hasn't been entered yet - if (win->type == WIN_MUC) { - g_string_printf(msg, "You have not joined %s.", from); + // no window for intended recipient, show message in current and console + if (win == NULL) { + g_string_printf(msg, "Recipient %s not found: %s", recipient, err_msg); + cons_show_error(msg->str); + win = wins_get_current(); + if (win->type != WIN_CONSOLE) { + win_print_line(win, '!', COLOUR_ERROR, msg->str); + } + + // intended recipient was invalid chat room + } else if (win->type == WIN_MUC) { + g_string_printf(msg, "Room %s not found: %s", recipient, err_msg); + cons_show_error(msg->str); + win_print_line(win, '!', COLOUR_ERROR, msg->str); // unknown chat recipient } else { - if (prefs_get_boolean(PREF_STATES)) { - chat_session_set_recipient_supports(from, FALSE); - } - g_string_printf(msg, "Recipient %s not found at server.", from); + g_string_printf(msg, "Recipient %s not found: %s", recipient, err_msg); + cons_show_error(msg->str); + win_print_line(win, '!', COLOUR_ERROR, msg->str); } - cons_show_error(msg->str); - win_print_line(win, '!', COLOUR_ERROR, msg->str); - wins_refresh_current(); g_string_free(msg, TRUE); diff --git a/src/ui/ui.h b/src/ui/ui.h index 8f539459..cd72e6fa 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -130,7 +130,7 @@ void (*ui_group_added)(const char * const contact, const char * const group); void (*ui_group_removed)(const char * const contact, const char * const group); void (*ui_chat_win_contact_online)(PContact contact, Resource *resource, GDateTime *last_activity); void (*ui_chat_win_contact_offline)(PContact contact, char *resource, char *status); -void (*ui_handle_recipient_not_found)(const char * const from); +void (*ui_handle_recipient_not_found)(const char * const recipient, const char * const err_msg); // contact status functions void (*ui_status_room)(const char * const contact); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index bb5c58eb..236999b9 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -194,15 +194,28 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { // log message, function never returns NULL - char *err_msg = stanza_get_error_message(stanza); char *id = xmpp_stanza_get_id(stanza); - if (id != NULL) { - log_info("Error recieved (id=%s): %s", id, err_msg); - } else { - log_info("Error received: %s", err_msg); - } - char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + char *err_msg = stanza_get_error_message(stanza); + + GString *log_msg = g_string_new("Error receievd"); + if (id != NULL) { + g_string_append(log_msg, " (id:"); + g_string_append(log_msg, id); + g_string_append(log_msg, ")"); + } + if (from != NULL) { + g_string_append(log_msg, " (from:"); + g_string_append(log_msg, from); + g_string_append(log_msg, ")"); + } + g_string_append(log_msg, ", error: "); + g_string_append(log_msg, err_msg); + + log_info(log_msg->str); + + g_string_free(log_msg, TRUE); + xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); char *type = NULL; if (error_stanza != NULL) { @@ -211,8 +224,8 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // handle recipient not found if ((from != NULL) && ((type != NULL && (strcmp(type, "cancel") == 0)))) { - log_info("Recipient %s not found.", from); - handle_recipient_not_found(from); + char *cpy = strdup(from); + handle_recipient_not_found(cpy, err_msg); } return 1;