about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-05-07 22:05:36 +0100
committerJames Booth <boothj5@gmail.com>2015-05-07 22:05:36 +0100
commita2c62117322eea58c17231c27c5ee3b41900ea81 (patch)
tree0f0278419d0eb8d02c70fc6ca535124fecf186c3
parent6fd9b179a08126deb20d6efedac3089e9bf432cb (diff)
downloadprofani-tty-a2c62117322eea58c17231c27c5ee3b41900ea81.tar.gz
Added ui_contact_online
-rw-r--r--src/event/server_events.c34
-rw-r--r--src/ui/core.c36
-rw-r--r--src/ui/ui.h1
-rw-r--r--tests/test_server_events.c72
-rw-r--r--tests/testsuite.c9
-rw-r--r--tests/ui/stub_ui.c7
6 files changed, 64 insertions, 95 deletions
diff --git a/src/event/server_events.c b/src/event/server_events.c
index e409e06a..e2e910a3 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -280,42 +280,12 @@ sv_ev_contact_offline(char *barejid, char *resource, char *status)
 }
 
 void
-sv_ev_contact_online(char *barejid, Resource *resource,
-    GDateTime *last_activity)
+sv_ev_contact_online(char *barejid, Resource *resource, GDateTime *last_activity)
 {
     gboolean updated = roster_update_presence(barejid, resource, last_activity);
 
     if (updated) {
-        char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE);
-        char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT);
-        PContact contact = roster_get_contact(barejid);
-        if (p_contact_subscription(contact)) {
-            if (strcmp(p_contact_subscription(contact), "none") != 0) {
-
-                // show in console if "all"
-                if (g_strcmp0(show_console, "all") == 0) {
-                    cons_show_contact_online(contact, resource, last_activity);
-
-                // show in console of "online" and presence online
-                } else if (g_strcmp0(show_console, "online") == 0 &&
-                        resource->presence == RESOURCE_ONLINE) {
-                    cons_show_contact_online(contact, resource, 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);
-
-                // 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);
-                }
-            }
-        }
-        prefs_free_string(show_console);
-        prefs_free_string(show_chat_win);
+        ui_contact_online(barejid, resource, last_activity);
     }
 
     rosterwin_roster();
diff --git a/src/ui/core.c b/src/ui/core.c
index 06dd84e3..cb295244 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -320,6 +320,42 @@ ui_chat_win_exists(const char * const barejid)
 }
 
 void
+ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity)
+{
+    char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE);
+    char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT);
+    PContact contact = roster_get_contact(barejid);
+
+    // show nothing
+    if (g_strcmp0(p_contact_subscription(contact), "none") == 0) {
+        free(show_console);
+        free(show_chat_win);
+        return;
+    }
+
+    // show in console if "all"
+    if (g_strcmp0(show_console, "all") == 0) {
+        cons_show_contact_online(contact, resource, last_activity);
+
+    // show in console of "online" and presence online
+    } else if (g_strcmp0(show_console, "online") == 0 && resource->presence == RESOURCE_ONLINE) {
+        cons_show_contact_online(contact, resource, 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);
+
+    // 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);
+    }
+
+    free(show_console);
+    free(show_chat_win);
+}
+
+void
 ui_contact_typing(const char * const barejid, const char * const resource)
 {
     ProfChatWin *chatwin = wins_get_chat(barejid);
diff --git a/src/ui/ui.h b/src/ui/ui.h
index c98d45e8..48b8d393 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -112,6 +112,7 @@ char * ui_ask_password(void);
 void ui_handle_stanza(const char * const msg);
 
 // ui events
+void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity);
 void ui_contact_typing(const char * const barejid, const char * const resource);
 void ui_incoming_msg(const char * const from, const char * const resource,  const char * const message, GTimeVal *tv_stamp);
 void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp);
diff --git a/tests/test_server_events.c b/tests/test_server_events.c
index d87dc217..58489807 100644
--- a/tests/test_server_events.c
+++ b/tests/test_server_events.c
@@ -14,31 +14,19 @@
 #include "ui/stub_ui.h"
 #include "muc.h"
 
-void console_doesnt_show_online_presence_when_set_none(void **state)
-{
-    prefs_set_string(PREF_STATUSES_CONSOLE, "none");
-    roster_init();
-    roster_add("test1@server", "bob", NULL, "both", FALSE);
-    Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10);
-
-    sv_ev_contact_online("test1@server", resource, NULL);
-
-    roster_clear();
-}
-
 void console_shows_online_presence_when_set_online(void **state)
 {
     prefs_set_string(PREF_STATUSES_CONSOLE, "online");
     roster_init();
-    roster_add("test1@server", "bob", NULL, "both", FALSE);
+    char *barejid = "test1@server";
+    roster_add(barejid, "bob", NULL, "both", FALSE);
     Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10);
-    PContact contact = roster_get_contact("test1@server");
 
