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 []") + "/lastactivity set on|off", + "/lastactivity get []") CMD_DESC( "Enable/disable sending last activity, and send last activity requests.") CMD_ARGS( { "on|off", "Enable or disable sending of last activity." }, { "", "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], "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; } - if (g_strcmp0(args[0], "off") == 0) { - caps_remove_feature(XMPP_FEATURE_LASTACTIVITY); - } - 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