mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
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
This commit is contained in:
parent
7319f9eb1d
commit
a5ca65453e
@ -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;
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user