about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-07-09 00:35:43 +0100
committerJames Booth <boothj5@gmail.com>2014-07-09 00:36:09 +0100
commit4b14c0c484a878e1afa34bcbb3930230baa4c33d (patch)
treead8058688ac5bc60b08c354b1759097327aedb45
parent06caa0c4f13d04736d28db8197f24dcd66db141c (diff)
downloadprofani-tty-4b14c0c484a878e1afa34bcbb3930230baa4c33d.tar.gz
Added autocomplete for nicknames in MUC input text
issue #321
-rw-r--r--src/muc.c27
-rw-r--r--src/muc.h2
-rw-r--r--src/ui/inputwin.c8
3 files changed, 36 insertions, 1 deletions
diff --git a/src/muc.c b/src/muc.c
index 64ca9bca..4e943b9c 100644
--- a/src/muc.c
+++ b/src/muc.c
@@ -29,6 +29,7 @@
 #include "common.h"
 #include "jid.h"
 #include "tools/autocomplete.h"
+#include "ui/ui.h"
 
 typedef struct _muc_room_t {
     char *room; // e.g. test@conference.server
@@ -567,6 +568,32 @@ muc_complete_roster_nick_change(const char * const room,
     return NULL;
 }
 
+void
+muc_autocomplete(char *input, int *size)
+{
+    char *recipient = ui_current_recipient();
+    Autocomplete nick_ac = muc_get_roster_ac(recipient);
+    if (nick_ac != NULL) {
+        input[*size] = '\0';
+        gchar *last_space = g_strrstr(input, " ");
+        char *result = NULL;
+        if (last_space == NULL) {
+            result = autocomplete_complete(nick_ac, input);
+        } else {
+            int len = (last_space - input);
+            cons_debug("SIZE: %d", len);
+            char *start_str = strndup(input, len);
+            result = autocomplete_param_with_ac(input, size, start_str, nick_ac);
+            free(start_str);
+        }
+        if (result != NULL) {
+            ui_replace_input(input, result, size);
+            g_free(result);
+            return;
+        }
+    }
+}
+
 static void
 _free_room(ChatRoom *room)
 {
diff --git a/src/muc.h b/src/muc.h
index 88b87191..cd822f67 100644
--- a/src/muc.h
+++ b/src/muc.h
@@ -76,4 +76,6 @@ char * muc_get_subject(const char * const room);
 void muc_add_pending_broadcast(const char * const room, const char * const message);
 GList * muc_get_pending_broadcasts(const char * const room);
 
+void muc_autocomplete(char *input, int *size);
+
 #endif
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 8ac01b45..f90c59a2 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -39,6 +39,7 @@
 #include "config/preferences.h"
 #include "config/theme.h"
 #include "log.h"
+#include "muc.h"
 #include "profanity.h"
 #include "roster_list.h"
 #include "ui/ui.h"
@@ -511,7 +512,12 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
             return 1;
 
         case 9: // tab
-            cmd_autocomplete(input, size);
+            if ((strncmp(input, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) {
+                cons_debug("MUC AC");
+                muc_autocomplete(input, size);
+            } else {
+                cmd_autocomplete(input, size);
+            }
             return 1;
 
         default: