about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-10-27 23:05:20 +0000
committerJames Booth <boothj5@gmail.com>2015-10-27 23:05:20 +0000
commit62c2febc11457baf00220f9c3951397dac7989d1 (patch)
treea54f1b0bddca2bff6e64d0321e8114c40d9ba9c8
parentf4fbf0ecf0686f3da83d08b46a4887e1f8180205 (diff)
downloadprofani-tty-62c2febc11457baf00220f9c3951397dac7989d1.tar.gz
Tidied ui_recipient_gone
-rw-r--r--src/event/server_events.c16
-rw-r--r--src/ui/chatwin.c40
-rw-r--r--src/ui/ui.h2
-rw-r--r--tests/unittests/ui/stub_ui.c2
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) {}