about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-10-27 23:39:26 +0000
committerJames Booth <boothj5@gmail.com>2015-10-27 23:39:26 +0000
commit3f7f1186a64ea8ed39e6b72b1bbe3dd0037a5617 (patch)
treea1de7dcd82e4826eaecd611f7489899af961733d
parent77e854c1e8c940a8dd939adab6ab00e909b9f133 (diff)
downloadprofani-tty-3f7f1186a64ea8ed39e6b72b1bbe3dd0037a5617.tar.gz
Tidied remaining chatwin functions
-rw-r--r--src/ui/chatwin.c25
-rw-r--r--src/ui/core.c20
-rw-r--r--src/ui/ui.h4
-rw-r--r--tests/unittests/ui/stub_ui.c4
4 files changed, 30 insertions, 23 deletions
diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c
index 591635bb..0e78fc24 100644
--- a/src/ui/chatwin.c
+++ b/src/ui/chatwin.c
@@ -304,33 +304,28 @@ chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message)
 }
 
 void
-ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity)
+chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity)
 {
+    assert(chatwin != NULL);
+
     const char *show = string_from_resource_presence(resource->presence);
+    PContact contact = roster_get_contact(chatwin->barejid);
     char *display_str = p_contact_create_display_string(contact, resource->name);
-    const char *barejid = p_contact_barejid(contact);
 
-    ProfWin *window = (ProfWin*)wins_get_chat(barejid);
-    if (window) {
-        win_show_status_string(window, display_str, show, resource->status,
-            last_activity, "++", "online");
-
-    }
+    win_show_status_string((ProfWin*)chatwin, display_str, show, resource->status, last_activity, "++", "online");
 
     free(display_str);
 }
 
 void
-ui_chat_win_contact_offline(PContact contact, char *resource, char *status)
+chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status)
 {
+    assert(chatwin != NULL);
+
+    PContact contact = roster_get_contact(chatwin->barejid);
     char *display_str = p_contact_create_display_string(contact, resource);
-    const char *barejid = p_contact_barejid(contact);
 
-    ProfWin *window = (ProfWin*)wins_get_chat(barejid);
-    if (window) {
-        win_show_status_string(window, display_str, "offline", status, NULL, "--",
-            "offline");
-    }
+    win_show_status_string((ProfWin*)chatwin, display_str, "offline", status, NULL, "--", "offline");
 
     free(display_str);
 }
diff --git a/src/ui/core.c b/src/ui/core.c
index d8c9aa4e..eb36ba22 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -323,11 +323,17 @@ ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity)
 
     // show in chat win if "all"
     if (g_strcmp0(show_chat_win, "all") == 0) {
-        ui_chat_win_contact_online(contact, resource, last_activity);
+        ProfChatWin *chatwin = wins_get_chat(barejid);
+        if (chatwin) {
+            chatwin_contact_online(chatwin, resource, last_activity);
+        }
 
     // show in char win if "online" and presence online
     } else if (g_strcmp0(show_chat_win, "online") == 0 && resource->presence == RESOURCE_ONLINE) {
-        ui_chat_win_contact_online(contact, resource, last_activity);
+        ProfChatWin *chatwin = wins_get_chat(barejid);
+        if (chatwin) {
+            chatwin_contact_online(chatwin, resource, last_activity);
+        }
     }
 
     free(show_console);
@@ -1790,11 +1796,17 @@ ui_contact_offline(char *barejid, char *resource, char *status)
 
             // show in chat win if "all"
             if (g_strcmp0(show_chat_win, "all") == 0) {
-                ui_chat_win_contact_offline(contact, resource, status);
+                ProfChatWin *chatwin = wins_get_chat(barejid);
+                if (chatwin) {
+                    chatwin_contact_offline(chatwin, resource, status);
+                }
 
             // show in char win if "online" and presence online
             } else if (g_strcmp0(show_chat_win, "online") == 0) {
-                ui_chat_win_contact_offline(contact, resource, status);
+                ProfChatWin *chatwin = wins_get_chat(barejid);
+                if (chatwin) {
+                    chatwin_contact_offline(chatwin, resource, status);
+                }
             }
         }
     }
diff --git a/src/ui/ui.h b/src/ui/ui.h
index fa8e45f1..100ca10a 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -168,8 +168,8 @@ void ui_contact_already_in_group(const char *const contact, const char *const gr
 void ui_contact_not_in_group(const char *const contact, const char *const group);
 void ui_group_added(const char *const contact, const char *const group);
 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_offline(PContact contact, char *resource, char *status);
+void chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity);
+void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status);
 void ui_contact_offline(char *barejid, char *resource, char *status);
 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);
diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c
index 83d59135..5e0ac484 100644
--- a/tests/unittests/ui/stub_ui.c
+++ b/tests/unittests/ui/stub_ui.c
@@ -243,8 +243,8 @@ void ui_contact_already_in_group(const char * const contact, const char * const
 void ui_contact_not_in_group(const char * const contact, const char * const group) {}
 void ui_group_added(const char * const contact, const char * const group) {}
 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_offline(PContact contact, char *resource, char *status) {}
+void chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity) {}
+void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status) {}
 
 void ui_contact_offline(char *barejid, char *resource, char *status) {}