about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server_events.c47
-rw-r--r--src/ui/console.c36
-rw-r--r--src/ui/core.c43
-rw-r--r--src/ui/ui.h4
4 files changed, 87 insertions, 43 deletions
diff --git a/src/server_events.c b/src/server_events.c
index 32cad211..d8943885 100644
--- a/src/server_events.c
+++ b/src/server_events.c
@@ -301,27 +301,8 @@ handle_contact_offline(char *barejid, char *resource, char *status)
         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();
+                cons_show_contact_offline(contact, resource, status);
+                ui_chat_win_contact_offline(contact, resource, status);
             }
         }
         jid_destroy(jid);
@@ -338,28 +319,8 @@ handle_contact_online(char *barejid, Resource *resource,
         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);
-                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();
+                cons_show_contact_online(contact, resource, last_activity);
+                ui_chat_win_contact_online(contact, resource, last_activity);
             }
         }
     }
diff --git a/src/ui/console.c b/src/ui/console.c
index d1c1e52b..502ce342 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -1370,6 +1370,40 @@ _cons_show_roster(GSList *list)
 }
 
 static void
+_cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity)
+{
+    const char *show = string_from_resource_presence(resource->presence);
+    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");
+
+    free(display_str);
+
+    if (wins_is_current(console)) {
+        ui_current_page_off();
+    }
+    wins_refresh_console();
+}
+
+static void
+_cons_show_contact_offline(PContact contact, char *resource, char *status)
+{
+    char *display_str = p_contact_create_display_string(contact, resource);
+
+    ProfWin *console = wins_get_console();
+    win_show_status_string(console, display_str, "offline", status, NULL, "--",
+        "offline");
+    free(display_str);
+
+    if (wins_is_current(console)) {
+        ui_current_page_off();
+    }
+    wins_refresh_console();
+}
+
+static void
 _cons_show_contacts(GSList *list)
 {
     ProfWin *console = wins_get_console();
@@ -1594,4 +1628,6 @@ console_init_module(void)
     cons_show_roster = _cons_show_roster;
     cons_show_contacts = _cons_show_contacts;
     cons_alert = _cons_alert;
+    cons_show_contact_online = _cons_show_contact_online;
+    cons_show_contact_offline = _cons_show_contact_offline;
 }
diff --git a/src/ui/core.c b/src/ui/core.c
index 9c5131d7..43b22f83 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -1405,6 +1405,47 @@ _ui_ask_password(void)
 }
 
 static void
+_ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity)
+{
+    const char *show = string_from_resource_presence(resource->presence);
+    char *display_str = p_contact_create_display_string(contact, resource->name);
+    const char *barejid = p_contact_barejid(contact);
+
+    ProfWin *window = wins_get_by_recipient(barejid);
+    if (window != NULL) {
+        win_show_status_string(window, display_str, show, resource->status,
+            last_activity, "++", "online");
+
+        if (wins_is_current(window)) {
+            wins_refresh_current();
+            ui_current_page_off();
+        }
+    }
+
+    free(display_str);
+}
+
+static void
+_ui_chat_win_contact_offline(PContact contact, char *resource, char *status)
+{
+    char *display_str = p_contact_create_display_string(contact, resource);
+    const char *barejid = p_contact_barejid(contact);
+
+    ProfWin *window = wins_get_by_recipient(barejid);
+    if (window != NULL) {
+        win_show_status_string(window, display_str, "offline", status, NULL, "--",
+            "offline");
+
+        if (wins_is_current(window)) {
+            wins_refresh_current();
+            ui_current_page_off();
+        }
+    }
+
+    free(display_str);
+}
+
+static void
 _ui_draw_win_title(void)
 {
     char new_win_title[100];
@@ -1675,4 +1716,6 @@ ui_init_module(void)
     ui_gone_insecure = _ui_gone_insecure;
     ui_trust = _ui_trust;
     ui_untrust = _ui_untrust;
+    ui_chat_win_contact_online = _ui_chat_win_contact_online;
+    ui_chat_win_contact_offline = _ui_chat_win_contact_offline;
 }
diff --git a/src/ui/ui.h b/src/ui/ui.h
index a220952d..df59e477 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -128,6 +128,8 @@ void (*ui_contact_already_in_group)(const char * const contact, const char * con
 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);
 
 // contact status functions
 void (*ui_status_room)(const char * const contact);
@@ -224,6 +226,8 @@ void (*cons_reconnect_setting)(void);
 void (*cons_autoping_setting)(void);
 void (*cons_priority_setting)(void);
 void (*cons_autoconnect_setting)(void);
+void (*cons_show_contact_online)(PContact contact, Resource *resource, GDateTime *last_activity);
+void (*cons_show_contact_offline)(PContact contact, char *resource, char *status);
 
 // status bar actions
 void (*status_bar_refresh)(void);