about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2018-02-09 20:47:41 +0000
committerJames Booth <boothj5@gmail.com>2018-02-09 20:47:41 +0000
commitd65fc24658c019601fc6f4365dde578a6b397e58 (patch)
treee2486b5241f5b355de69cd8522f87f5ba2da6fcd
parentbea815cc73989ab6b8b5fdcefb11306435b4c9f4 (diff)
downloadprofani-tty-d65fc24658c019601fc6f4365dde578a6b397e58.tar.gz
Fix muc nick autocomplete colon mid message
-rw-r--r--src/xmpp/muc.c70
1 files changed, 37 insertions, 33 deletions
diff --git a/src/xmpp/muc.c b/src/xmpp/muc.c
index 43e2bdbf..9f2f9f61 100644
--- a/src/xmpp/muc.c
+++ b/src/xmpp/muc.c
@@ -692,43 +692,47 @@ muc_roster_nick_change_complete(const char *const room, const char *const nick)
 char*
 muc_autocomplete(ProfWin *window, const char *const input, gboolean previous)
 {
-    if (window->type == WIN_MUC) {
-        ProfMucWin *mucwin = (ProfMucWin*)window;
-        assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
-        ChatRoom *chat_room = g_hash_table_lookup(rooms, mucwin->roomjid);
-
-        if (chat_room && chat_room->nick_ac) {
-            const char * search_str = NULL;
-
-            gchar *last_space = g_strrstr(input, " ");
-            if (!last_space) {
-                search_str = input;
-                if (!chat_room->autocomplete_prefix) {
-                    chat_room->autocomplete_prefix = strdup("");
-                }
-            } else {
-                search_str = last_space+1;
-                if (!chat_room->autocomplete_prefix) {
-                    chat_room->autocomplete_prefix = g_strndup(input, search_str - input);
-                }
-            }
+    if (window->type != WIN_MUC) {
+        return NULL;
+    }
 
-            char *result = autocomplete_complete(chat_room->nick_ac, search_str, FALSE, previous);
-            if (result) {
-                GString *replace_with = g_string_new(chat_room->autocomplete_prefix);
-                g_string_append(replace_with, result);
-                if (!last_space || (*(last_space+1) == '\0')) {
-                    g_string_append(replace_with, ": ");
-                }
-                g_free(result);
-                result = replace_with->str;
-                g_string_free(replace_with, FALSE);
-                return result;
-            }
+    ProfMucWin *mucwin = (ProfMucWin*)window;
+    assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
+    ChatRoom *chat_room = g_hash_table_lookup(rooms, mucwin->roomjid);
+    if (chat_room == NULL || chat_room->nick_ac == NULL) {
+        return NULL;
+    }
+
+    const char * search_str = NULL;
+
+    gchar *last_space = g_strrstr(input, " ");
+    if (!last_space) {
+        search_str = input;
+        if (!chat_room->autocomplete_prefix) {
+            chat_room->autocomplete_prefix = strdup("");
+        }
+    } else {
+        search_str = last_space+1;
+        if (!chat_room->autocomplete_prefix) {
+            chat_room->autocomplete_prefix = g_strndup(input, search_str - input);
         }
     }
 
-    return NULL;
+    char *result = autocomplete_complete(chat_room->nick_ac, search_str, FALSE, previous);
+    if (result == NULL) {
+        return NULL;
+    }
+
+    GString *replace_with = g_string_new(chat_room->autocomplete_prefix);
+    g_string_append(replace_with, result);
+
+    if (strlen(chat_room->autocomplete_prefix) == 0) {
+        g_string_append(replace_with, ": ");
+    }
+    g_free(result);
+    result = replace_with->str;
+    g_string_free(replace_with, FALSE);
+    return result;
 }
 
 void