From 5610f70b35a018863a67c903f270b9e54ceb030d Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 19 Jan 2014 17:51:32 +0000 Subject: [PATCH] Inlined ui_contact_online and ui_contact_offline --- src/server_events.c | 68 ++++++++++++++++++++++++++++++++++++--------- src/ui/core.c | 56 ------------------------------------- src/ui/ui.h | 4 --- 3 files changed, 55 insertions(+), 73 deletions(-) diff --git a/src/server_events.c b/src/server_events.c index 9165f0f8..32cad211 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -21,6 +21,7 @@ */ #include +#include #include "chat_session.h" #include "log.h" @@ -28,6 +29,9 @@ #include "config/preferences.h" #include "roster_list.h" #include "ui/ui.h" + +#include "ui/windows.h" + #ifdef HAVE_LIBOTR #include "otr.h" #endif @@ -288,16 +292,35 @@ handle_subscription(const char *from, jabber_subscr_t type) } void -handle_contact_offline(char *contact, char *resource, char *status) +handle_contact_offline(char *barejid, char *resource, char *status) { - gboolean updated = roster_contact_offline(contact, resource, status); + gboolean updated = roster_contact_offline(barejid, resource, status); if (resource != NULL && updated && prefs_get_boolean(PREF_STATUSES)) { - Jid *jid = jid_create_from_bare_and_resource(contact, resource); - PContact result = roster_get_contact(contact); - if (p_contact_subscription(result) != NULL) { - if (strcmp(p_contact_subscription(result), "none") != 0) { - ui_contact_offline(jid->fulljid, "offline", status); + Jid *jid = jid_create_from_bare_and_resource(barejid, resource); + PContact contact = roster_get_contact(barejid); + if (p_contact_subscription(contact) != NULL) { + if (strcmp(p_contact_subscription(contact), "none") != 0) { + char *display_str = p_contact_create_display_string(contact, jid->resourcepart); + + ProfWin *console = wins_get_console(); + win_show_status_string(console, display_str, "offline", status, NULL, "--", + "offline"); + + ProfWin *window = wins_get_by_recipient(barejid); + if (window != NULL) { + win_show_status_string(window, display_str, "offline", status, NULL, "--", + "offline"); + } + + free(display_str); + + if (wins_is_current(console)) { + wins_refresh_current(); + } else if ((window != NULL) && (wins_is_current(window))) { + wins_refresh_current(); + } + ui_current_page_off(); } } @@ -306,17 +329,36 @@ handle_contact_offline(char *contact, char *resource, char *status) } void -handle_contact_online(char *contact, Resource *resource, +handle_contact_online(char *barejid, Resource *resource, GDateTime *last_activity) { - gboolean updated = roster_update_presence(contact, resource, last_activity); + gboolean updated = roster_update_presence(barejid, resource, last_activity); if (updated && prefs_get_boolean(PREF_STATUSES)) { - PContact result = roster_get_contact(contact); - if (p_contact_subscription(result) != NULL) { - if (strcmp(p_contact_subscription(result), "none") != 0) { + PContact contact = roster_get_contact(barejid); + if (p_contact_subscription(contact) != NULL) { + if (strcmp(p_contact_subscription(contact), "none") != 0) { const char *show = string_from_resource_presence(resource->presence); - ui_contact_online(contact, resource->name, show, resource->status, last_activity); + char *display_str = p_contact_create_display_string(contact, resource->name); + + ProfWin *console = wins_get_console(); + win_show_status_string(console, display_str, show, resource->status, last_activity, + "++", "online"); + + ProfWin *window = wins_get_by_recipient(barejid); + if (window != NULL) { + win_show_status_string(window, display_str, show, resource->status, + last_activity, "++", "online"); + } + + free(display_str); + + if (wins_is_current(console)) { + wins_refresh_current(); + } else if ((window != NULL) && (wins_is_current(window))) { + wins_refresh_current(); + } + ui_current_page_off(); } } diff --git a/src/ui/core.c b/src/ui/core.c index 10276c4b..9c5131d7 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -354,60 +354,6 @@ _ui_handle_error_message(const char * const from, const char * const err_msg) ui_print_error_from_recipient(from, err_msg); } -static void -_ui_contact_online(const char * const barejid, const char * const resource, - const char * const show, const char * const status, GDateTime *last_activity) -{ - PContact contact = roster_get_contact(barejid); - char *display_str = p_contact_create_display_string(contact, resource); - - ProfWin *console = wins_get_console(); - win_show_status_string(console, display_str, show, status, last_activity, - "++", "online"); - - ProfWin *window = wins_get_by_recipient(barejid); - if (window != NULL) { - win_show_status_string(window, display_str, show, status, - last_activity, "++", "online"); - } - - free(display_str); - - if (wins_is_current(console)) { - wins_refresh_current(); - } else if ((window != NULL) && (wins_is_current(window))) { - wins_refresh_current(); - } -} - -static void -_ui_contact_offline(const char * const from, const char * const show, - const char * const status) -{ - Jid *jidp = jid_create(from); - PContact contact = roster_get_contact(jidp->barejid); - char *display_str = p_contact_create_display_string(contact, jidp->resourcepart); - - ProfWin *console = wins_get_console(); - win_show_status_string(console, display_str, show, status, NULL, "--", - "offline"); - - ProfWin *window = wins_get_by_recipient(jidp->barejid); - if (window != NULL) { - win_show_status_string(window, display_str, show, status, NULL, "--", - "offline"); - } - - jid_destroy(jidp); - free(display_str); - - if (wins_is_current(console)) { - wins_refresh_current(); - } else if ((window != NULL) && (wins_is_current(window))) { - wins_refresh_current(); - } -} - static void _ui_disconnected(void) { @@ -1675,8 +1621,6 @@ ui_init_module(void) ui_group_added = _ui_group_added; ui_group_removed = _ui_group_removed; ui_handle_error_message = _ui_handle_error_message; - ui_contact_online = _ui_contact_online; - ui_contact_offline = _ui_contact_offline; ui_disconnected = _ui_disconnected; ui_handle_special_keys = _ui_handle_special_keys; ui_close_connected_win = _ui_close_connected_win; diff --git a/src/ui/ui.h b/src/ui/ui.h index a6d27b1b..a220952d 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -100,10 +100,6 @@ char * (*ui_ask_password)(void); void (*ui_contact_typing)(const char * const from); void (*ui_incoming_msg)(const char * const from, const char * const message, GTimeVal *tv_stamp, gboolean priv); -void (*ui_contact_online)(const char * const barejid, const char * const resource, - const char * const show, const char * const status, GDateTime *last_activity); -void (*ui_contact_offline)(const char * const from, const char * const show, - const char * const status); void (*ui_disconnected)(void); void (*ui_recipient_gone)(const char * const barejid); void (*ui_outgoing_msg)(const char * const from, const char * const to,