From 44fc3f05069ec8981e953e3089af0d98026ac450 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 28 Jan 2021 15:11:50 +0100 Subject: [PATCH] Add /mam command Regards https://github.com/profanity-im/profanity/issues/660 --- src/command/cmd_ac.c | 6 +++--- src/command/cmd_defs.c | 15 +++++++++++++++ src/command/cmd_funcs.c | 8 ++++++++ src/command/cmd_funcs.h | 1 + src/ui/console.c | 10 ++++++++++ src/ui/ui.h | 1 + 6 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index f7414bad..65d73b33 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1165,12 +1165,12 @@ cmd_ac_remove_form_fields(DataForm* form) char* cmd_ac_complete(ProfWin* window, const char* const input, gboolean previous) { - char *found = NULL; + char* found = NULL; // autocomplete command if ((strncmp(input, "/", 1) == 0) && (!strchr(input, ' '))) { found = autocomplete_complete(commands_ac, input, TRUE, previous); - // autocomplete parameters + // autocomplete parameters } else { found = _cmd_ac_complete_params(window, input, previous); } @@ -1633,7 +1633,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", "/os", "/slashguard" }; + "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/os", "/slashguard", "/mam" }; for (int i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice, previous, NULL); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 94633f03..ce79cf7d 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2546,6 +2546,21 @@ static struct cmd_t command_defs[] = { "/url save https://profanity-im.github.io/guide/latest/userguide.html /home/user/Download/") }, + { "/mam", + parse_args, 1, 1, &cons_mam_setting, + CMD_NOSUBFUNCS + CMD_MAINFUNC(cmd_mam) + CMD_TAGS( + CMD_TAG_CHAT) + CMD_SYN( + "/os |") + CMD_DESC( + "Enable/Disable Message Archive Management (XEP-0313)") + CMD_ARGS( + { "on|off", "Enable or disable MAM" }) + CMD_NOEXAMPLES + }, + // NEXT-COMMAND (search helper) }; diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index c227b79d..d2cf2307 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9278,3 +9278,11 @@ cmd_executable_urlsave(ProfWin* window, const char* const command, gchar** args) return TRUE; } + +gboolean +cmd_mam(ProfWin* window, const char* const command, gchar** args) +{ + _cmd_set_boolean_preference(args[0], command, "Message Archive Management", PREF_MAM); + + return TRUE; +} diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 4955972c..bcd634da 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -240,5 +240,6 @@ gboolean cmd_url_save(ProfWin* window, const char* const command, gchar** args); gboolean cmd_executable_avatar(ProfWin* window, const char* const command, gchar** args); gboolean cmd_executable_urlopen(ProfWin* window, const char* const command, gchar** args); gboolean cmd_executable_urlsave(ProfWin* window, const char* const command, gchar** args); +gboolean cmd_mam(ProfWin* window, const char* const command, gchar** args); #endif diff --git a/src/ui/console.c b/src/ui/console.c index f701dc88..190adeea 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2082,6 +2082,16 @@ cons_slashguard_setting(void) } } +void +cons_mam_setting(void) +{ + if (prefs_get_boolean(PREF_MAM)) { + cons_show("Message Archive Management (XEP-0313) (/mam) : ON"); + } else { + cons_show("Message Archive Management (XEP-0313) (/mam) : OFF"); + } +} + void cons_show_connection_prefs(void) { diff --git a/src/ui/ui.h b/src/ui/ui.h index f26eaa10..8ce27840 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -321,6 +321,7 @@ void cons_os_setting(void); void cons_correction_setting(void); void cons_executable_setting(void); void cons_slashguard_setting(void); +void cons_mam_setting(void); void cons_show_contact_online(PContact contact, Resource* resource, GDateTime* last_activity); void cons_show_contact_offline(PContact contact, char* resource, char* status); void cons_theme_properties(void);