mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added fallback message error handlers
This commit is contained in:
parent
678a5bd05c
commit
27293ebbc2
@ -61,6 +61,18 @@ handle_recipient_not_found(const char * const recipient, const char * const err_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
handle_recipient_error(const char * const recipient, const char * const err_msg)
|
||||||
|
{
|
||||||
|
ui_handle_recipient_error(recipient, err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
handle_error(const char * const err_msg)
|
||||||
|
{
|
||||||
|
ui_handle_error(err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
handle_login_account_success(char *account_name)
|
handle_login_account_success(char *account_name)
|
||||||
{
|
{
|
||||||
|
@ -76,5 +76,7 @@ void handle_roster_remove(const char * const barejid);
|
|||||||
void handle_roster_add(const char * const barejid, const char * const name);
|
void handle_roster_add(const char * const barejid, const char * const name);
|
||||||
void handle_autoping_cancel(void);
|
void handle_autoping_cancel(void);
|
||||||
void handle_recipient_not_found(const char * const recipient, const char * const err_msg);
|
void handle_recipient_not_found(const char * const recipient, const char * const err_msg);
|
||||||
|
void handle_recipient_error(const char * const recipient, const char * const err_msg);
|
||||||
|
void handle_error(const char * const err_msg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -387,6 +387,39 @@ _ui_handle_recipient_not_found(const char * const recipient, const char * const
|
|||||||
g_string_free(msg, TRUE);
|
g_string_free(msg, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_ui_handle_recipient_error(const char * const recipient, const char * const err_msg)
|
||||||
|
{
|
||||||
|
ProfWin *win = wins_get_by_recipient(recipient);
|
||||||
|
GString *msg = g_string_new("");
|
||||||
|
g_string_printf(msg, "Error from %s: %s", recipient, err_msg);
|
||||||
|
|
||||||
|
// always show in console
|
||||||
|
cons_show_error(msg->str);
|
||||||
|
|
||||||
|
// show in window if exists for recipient
|
||||||
|
if (win != NULL) {
|
||||||
|
win_print_line(win, '!', COLOUR_ERROR, msg->str);
|
||||||
|
}
|
||||||
|
|
||||||
|
wins_refresh_current();
|
||||||
|
|
||||||
|
g_string_free(msg, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_ui_handle_error(const char * const err_msg)
|
||||||
|
{
|
||||||
|
GString *msg = g_string_new("");
|
||||||
|
g_string_printf(msg, "Error %s", err_msg);
|
||||||
|
|
||||||
|
cons_show_error(msg->str);
|
||||||
|
|
||||||
|
wins_refresh_current();
|
||||||
|
|
||||||
|
g_string_free(msg, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_ui_disconnected(void)
|
_ui_disconnected(void)
|
||||||
{
|
{
|
||||||
@ -1752,4 +1785,6 @@ ui_init_module(void)
|
|||||||
ui_chat_win_contact_online = _ui_chat_win_contact_online;
|
ui_chat_win_contact_online = _ui_chat_win_contact_online;
|
||||||
ui_chat_win_contact_offline = _ui_chat_win_contact_offline;
|
ui_chat_win_contact_offline = _ui_chat_win_contact_offline;
|
||||||
ui_handle_recipient_not_found = _ui_handle_recipient_not_found;
|
ui_handle_recipient_not_found = _ui_handle_recipient_not_found;
|
||||||
|
ui_handle_recipient_error = _ui_handle_recipient_error;
|
||||||
|
ui_handle_error = _ui_handle_error;
|
||||||
}
|
}
|
||||||
|
@ -131,6 +131,8 @@ 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_online)(PContact contact, Resource *resource, GDateTime *last_activity);
|
||||||
void (*ui_chat_win_contact_offline)(PContact contact, char *resource, char *status);
|
void (*ui_chat_win_contact_offline)(PContact contact, char *resource, char *status);
|
||||||
void (*ui_handle_recipient_not_found)(const char * const recipient, const char * const err_msg);
|
void (*ui_handle_recipient_not_found)(const char * const recipient, const char * const err_msg);
|
||||||
|
void (*ui_handle_recipient_error)(const char * const recipient, const char * const err_msg);
|
||||||
|
void (*ui_handle_error)(const char * const err_msg);
|
||||||
|
|
||||||
// contact status functions
|
// contact status functions
|
||||||
void (*ui_status_room)(const char * const contact);
|
void (*ui_status_room)(const char * const contact);
|
||||||
|
@ -193,9 +193,10 @@ static int
|
|||||||
_message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
_message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
void * const userdata)
|
void * const userdata)
|
||||||
{
|
{
|
||||||
// log message, function never returns NULL
|
|
||||||
char *id = xmpp_stanza_get_id(stanza);
|
char *id = xmpp_stanza_get_id(stanza);
|
||||||
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||||
|
|
||||||
|
// stanza_get_error never returns NULL
|
||||||
char *err_msg = stanza_get_error_message(stanza);
|
char *err_msg = stanza_get_error_message(stanza);
|
||||||
|
|
||||||
GString *log_msg = g_string_new("Error receievd");
|
GString *log_msg = g_string_new("Error receievd");
|
||||||
@ -225,6 +226,14 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
// handle recipient not found ('from' contains a value and type is 'cancel')
|
// handle recipient not found ('from' contains a value and type is 'cancel')
|
||||||
if ((from != NULL) && ((type != NULL && (strcmp(type, "cancel") == 0)))) {
|
if ((from != NULL) && ((type != NULL && (strcmp(type, "cancel") == 0)))) {
|
||||||
handle_recipient_not_found(from, err_msg);
|
handle_recipient_not_found(from, err_msg);
|
||||||
|
|
||||||
|
// handle any other error from recipient
|
||||||
|
} else if (from != NULL) {
|
||||||
|
handle_recipient_error(from, err_msg);
|
||||||
|
|
||||||
|
// handle errors from no recipient
|
||||||
|
} else {
|
||||||
|
handle_error(err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user