1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Refactored handle_presence_error, removed no longer used functions

This commit is contained in:
James Booth 2014-01-30 22:20:57 +00:00
parent 2cd24a484a
commit 12666b41e6
7 changed files with 16 additions and 84 deletions

View File

@ -39,17 +39,26 @@
// handle presence stanza errors
void
handle_presence_error(const char *from, const char *err_msg)
handle_presence_error(const char *from, const char * const type,
const char *err_msg)
{
ui_handle_error_message(from, err_msg);
// handle nickname conflict on entering room
if (g_strcmp0(err_msg, "conflict") == 0) {
// remove the room from muc
Jid *room_jid = jid_create(from);
if (!muc_get_roster_received(room_jid->barejid)) {
muc_leave_room(room_jid->barejid);
ui_handle_recipient_error(room_jid->barejid, err_msg);
}
jid_destroy(room_jid);
// handle any other error from recipient
} else if (from != NULL) {
ui_handle_recipient_error(from, err_msg);
// handle errors from no recipient
} else {
ui_handle_error(err_msg);
}
}

View File

@ -25,7 +25,6 @@
#include "xmpp/xmpp.h"
void handle_presence_error(const char *from, const char *err_msg);
void handle_login_account_success(char *account_name);
void handle_lost_connection(void);
void handle_failed_login(void);
@ -77,5 +76,7 @@ void handle_roster_add(const char * const barejid, const char * const name);
void handle_autoping_cancel(void);
void handle_message_error(const char * const from, const char * const type,
const char * const err_msg);
void handle_presence_error(const char *from, const char * const type,
const char *err_msg);
#endif

View File

@ -338,22 +338,6 @@ _ui_group_removed(const char * const contact, const char * const group)
cons_show("%s removed from group %s", contact, group);
}
static void
_ui_handle_error_message(const char * const from, const char * const err_msg)
{
if (err_msg == NULL) {
cons_show_error("Unknown error received from service.");
} else {
ProfWin *current = wins_get_current();
gboolean handled = win_handle_error_message(current, from, err_msg);
if (handled != TRUE) {
cons_show_error("Error received from server: %s", err_msg);
}
}
ui_print_error_from_recipient(from, err_msg);
}
static void
_ui_handle_recipient_not_found(const char * const recipient, const char * const err_msg)
{
@ -390,6 +374,7 @@ _ui_handle_recipient_not_found(const char * const recipient, const char * const
static void
_ui_handle_recipient_error(const char * const recipient, const char * const err_msg)
{
cons_debug("RECIPIENT = %s", recipient);
ProfWin *win = wins_get_by_recipient(recipient);
GString *msg = g_string_new("");
g_string_printf(msg, "Error from %s: %s", recipient, err_msg);
@ -869,21 +854,6 @@ _ui_current_page_off(void)
win_refresh(current);
}
static void
_ui_print_error_from_recipient(const char * const from, const char *err_msg)
{
if (from == NULL || err_msg == NULL)
return;
ProfWin *window = wins_get_by_recipient(from);
if (window != NULL) {
win_vprint_line(window, '-', COLOUR_ERROR, "%s", err_msg);
if (wins_is_current(window)) {
wins_refresh_current();
}
}
}
static void
_ui_print_system_msg_from_recipient(const char * const from, const char *message)
{
@ -1727,7 +1697,6 @@ ui_init_module(void)
ui_contact_not_in_group = _ui_contact_not_in_group;
ui_group_added = _ui_group_added;
ui_group_removed = _ui_group_removed;
ui_handle_error_message = _ui_handle_error_message;
ui_disconnected = _ui_disconnected;
ui_handle_special_keys = _ui_handle_special_keys;
ui_close_connected_win = _ui_close_connected_win;
@ -1750,7 +1719,6 @@ ui_init_module(void)
ui_current_print_formatted_line = _ui_current_print_formatted_line;
ui_current_error_line = _ui_current_error_line;
ui_current_page_off = _ui_current_page_off;
ui_print_error_from_recipient = _ui_print_error_from_recipient;
ui_print_system_msg_from_recipient = _ui_print_system_msg_from_recipient;
ui_recipient_gone = _ui_recipient_gone;
ui_new_chat_win = _ui_new_chat_win;

View File

@ -68,9 +68,7 @@ void (*ui_untrust)(const char * const recipient);
unsigned long (*ui_get_idle_time)(void);
void (*ui_reset_idle_time)(void);
void (*ui_new_chat_win)(const char * const to);
void (*ui_print_error_from_recipient)(const char * const from, const char *err_msg);
void (*ui_print_system_msg_from_recipient)(const char * const from, const char *message);
void (*ui_handle_error_message)(const char * const from, const char * const err_msg);
gint (*ui_unread)(void);
void (*ui_close_connected_win)(int index);
int (*ui_close_all_wins)(void);

View File

@ -38,9 +38,6 @@
static void _win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
const char * const from, const char * const message);
static gboolean
_muc_handle_error_message(ProfWin *window, const char * const from,
const char * const err_msg);
ProfWin*
win_create(const char * const title, int cols, win_type_t type)
@ -314,44 +311,6 @@ win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
}
}
gboolean
win_handle_error_message(ProfWin *window, const char * const from,
const char * const err_msg)
{
gboolean handled = FALSE;
switch (window->type)
{
case WIN_CHAT:
case WIN_PRIVATE:
case WIN_DUCK:
case WIN_CONSOLE:
handled = FALSE;
break;
case WIN_MUC:
handled = _muc_handle_error_message(window, from, err_msg);
break;
default:
assert(FALSE);
break;
}
return handled;
}
static gboolean
_muc_handle_error_message(ProfWin *window, const char * const from,
const char * const err_msg)
{
gboolean handled = FALSE;
if (g_strcmp0(err_msg, "conflict") == 0) {
win_print_line(window, '-', 0, "Nickname already in use.");
win_refresh(window);
handled = TRUE;
}
return handled;
}
static void
_win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
const char * const from, const char * const message)

View File

@ -74,8 +74,5 @@ void win_show_status_string(ProfWin *window, const char * const from,
const char * const default_show);
void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
const char * const from, const char * const message);
gboolean
win_handle_error_message(ProfWin *window, const char * const from,
const char * const err_msg);
#endif

View File

@ -370,7 +370,7 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
g_string_free(log_msg, TRUE);
handle_presence_error(from, err_msg);
handle_presence_error(from, type, err_msg);
free(err_msg);