about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-06-04 11:16:24 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-06-04 12:33:57 +0200
commitea62c3f29366f0f7b4b47bf0e52ee34882c33897 (patch)
treefee3efffc7c12ab5e23fd449241b889108af6fb6 /src/ui
parent48013f8d4368a81596cff42b5697a6f49a29865e (diff)
downloadprofani-tty-ea62c3f29366f0f7b4b47bf0e52ee34882c33897.tar.gz
Determine chat window names beforehand
Save the name for displaying the windows in the statusbar inside the tab
object.
So far we calculated them repeatedly and this created issues when we
lost the connection.

Regards https://github.com/profanity-im/profanity/issues/1083
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/statusbar.c57
1 files changed, 44 insertions, 13 deletions
diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c
index d0ce7309..46320a04 100644
--- a/src/ui/statusbar.c
+++ b/src/ui/statusbar.c
@@ -57,6 +57,7 @@ typedef struct _status_bar_tab_t {
     win_type_t window_type;
     char *identifier;
     gboolean highlight;
+    char *display_name;
 } StatusBarTab;
 
 typedef struct _status_bar_t {
@@ -94,6 +95,7 @@ status_bar_init(void)
     StatusBarTab *console = malloc(sizeof(StatusBarTab));
     console->window_type = WIN_CONSOLE;
     console->identifier = strdup("console");
+    console->display_name = NULL;
     g_hash_table_insert(statusbar->tabs, GINT_TO_POINTER(1), console);
     statusbar->current_tab = 1;
 
@@ -182,6 +184,24 @@ status_bar_active(const int win, win_type_t wintype, char *identifier)
     tab->identifier = strdup(identifier);
     tab->highlight = FALSE;
     tab->window_type = wintype;
+    tab->display_name = NULL;
+
+    if (tab->window_type == WIN_CHAT) {
+        PContact contact = roster_get_contact(tab->identifier);
+        if (contact && p_contact_name(contact)) {
+            tab->display_name = strdup(p_contact_name(contact));
+        } else {
+            char *pref = prefs_get_string(PREF_STATUSBAR_CHAT);
+            if (g_strcmp0("user", pref) == 0) {
+                Jid *jidp = jid_create(tab->identifier);
+                tab->display_name = strdup(jidp->localpart);
+                jid_destroy(jidp);
+            } else {
+                tab->display_name = strdup(tab->identifier);
+            }
+        }
+    }
+
     g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab);
 
     status_bar_draw();
@@ -199,6 +219,24 @@ status_bar_new(const int win, win_type_t wintype, char* identifier)
     tab->identifier = strdup(identifier);
     tab->highlight = TRUE;
     tab->window_type = wintype;
+    tab->display_name = NULL;
+
+    if (tab->window_type == WIN_CHAT) {
+        PContact contact = roster_get_contact(tab->identifier);
+        if (contact && p_contact_name(contact)) {
+            tab->display_name = strdup(p_contact_name(contact));
+        } else {
+            char *pref = prefs_get_string(PREF_STATUSBAR_CHAT);
+            if (g_strcmp0("user", pref) == 0) {
+                Jid *jidp = jid_create(tab->identifier);
+                tab->display_name = strdup(jidp->localpart);
+                jid_destroy(jidp);
+            } else {
+                tab->display_name = strdup(tab->identifier);
+            }
+        }
+    }
+
     g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab);
 
     status_bar_draw();
@@ -461,8 +499,12 @@ _destroy_tab(StatusBarTab *tab)
         if (tab->identifier) {
             free(tab->identifier);
         }
+        if (tab->display_name) {
+            free(tab->display_name);
+        }
         free(tab);
     }
+    tab = NULL;
 }
 
 static int
@@ -520,19 +562,8 @@ _display_name(StatusBarTab *tab)
     } else if (tab->window_type == WIN_PLUGIN) {
         fullname = strdup(tab->identifier);
     } else if (tab->window_type == WIN_CHAT) {
-        PContact contact = roster_get_contact(tab->identifier);
-        if (contact && p_contact_name(contact)) {
-            fullname = strdup(p_contact_name(contact));
-        } else {
-            char *pref = prefs_get_string(PREF_STATUSBAR_CHAT);
-            if (g_strcmp0("user", pref) == 0) {
-                Jid *jidp = jid_create(tab->identifier);
-                char *user = strdup(jidp->localpart);
-                jid_destroy(jidp);
-                fullname = user;
-            } else {
-                fullname = strdup(tab->identifier);
-            }
+        if (tab && tab->display_name) {
+            fullname = strdup(tab->display_name);
         }
     } else if (tab->window_type == WIN_MUC) {
         char *pref = prefs_get_string(PREF_STATUSBAR_ROOM);