From 62c2febc11457baf00220f9c3951397dac7989d1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Oct 2015 23:05:20 +0000 Subject: [PATCH] Tidied ui_recipient_gone --- src/event/server_events.c | 16 ++++++++++++++- src/ui/chatwin.c | 40 +++++++++++------------------------- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 026b5147..2a66d6fe 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -346,7 +346,21 @@ sv_ev_inactive(char *barejid, char *resource) void sv_ev_gone(const char *const barejid, const char *const resource) { - ui_recipient_gone(barejid, resource); + if (barejid && resource) { + gboolean show_message = TRUE; + + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + ChatSession *session = chat_session_get(barejid); + if (session && g_strcmp0(session->resource, resource) != 0) { + show_message = FALSE; + } + if (show_message) { + ui_recipient_gone(chatwin); + } + } + } + if (wins_chat_exists(barejid)) { chat_session_recipient_gone(barejid, resource); } diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 7921e559..c4fe9507 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -191,37 +191,21 @@ ui_handle_otr_error(const char *const barejid, const char *const message) } void -ui_recipient_gone(const char *const barejid, const char *const resource) +ui_recipient_gone(ProfChatWin *chatwin) { - if (barejid == NULL) - return; - if (resource == NULL) - return; - - gboolean show_message = TRUE; - - ProfChatWin *chatwin = wins_get_chat(barejid); - if (chatwin) { - ChatSession *session = chat_session_get(barejid); - if (session && g_strcmp0(session->resource, resource) != 0) { - show_message = FALSE; - } - if (show_message) { - const char * display_usr = NULL; - PContact contact = roster_get_contact(barejid); - if (contact) { - if (p_contact_name(contact)) { - display_usr = p_contact_name(contact); - } else { - display_usr = barejid; - } - } else { - display_usr = barejid; - } - - win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); + const char *display_usr = NULL; + PContact contact = roster_get_contact(chatwin->barejid); + if (contact) { + if (p_contact_name(contact)) { + display_usr = p_contact_name(contact); + } else { + display_usr = chatwin->barejid; } + } else { + display_usr = chatwin->barejid; } + + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); } ProfChatWin* diff --git a/src/ui/ui.h b/src/ui/ui.h index 5e634438..81a600c3 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -104,7 +104,7 @@ void ui_incoming_private_msg(const char *const fulljid, const char *const messag void chatwin_receipt_received(ProfChatWin *chatwin, const char *const id); void ui_disconnected(void); -void ui_recipient_gone(const char *const barejid, const char *const resource); +void ui_recipient_gone(ProfChatWin *chatwin); void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode); void ui_outgoing_chat_msg_carbon(const char *const barejid, const char *const message); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 14911282..4967d8b6 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -179,7 +179,7 @@ void chatwin_receipt_received(ProfChatWin *chatwin, const char * const id) {} void ui_incoming_private_msg(const char * const fulljid, const char * const message, GDateTime *timestamp) {} void ui_disconnected(void) {} -void ui_recipient_gone(const char * const barejid, const char * const resource) {} +void ui_recipient_gone(ProfChatWin *chatwin) {} void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode) {} void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message) {}