about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-07-22 13:13:30 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-07-22 13:13:30 +0200
commita5ca65453e04a2af2b01c1c0bfb65c9a5cc1563e (patch)
treed671213ae31a466f545f7728fbfe8c87156da379 /src
parent7319f9eb1dfd081f72e6fd146e432a5eb4e13f64 (diff)
downloadprofani-tty-a5ca65453e04a2af2b01c1c0bfb65c9a5cc1563e.tar.gz
Fix lastactivity behaviour
Autocomplete only completed on|off.

Now:

`/lastactivity get` -> get server uptime
`/lastactivity get <jid>` -> get user lastactivity
`/lastactivity set on` -> enable for self
`/lastactivity set off` -> disable for self

Fix https://github.com/profanity-im/profanity/issues/1411
Diffstat (limited to 'src')
-rw-r--r--src/command/cmd_ac.c33
-rw-r--r--src/command/cmd_defs.c16
-rw-r--r--src/command/cmd_funcs.c46
3 files changed, 68 insertions, 27 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 01211b16..cf148fc4 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -126,6 +126,7 @@ static char* _correct_autocomplete(ProfWin* window, const char* const input, gbo
 static char* _software_autocomplete(ProfWin* window, const char* const input, gboolean previous);
 static char* _url_autocomplete(ProfWin* window, const char* const input, gboolean previous);
 static char* _executable_autocomplete(ProfWin* window, const char* const input, gboolean previous);
+static char* _lastactivity_autocomplete(ProfWin* window, const char* const input, gboolean previous);
 
 static char* _script_autocomplete_func(const char* const prefix, gboolean previous, void* context);
 
@@ -1654,7 +1655,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ
 
     // autocomplete boolean settings
     gchar* boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash",
-                                 "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/lastactivity", "/os", "/slashguard" };
+                                 "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/os", "/slashguard" };
 
     for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) {
         result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice, previous, NULL);
@@ -1786,6 +1787,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ
     g_hash_table_insert(ac_funcs, "/software", _software_autocomplete);
     g_hash_table_insert(ac_funcs, "/url", _url_autocomplete);
     g_hash_table_insert(ac_funcs, "/executable", _executable_autocomplete);
+    g_hash_table_insert(ac_funcs, "/lastactivity", _lastactivity_autocomplete);
 
     int len = strlen(input);
     char parsed[len + 1];
@@ -4163,3 +4165,32 @@ _executable_autocomplete(ProfWin* window, const char* const input, gboolean prev
 
     return NULL;
 }
+
+static char*
+_lastactivity_autocomplete(ProfWin* window, const char* const input, gboolean previous)
+{
+    char* result = NULL;
+
+    result = autocomplete_param_with_ac(input, "/lastactivity", status_ac, TRUE, previous);
+    if (result) {
+        return result;
+    }
+
+    jabber_conn_status_t conn_status = connection_get_status();
+
+    if (conn_status == JABBER_CONNECTED) {
+
+        result = autocomplete_param_with_func(input, "/lastactivity set", prefs_autocomplete_boolean_choice, previous, NULL);
+        if (result) {
+            return result;
+        }
+
+        result = autocomplete_param_with_func(input, "/lastactivity get", roster_barejid_autocomplete, previous, NULL);
+        if (result) {
+            return result;
+        }
+
+    }
+
+    return NULL;
+}
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 456366c2..e0e60876 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -885,25 +885,25 @@ static struct cmd_t command_defs[] = {
     },
 
     { "/lastactivity",
-      parse_args, 0, 1, NULL,
+      parse_args, 1, 2, NULL,
       CMD_NOSUBFUNCS
       CMD_MAINFUNC(cmd_lastactivity)
       CMD_TAGS(
               CMD_TAG_PRESENCE)
       CMD_SYN(
-              "/lastactivity on|off",
-              "/lastactivity [<jid>]")
+              "/lastactivity set on|off",
+              "/lastactivity get [<jid>]")
       CMD_DESC(
               "Enable/disable sending last activity, and send last activity requests.")
       CMD_ARGS(
               { "on|off", "Enable or disable sending of last activity." },
               { "<jid>", "The JID of the entity to query. Omitting the JID will query your server for its uptime." })
       CMD_EXAMPLES(
-              "/lastactivity",
-              "/lastactivity off",
-              "/lastactivity freyja@asgaard.edda",
-              "/lastactivity freyja@asgaard.edda/laptop",
-              "/lastactivity someserver.com")
+              "/lastactivity get",
+              "/lastactivity set off",
+              "/lastactivity get freyja@asgaard.edda",
+              "/lastactivity get freyja@asgaard.edda/laptop",
+              "/lastactivity get someserver.com")
     },
 
     { "/nick",
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 96be6802..56a68297 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -4903,15 +4903,20 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
 gboolean
 cmd_lastactivity(ProfWin* window, const char* const command, gchar** args)
 {
-    if ((g_strcmp0(args[0], "on") == 0) || (g_strcmp0(args[0], "off") == 0)) {
-        _cmd_set_boolean_preference(args[0], command, "Last activity", PREF_LASTACTIVITY);
-        if (g_strcmp0(args[0], "on") == 0) {
-            caps_add_feature(XMPP_FEATURE_LASTACTIVITY);
-        }
-        if (g_strcmp0(args[0], "off") == 0) {
-            caps_remove_feature(XMPP_FEATURE_LASTACTIVITY);
+    if ((g_strcmp0(args[0], "set") == 0)) {
+        if ((g_strcmp0(args[1], "on") == 0) || (g_strcmp0(args[1], "off") == 0)) {
+            _cmd_set_boolean_preference(args[1], command, "Last activity", PREF_LASTACTIVITY);
+            if (g_strcmp0(args[1], "on") == 0) {
+                caps_add_feature(XMPP_FEATURE_LASTACTIVITY);
+            }
+            if (g_strcmp0(args[1], "off") == 0) {
+                caps_remove_feature(XMPP_FEATURE_LASTACTIVITY);
+            }
+            return TRUE;
+        } else {
+            cons_bad_cmd_usage(command);
+            return TRUE;
         }
-        return TRUE;
     }
 
     jabber_conn_status_t conn_status = connection_get_status();
@@ -4921,20 +4926,25 @@ cmd_lastactivity(ProfWin* window, const char* const command, gchar** args)
         return TRUE;
     }
 
-    if (args[0] == NULL) {
-        Jid* jidp = jid_create(connection_get_fulljid());
-        GString* jid = g_string_new(jidp->domainpart);
+    if ((g_strcmp0(args[0], "get") == 0)) {
+        if (args[1] == NULL) {
+            Jid* jidp = jid_create(connection_get_fulljid());
+            GString* jid = g_string_new(jidp->domainpart);
 
-        iq_last_activity_request(jid->str);
+            iq_last_activity_request(jid->str);
 
-        g_string_free(jid, TRUE);
-        jid_destroy(jidp);
+            g_string_free(jid, TRUE);
+            jid_destroy(jidp);
 
-        return TRUE;
-    } else {
-        iq_last_activity_request(args[0]);
-        return TRUE;
+            return TRUE;
+        } else {
+            iq_last_activity_request(args[1]);
+            return TRUE;
+        }
     }
+
+    cons_bad_cmd_usage(command);
+    return TRUE;
 }
 
 gboolean