about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-06-04 16:02:56 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-06-04 16:19:04 +0200
commitb210fb3603c4b52d478dd81810c6b4c38210bfd6 (patch)
tree2bd0abfe33281743d0f5b8d0c8f8186ad58d8d24
parent2d00444702661d7f5b989b2a7556aafeab4309fd (diff)
downloadprofani-tty-b210fb3603c4b52d478dd81810c6b4c38210bfd6.tar.gz
statusbar: check if roster exists
We destory the roster in ev_disconnect_cleanup().
Adding a function to test if the roster has been destroyed and testing
for it in the statusbar.

So now when the connection is lost 'Lost connection' is printed in all
open windows.
We can then reconnect with `/connect accountname`.

Should fix https://github.com/profanity-im/profanity/issues/1083
-rw-r--r--src/ui/statusbar.c6
-rw-r--r--src/xmpp/roster_list.c8
-rw-r--r--src/xmpp/roster_list.h1
3 files changed, 13 insertions, 2 deletions
diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c
index 4570be50..0e24ab3f 100644
--- a/src/ui/statusbar.c
+++ b/src/ui/statusbar.c
@@ -187,7 +187,10 @@ _create_tab(const int win, win_type_t wintype, char *identifier, gboolean highli
     tab->display_name = NULL;
 
     if (tab->window_type == WIN_CHAT) {
-        PContact contact = roster_get_contact(tab->identifier);
+        PContact contact = NULL;
+        if (roster_exists()) {
+            contact = roster_get_contact(tab->identifier);
+        }
         if (contact && p_contact_name(contact)) {
             tab->display_name = strdup(p_contact_name(contact));
         } else {
@@ -601,5 +604,4 @@ _display_name(StatusBarTab *tab)
     g_free(trimmed);
 
     return trimmedname;
-
 }
diff --git a/src/xmpp/roster_list.c b/src/xmpp/roster_list.c
index 81a51581..7954e3de 100644
--- a/src/xmpp/roster_list.c
+++ b/src/xmpp/roster_list.c
@@ -707,3 +707,11 @@ roster_process_pending_presence(void)
     g_slist_free(roster_pending_presence);
     roster_pending_presence = NULL;
 }
+
+gboolean
+roster_exists(void) {
+    if (roster != NULL) {
+        return TRUE;
+    }
+    return FALSE;
+}
diff --git a/src/xmpp/roster_list.h b/src/xmpp/roster_list.h
index 57a932be..93f1253e 100644
--- a/src/xmpp/roster_list.h
+++ b/src/xmpp/roster_list.h
@@ -73,5 +73,6 @@ char* roster_get_msg_display_name(const char *const barejid, const char *const r
 gint roster_compare_name(PContact a, PContact b);
 gint roster_compare_presence(PContact a, PContact b);
 void roster_process_pending_presence(void);
+gboolean roster_exists(void);
 
 #endif