-    expect_memory(cons_show_contact_online, contact, contact, sizeof(contact));
-    expect_memory(cons_show_contact_online, resource, resource, sizeof(resource));
-    expect_value(cons_show_contact_online, last_activity, NULL);
+    expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid));
+    expect_memory(ui_contact_online, resource, resource, sizeof(resource));
+    expect_value(ui_contact_online, last_activity, NULL);
 
-    sv_ev_contact_online("test1@server", resource, NULL);
+    sv_ev_contact_online(barejid, resource, NULL);
 
     roster_clear();
 }
@@ -47,39 +35,15 @@ void console_shows_online_presence_when_set_all(void **state)
 {
     prefs_set_string(PREF_STATUSES_CONSOLE, "all");
     roster_init();
-    roster_add("test1@server", "bob", NULL, "both", FALSE);
+    char *barejid = "test1@server";
+    roster_add(barejid, "bob", NULL, "both", FALSE);
     Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10);
-    PContact contact = roster_get_contact("test1@server");
-
-    expect_memory(cons_show_contact_online, contact, contact, sizeof(contact));
-    expect_memory(cons_show_contact_online, resource, resource, sizeof(resource));
-    expect_value(cons_show_contact_online, last_activity, NULL);
-
-    sv_ev_contact_online("test1@server", resource, NULL);
-
-    roster_clear();
-}
 
-void console_doesnt_show_dnd_presence_when_set_none(void **state)
-{
-    prefs_set_string(PREF_STATUSES_CONSOLE, "none");
-    roster_init();
-    roster_add("test1@server", "bob", NULL, "both", FALSE);
-    Resource *resource = resource_new("resource", RESOURCE_DND, NULL, 10);
+    expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid));
+    expect_memory(ui_contact_online, resource, resource, sizeof(resource));
+    expect_value(ui_contact_online, last_activity, NULL);
 
-    sv_ev_contact_online("test1@server", resource, NULL);
-
-    roster_clear();
-}
-
-void console_doesnt_show_dnd_presence_when_set_online(void **state)
-{
-    prefs_set_string(PREF_STATUSES_CONSOLE, "online");
-    roster_init();
-    roster_add("test1@server", "bob", NULL, "both", FALSE);
-    Resource *resource = resource_new("resource", RESOURCE_DND, NULL, 10);
-
-    sv_ev_contact_online("test1@server", resource, NULL);
+    sv_ev_contact_online(barejid, resource, NULL);
 
     roster_clear();
 }
@@ -88,15 +52,15 @@ void console_shows_dnd_presence_when_set_all(void **state)
 {
     prefs_set_string(PREF_STATUSES_CONSOLE, "all");
     roster_init();
-    roster_add("test1@server", "bob", NULL, "both", FALSE);
+    char *barejid = "test1@server";
+    roster_add(barejid, "bob", NULL, "both", FALSE);
     Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10);
-    PContact contact = roster_get_contact("test1@server");
 
-    expect_memory(cons_show_contact_online, contact, contact, sizeof(contact));
-    expect_memory(cons_show_contact_online, resource, resource, sizeof(resource));
-    expect_value(cons_show_contact_online, last_activity, NULL);
+    expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid));
+    expect_memory(ui_contact_online, resource, resource, sizeof(resource));
+    expect_value(ui_contact_online, last_activity, NULL);
 
-    sv_ev_contact_online("test1@server", resource, NULL);
+    sv_ev_contact_online(barejid, resource, NULL);
 
     roster_clear();
 }
diff --git a/tests/testsuite.c b/tests/testsuite.c
index 91fd54e3..3f860178 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -425,21 +425,12 @@ int main(int argc, char* argv[]) {
             load_preferences,
             close_preferences),
 
-        unit_test_setup_teardown(console_doesnt_show_online_presence_when_set_none,
-            load_preferences,
-            close_preferences),
         unit_test_setup_teardown(console_shows_online_presence_when_set_online,
             load_preferences,
             close_preferences),
         unit_test_setup_teardown(console_shows_online_presence_when_set_all,
             load_preferences,
             close_preferences),
-        unit_test_setup_teardown(console_doesnt_show_dnd_presence_when_set_none,
-            load_preferences,
-            close_preferences),
-        unit_test_setup_teardown(console_doesnt_show_dnd_presence_when_set_online,
-            load_preferences,
-            close_preferences),
         unit_test_setup_teardown(console_shows_dnd_presence_when_set_all,
             load_preferences,
             close_preferences),
diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c
index c23723e1..f3c5831f 100644
--- a/tests/ui/stub_ui.c
+++ b/tests/ui/stub_ui.c
@@ -185,6 +185,13 @@ char * ui_ask_password(void)
 void ui_handle_stanza(const char * const msg) {}
 
 // ui events
+void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity)
+{
+    check_expected(barejid);
+    check_expected(resource);
+    check_expected(last_activity);
+}
+
 void ui_contact_typing(const char * const barejid, const char * const resource) {}
 void ui_incoming_msg(const char * const from, const char * const resource, const char * const message, GTimeVal *tv_stamp) {}
 void ui_message_receipt(const char * const barejid, const char * const id) {}