From 039bf5d04de6d388379d5cca300f00b1022d068e Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 10 Feb 2020 13:35:46 +0100 Subject: xep-0308: add `correction` autocompletion --- src/command/cmd_defs.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/command/cmd_defs.c') diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index b583a06b..30e11990 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2361,6 +2361,24 @@ static struct cmd_t command_defs[] = { "on|off", ""}) CMD_NOEXAMPLES }, + + { "/correction", + parse_args, 1, 1, &cons_correction_setting, + CMD_NOSUBFUNCS + CMD_MAINFUNC(cmd_os) + CMD_TAGS( + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/correction |", + "/correction char ") + CMD_DESC( + "Settings regarding Last Message Correction (XEP-0308).") + CMD_ARGS( + { "on|off", "Enable/Disable support for last message correction."}, + { "char", "Set character that will prefix corrected messages. Default: +"}) + CMD_NOEXAMPLES + }, }; static GHashTable *search_index; -- cgit 1.4.1-2-gfad0 From c2d70a071fb107a98f9b057eab4e5021f0eb7187 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 10 Feb 2020 13:48:31 +0100 Subject: xep-0308: set correction char in config --- src/command/cmd_defs.c | 2 +- src/command/cmd_funcs.c | 27 +++++++++++++++++++++++++++ src/command/cmd_funcs.h | 1 + src/config/preferences.c | 26 ++++++++++++++++++++++++++ src/config/preferences.h | 3 +++ 5 files changed, 58 insertions(+), 1 deletion(-) (limited to 'src/command/cmd_defs.c') diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 30e11990..1563bf73 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2365,7 +2365,7 @@ static struct cmd_t command_defs[] = { "/correction", parse_args, 1, 1, &cons_correction_setting, CMD_NOSUBFUNCS - CMD_MAINFUNC(cmd_os) + CMD_MAINFUNC(cmd_correction) CMD_TAGS( CMD_TAG_CHAT, CMD_TAG_GROUPCHAT) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 930004b3..1870429d 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8651,3 +8651,30 @@ cmd_os(ProfWin *window, const char *const command, gchar **args) return TRUE; } + +gboolean +cmd_correction(ProfWin *window, const char *const command, gchar **args) +{ + // enable/disable + if (g_strcmp0(args[0], "on") == 0) { + prefs_set_boolean(PREF_BOOKMARK_INVITE, TRUE); + return TRUE; + } else if (g_strcmp0(args[0], "off") == 0) { + prefs_set_boolean(PREF_BOOKMARK_INVITE, FALSE); + return TRUE; + } + + // char + if (g_strcmp(args[0], "char") == 0) { + if (args[1] == NULL) { + cons_bad_cmd_usage(command); + } else if (strlen(args[1]) != 1) { + cons_bad_cmd_usage(command); + } else { + prefs_set_correction_char(args[1][0]); + cons_show("LMC char set to %c.", args[1][0]); + } + } + + return TRUE; +} diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index a743951f..a2ccd000 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -227,4 +227,5 @@ gboolean cmd_paste(ProfWin *window, const char *const command, gchar **args); gboolean cmd_color(ProfWin *window, const char *const command, gchar **args); gboolean cmd_avatar(ProfWin *window, const char *const command, gchar **args); gboolean cmd_os(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_correction(ProfWin *window, const char *const command, gchar **args); #endif diff --git a/src/config/preferences.c b/src/config/preferences.c index 6cc2bb56..d817f907 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1201,6 +1201,32 @@ prefs_set_roster_presence_indent(gint value) g_key_file_set_integer(prefs, PREF_GROUP_UI, "roster.presence.indent", value); } +char +prefs_get_correction_char(void) +{ + char result = '+'; + + char *resultstr = g_key_file_get_string(prefs, PREF_GROUP_UI, "correction.char", NULL); + if (!resultstr) { + result = '+'; + } else { + result = resultstr[0]; + } + free(resultstr); + + return result; +} + +void +prefs_set_correction_char(char ch) +{ + char str[2]; + str[0] = ch; + str[1] = '\0'; + + g_key_file_set_string(prefs, PREF_GROUP_UI, "correction.char", str); +} + gboolean prefs_add_room_notify_trigger(const char * const text) { diff --git a/src/config/preferences.h b/src/config/preferences.h index e11eec46..2a30f655 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -268,6 +268,9 @@ void prefs_set_roster_presence_indent(gint value); gint prefs_get_occupants_indent(void); void prefs_set_occupants_indent(gint value); +char prefs_get_correction_char(void); +void prefs_set_correction_char(char ch); + void prefs_add_login(const char *jid); void prefs_set_tray_timer(gint value); -- cgit 1.4.1-2-gfad0 From dd8086772d274542a28b7af045572933f0b6ac7d Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 10 Feb 2020 14:52:42 +0100 Subject: xep-0308: create setting to toggle lmc and print settings if only `/correction` is run. --- src/command/cmd_defs.c | 2 +- src/command/cmd_funcs.c | 8 +++++--- src/config/preferences.c | 3 +++ src/config/preferences.h | 1 + src/ui/console.c | 9 ++++++++- src/ui/window.c | 6 ++---- src/xmpp/capabilities.c | 9 +++++++-- 7 files changed, 27 insertions(+), 11 deletions(-) (limited to 'src/command/cmd_defs.c') diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 1563bf73..982d81f6 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2363,7 +2363,7 @@ static struct cmd_t command_defs[] = }, { "/correction", - parse_args, 1, 1, &cons_correction_setting, + parse_args, 1, 2, &cons_correction_setting, CMD_NOSUBFUNCS CMD_MAINFUNC(cmd_correction) CMD_TAGS( diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 1870429d..70a6dcc0 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8657,15 +8657,17 @@ cmd_correction(ProfWin *window, const char *const command, gchar **args) { // enable/disable if (g_strcmp0(args[0], "on") == 0) { - prefs_set_boolean(PREF_BOOKMARK_INVITE, TRUE); + _cmd_set_boolean_preference(args[0], command, "Last Message Correction", PREF_CORRECTION_ALLOW); + caps_add_feature(XMPP_FEATURE_LAST_MESSAGE_CORRECTION); return TRUE; } else if (g_strcmp0(args[0], "off") == 0) { - prefs_set_boolean(PREF_BOOKMARK_INVITE, FALSE); + _cmd_set_boolean_preference(args[0], command, "Last Message Correction", PREF_CORRECTION_ALLOW); + caps_remove_feature(XMPP_FEATURE_LAST_MESSAGE_CORRECTION); return TRUE; } // char - if (g_strcmp(args[0], "char") == 0) { + if (g_strcmp0(args[0], "char") == 0) { if (args[1] == NULL) { cons_bad_cmd_usage(command); } else if (strlen(args[1]) != 1) { diff --git a/src/config/preferences.c b/src/config/preferences.c index d817f907..dea6a529 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1786,6 +1786,7 @@ _get_group(preference_t pref) case PREF_RECEIPTS_REQUEST: case PREF_REVEAL_OS: case PREF_TLS_CERTPATH: + case PREF_CORRECTION_ALLOW: return PREF_GROUP_CONNECTION; case PREF_OTR_LOG: case PREF_OTR_POLICY: @@ -2036,6 +2037,8 @@ _get_key(preference_t pref) return "log"; case PREF_OMEMO_POLICY: return "policy"; + case PREF_CORRECTION_ALLOW: + return "correction.allow"; default: return NULL; } diff --git a/src/config/preferences.h b/src/config/preferences.h index 2a30f655..4c903272 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -161,6 +161,7 @@ typedef enum { PREF_OMEMO_LOG, PREF_OMEMO_POLICY, PREF_OCCUPANTS_WRAP, + PREF_CORRECTION_ALLOW, } preference_t; typedef struct prof_alias_t { diff --git a/src/ui/console.c b/src/ui/console.c index 57a04290..f7fa448d 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2024,7 +2024,14 @@ cons_os_setting(void) void cons_correction_setting(void) { - cons_show("TODO"); + if (prefs_get_boolean(PREF_CORRECTION_ALLOW)) { + cons_show("Last Message Correction (XEP-0308) (/correction) : ON"); + } else { + cons_show("Last Message Correction (XEP-0308) (/correction) : OFF"); + } + + char cc = prefs_get_correction_char(); + cons_show("LMC indication char (/correction char) : %c", cc); } void diff --git a/src/ui/window.c b/src/ui/window.c index b031ac22..339f4456 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1065,7 +1065,7 @@ win_correct_incoming(ProfWin *window, const char *const message, const char *con return; } - /* + /*TODO: set date? if (entry->date) { if (entry->date->timestamp) { g_date_time_unref(entry->date->timestamp); @@ -1076,9 +1076,7 @@ win_correct_incoming(ProfWin *window, const char *const message, const char *con entry->date = buffer_date_new_now(); */ - // TODO: setting - //entry->show_char = prefs_get_correction_char(); - entry->show_char = '+'; + entry->show_char = prefs_get_correction_char(); if (entry->message) { free(entry->message); diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index ebccec24..a0fcecb0 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -104,14 +104,19 @@ caps_init(void) g_hash_table_add(prof_features, strdup(STANZA_NS_CHATSTATES)); g_hash_table_add(prof_features, strdup(STANZA_NS_PING)); g_hash_table_add(prof_features, strdup(STANZA_NS_STABLE_ID)); + if (prefs_get_boolean(PREF_RECEIPTS_SEND)) { g_hash_table_add(prof_features, strdup(STANZA_NS_RECEIPTS)); } + if (prefs_get_boolean(PREF_LASTACTIVITY)) { g_hash_table_add(prof_features, strdup(STANZA_NS_LASTACTIVITY)); } - //TODO: depend on setting - g_hash_table_add(prof_features, strdup(STANZA_NS_LAST_MESSAGE_CORRECTION)); + + if (prefs_get_boolean(PREF_CORRECTION_ALLOW)) { + g_hash_table_add(prof_features, strdup(STANZA_NS_LAST_MESSAGE_CORRECTION)); + } + my_sha1 = NULL; } -- cgit 1.4.1-2-gfad0 From 11181100712fc2a1c2f310b4470d752488e8961e Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 10 Feb 2020 16:17:01 +0100 Subject: xep-0308: Implement `/correct` to correct the last send message So far the correction is sent. But the UI in Profanity itself is not updated. Also autocompletion for `/correct` with the last sent message is missing. --- src/command/cmd_ac.c | 11 +++++++++++ src/command/cmd_defs.c | 17 +++++++++++++++++ src/command/cmd_funcs.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/command/cmd_funcs.h | 1 + src/event/client_events.c | 26 +++++++++++++++++++------- src/event/client_events.h | 1 + src/ui/chatwin.c | 16 ++++++++++++++++ src/ui/win_types.h | 3 +++ src/ui/window.c | 4 ++++ src/xmpp/message.c | 7 +++++-- src/xmpp/stanza.c | 12 ++++++++++++ src/xmpp/stanza.h | 1 + src/xmpp/xmpp.h | 3 +-- 13 files changed, 132 insertions(+), 11 deletions(-) (limited to 'src/command/cmd_defs.c') diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 0b411bcb..17629d87 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -114,6 +114,7 @@ static char* _logging_autocomplete(ProfWin *window, const char *const input, gbo static char* _color_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _avatar_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _correction_autocomplete(ProfWin *window, const char *const input, gboolean previous); +static char* _correct_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _script_autocomplete_func(const char *const prefix, gboolean previous, void *context); @@ -1640,6 +1641,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ g_hash_table_insert(ac_funcs, "/color", _color_autocomplete); g_hash_table_insert(ac_funcs, "/avatar", _avatar_autocomplete); g_hash_table_insert(ac_funcs, "/correction", _correction_autocomplete); + g_hash_table_insert(ac_funcs, "/correct", _correct_autocomplete); int len = strlen(input); char parsed[len+1]; @@ -3736,3 +3738,12 @@ _correction_autocomplete(ProfWin *window, const char *const input, gboolean prev return NULL; } + +static char* +_correct_autocomplete(ProfWin *window, const char *const input, gboolean previous) +{ + char *result = NULL; + + //TODO: get last message + return result; +} diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 982d81f6..db719b17 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2367,6 +2367,7 @@ static struct cmd_t command_defs[] = CMD_NOSUBFUNCS CMD_MAINFUNC(cmd_correction) CMD_TAGS( + CMD_TAG_UI, CMD_TAG_CHAT, CMD_TAG_GROUPCHAT) CMD_SYN( @@ -2379,6 +2380,22 @@ static struct cmd_t command_defs[] = { "char", "Set character that will prefix corrected messages. Default: +"}) CMD_NOEXAMPLES }, + + { "/correct", + parse_args, 1, 1, NULL, + CMD_NOSUBFUNCS + CMD_MAINFUNC(cmd_correct) + CMD_TAGS( + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/correct ") + CMD_DESC( + "Correct and resend the last message (XEP-0308).") + CMD_ARGS( + { "", "The corrected message."}) + CMD_NOEXAMPLES + }, }; static GHashTable *search_index; diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 70a6dcc0..9620f0d7 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8680,3 +8680,44 @@ cmd_correction(ProfWin *window, const char *const command, gchar **args) return TRUE; } + +gboolean +cmd_correct(ProfWin *window, const char *const command, gchar **args) +{ + jabber_conn_status_t conn_status = connection_get_status(); + if (conn_status != JABBER_CONNECTED) { + cons_show("You are currently not connected."); + return TRUE; + } + + if (window->type == WIN_CHAT) { + ProfChatWin *chatwin = (ProfChatWin*)window; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + + if (chatwin->last_msg_id == NULL || chatwin->last_message == NULL) { + win_println(window, THEME_DEFAULT, '!', "No last message to correct."); + return TRUE; + } + + /* + char *session_jid = chat_session_get_jid(chatwin->barejid); + if (session_jid == NULL) { + win_println(window, THEME_DEFAULT, '!', "Cannot determine if recipeint supports last message correction."); + free(session_jid); + return TRUE; + } + + if (caps_jid_has_feature(session_jid, XMPP_FEATURE_LAST_MESSAGE_CORRECTION) == FALSE) { + win_println(window, THEME_DEFAULT, '!', "Recipient does not support last message correction."); + free(session_jid); + return TRUE; + } + + */ + // speciel send with replace tag + cl_ev_send_msg_correct(chatwin, args[0], FALSE, TRUE); + } + + win_println(window, THEME_DEFAULT, '!', "Command /correct only valid in regular chat windows."); + return TRUE; +} diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index a2ccd000..768e14a2 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -228,4 +228,5 @@ gboolean cmd_color(ProfWin *window, const char *const command, gchar **args); gboolean cmd_avatar(ProfWin *window, const char *const command, gchar **args); gboolean cmd_os(ProfWin *window, const char *const command, gchar **args); gboolean cmd_correction(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_correct(ProfWin *window, const char *const command, gchar **args); #endif diff --git a/src/event/client_events.c b/src/event/client_events.c index 6716b7e2..50a46ccc 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -115,7 +115,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs } void -cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oob_url) +cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *const oob_url, gboolean correct_last_msg) { chat_state_active(chatwin->state); @@ -139,11 +139,17 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo return; } + char *replace_id = NULL; + if (correct_last_msg) { + replace_id = chatwin->last_msg_id; + } + // OTR suported, PGP supported, OMEMO unsupported #ifdef HAVE_LIBOTR #ifdef HAVE_LIBGPGME #ifndef HAVE_OMEMO if (chatwin->pgp_send) { + // TODO: replace_id char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt); chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL); chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt); @@ -151,7 +157,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo } else { gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt); if (!handled) { - char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt); + char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id); chat_log_msg_out(chatwin->barejid, plugin_msg, NULL); chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PLAIN, request_receipt); free(id); @@ -171,7 +177,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo #ifndef HAVE_OMEMO gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt); if (!handled) { - char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt); + char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id); chat_log_msg_out(chatwin->barejid, plugin_msg, NULL); chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PLAIN, request_receipt); free(id); @@ -194,7 +200,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt); free(id); } else { - char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt); + char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id); chat_log_msg_out(chatwin->barejid, plugin_msg, NULL); chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PLAIN, request_receipt); free(id); @@ -217,7 +223,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt); free(id); } else { - char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt); + char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id); chat_log_msg_out(chatwin->barejid, plugin_msg, NULL); chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PLAIN, request_receipt); free(id); @@ -242,7 +248,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo } else { gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt); if (!handled) { - char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt); + char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id); chat_log_msg_out(chatwin->barejid, plugin_msg, NULL); chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PLAIN, request_receipt); free(id); @@ -301,7 +307,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo } else { gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt); if (!handled) { - char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt); + char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id); chat_log_msg_out(chatwin->barejid, plugin_msg, NULL); chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PLAIN, request_receipt); free(id); @@ -332,6 +338,12 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo #endif } +void +cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oob_url) +{ + cl_ev_send_msg_correct(chatwin, msg, oob_url, FALSE); +} + void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const oob_url) { diff --git a/src/event/client_events.h b/src/event/client_events.h index 82150f2e..66ade679 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -45,6 +45,7 @@ void cl_ev_disconnect(void); void cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs); +void cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *const oob_url, gboolean correct_last_msg); void cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oob_url); void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const oob_url); void cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg, const char *const oob_url); diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 8faf4934..d7906815 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -56,6 +56,7 @@ #endif static void _chatwin_history(ProfChatWin *chatwin, const char *const contact); +static void _chatwin_set_last_message(ProfChatWin *chatwin, const char *const id, const char *const message); ProfChatWin* chatwin_new(const char *const barejid) @@ -323,6 +324,11 @@ chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, enc_char = prefs_get_omemo_char(); } + // save last id and message for LMC + if (id) { + _chatwin_set_last_message(chatwin, id, message); + } + if (request_receipt && id) { win_print_with_receipt((ProfWin*)chatwin, enc_char, "me", message, id); } else { @@ -496,3 +502,13 @@ _chatwin_history(ProfChatWin *chatwin, const char *const contact) g_slist_free_full(history, free); } } + +static void +_chatwin_set_last_message(ProfChatWin *chatwin, const char *const id, const char *const message) +{ + free(chatwin->last_message); + chatwin->last_message = strdup(message); + + free(chatwin->last_msg_id); + chatwin->last_msg_id = strdup(id); +} diff --git a/src/ui/win_types.h b/src/ui/win_types.h index 68ed719e..0a0545bd 100644 --- a/src/ui/win_types.h +++ b/src/ui/win_types.h @@ -160,6 +160,9 @@ typedef struct prof_chat_win_t { char *enctext; char *incoming_char; char *outgoing_char; + // For LMC + char *last_message; + char *last_msg_id; } ProfChatWin; typedef struct prof_muc_win_t { diff --git a/src/ui/window.c b/src/ui/window.c index 339f4456..c668bd34 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -152,6 +152,8 @@ win_create_chat(const char *const barejid) new_win->enctext = NULL; new_win->incoming_char = NULL; new_win->outgoing_char = NULL; + new_win->last_message = NULL; + new_win->last_msg_id = NULL; new_win->memcheck = PROFCHATWIN_MEMCHECK; @@ -488,6 +490,8 @@ win_free(ProfWin* window) free(chatwin->enctext); free(chatwin->incoming_char); free(chatwin->outgoing_char); + free(chatwin->last_message); + free(chatwin->last_msg_id); chat_state_free(chatwin->state); break; } diff --git a/src/xmpp/message.c b/src/xmpp/message.c index f6100fa8..027b88f1 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -259,8 +259,7 @@ message_pubsub_event_handler_add(const char *const node, ProfMessageCallback fun } char* -message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url, - gboolean request_receipt) +message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url, gboolean request_receipt, const char *const replace_id) { xmpp_ctx_t * const ctx = connection_get_ctx(); @@ -284,6 +283,10 @@ message_send_chat(const char *const barejid, const char *const msg, const char * stanza_attach_receipt_request(ctx, message); } + if (replace_id) { + stanza_attach_correction(ctx, message, replace_id); + } + _send_message_stanza(message); xmpp_stanza_release(message); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index f398a268..7b0db5c7 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -2606,3 +2606,15 @@ stanza_create_avatar_retrieve_data_request(xmpp_ctx_t *ctx, const char *stanza_i return iq; } + +xmpp_stanza_t* +stanza_attach_correction(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const replace_id) +{ + xmpp_stanza_t *replace_stanza = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(replace_stanza, "replace"); + xmpp_stanza_set_id(replace_stanza, replace_id); + xmpp_stanza_set_ns(replace_stanza, STANZA_NS_LAST_MESSAGE_CORRECTION); + xmpp_stanza_add_child(stanza, replace_stanza); + + return stanza; +} diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index dc8c4e34..ee5c6772 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -245,6 +245,7 @@ xmpp_stanza_t* stanza_attach_hints_store(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza) xmpp_stanza_t* stanza_attach_receipt_request(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza); xmpp_stanza_t* stanza_attach_x_oob_url(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const url); xmpp_stanza_t* stanza_attach_origin_id(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const id); +xmpp_stanza_t* stanza_attach_correction(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const replace_id); xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t *const ctx, const char *const full_room_jid, const char *const passwd); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index dc1cdf27..15c61fa8 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -171,8 +171,7 @@ char* connection_jid_for_feature(const char *const feature); const char* connection_get_profanity_identifier(void); -char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url, - gboolean request_receipt); +char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url, gboolean request_receipt, const char *const replace_id); char* message_send_chat_otr(const char *const barejid, const char *const msg, gboolean request_receipt); char* message_send_chat_pgp(const char *const barejid, const char *const msg, gboolean request_receipt); char* message_send_chat_omemo(const char *const jid, uint32_t sid, GList *keys, const unsigned char *const iv, size_t iv_len, const unsigned char *const ciphertext, size_t ciphertext_len, gboolean request_receipt, gboolean muc); -- cgit 1.4.1-2-gfad0 From 1072cdab0add1389d0ab6667aceecf64e583fcc4 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 12 Feb 2020 14:45:26 +0100 Subject: xep-0308: Fix sending corrections for multiple words --- src/command/cmd_ac.c | 3 ++- src/command/cmd_defs.c | 6 ++++-- src/command/cmd_funcs.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/command/cmd_defs.c') diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 386e8939..c91bb447 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -3765,8 +3765,9 @@ _correct_autocomplete(ProfWin *window, const char *const input, gboolean previou return NULL; } - GString *result_str = g_string_new("/correct "); + GString *result_str = g_string_new("/correct \""); g_string_append(result_str, last_message); + g_string_append(result_str, "\""); char *result = result_str->str; g_string_free(result_str, FALSE); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index db719b17..a7b7e49c 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2393,8 +2393,10 @@ static struct cmd_t command_defs[] = CMD_DESC( "Correct and resend the last message (XEP-0308).") CMD_ARGS( - { "", "The corrected message."}) - CMD_NOEXAMPLES + { "\"message\"", "The corrected message. Multiple words need quotation marks."}) + CMD_EXAMPLES( + "/correct Profanity", + "/correct \"Profanity is the best\"") }, }; diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 768e14a2..f283c910 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -54,7 +54,7 @@ typedef struct cmd_help_t { * cmd - The command string including leading '/' * parser - The function used to parse arguments * min_args - Minimum number of arguments - * max_args - Maximum number of arguments + * max_args - Maximum number of arguments, -1 for infinite * setting_func - Function to display current settings to the console * sub_funcs - Optional list of functions mapped to the first argument * func - Main function to call when no arguments, or sub_funcs not implemented -- cgit 1.4.1-2-gfad0 From 8f37afcd37ad8663ca36c13ca7fbc4a431119f73 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 12 Feb 2020 14:50:58 +0100 Subject: xep-0308: Make /correct work without quotation marks Now we can specify an unlimited amount of arguments for commands. Maybe this is also helpful for other commands that use quotation marks so far. --- src/command/cmd_ac.c | 3 +-- src/command/cmd_defs.c | 8 +++----- src/command/cmd_funcs.c | 10 ++++++++-- src/tools/parser.c | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src/command/cmd_defs.c') diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index c91bb447..386e8939 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -3765,9 +3765,8 @@ _correct_autocomplete(ProfWin *window, const char *const input, gboolean previou return NULL; } - GString *result_str = g_string_new("/correct \""); + GString *result_str = g_string_new("/correct "); g_string_append(result_str, last_message); - g_string_append(result_str, "\""); char *result = result_str->str; g_string_free(result_str, FALSE); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index a7b7e49c..60fb262e 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2382,7 +2382,7 @@ static struct cmd_t command_defs[] = }, { "/correct", - parse_args, 1, 1, NULL, + parse_args, 1, -1, NULL, CMD_NOSUBFUNCS CMD_MAINFUNC(cmd_correct) CMD_TAGS( @@ -2393,10 +2393,8 @@ static struct cmd_t command_defs[] = CMD_DESC( "Correct and resend the last message (XEP-0308).") CMD_ARGS( - { "\"message\"", "The corrected message. Multiple words need quotation marks."}) - CMD_EXAMPLES( - "/correct Profanity", - "/correct \"Profanity is the best\"") + { "message", "The corrected message."}) + CMD_NOEXAMPLES }, }; diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index cfb78cd4..40f5d8f4 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8701,7 +8701,10 @@ cmd_correct(ProfWin *window, const char *const command, gchar **args) } // send message again, with replace flag - cl_ev_send_msg_correct(chatwin, args[0], FALSE, TRUE); + gchar *message = g_strjoinv(" ", args); + cl_ev_send_msg_correct(chatwin, message, FALSE, TRUE); + + free(message); return TRUE; } else if (window->type == WIN_MUC) { ProfMucWin *mucwin = (ProfMucWin*)window; @@ -8713,7 +8716,10 @@ cmd_correct(ProfWin *window, const char *const command, gchar **args) } // send message again, with replace flag - cl_ev_send_muc_msg_corrected(mucwin, args[0], FALSE, TRUE); + gchar *message = g_strjoinv(" ", args); + cl_ev_send_muc_msg_corrected(mucwin, message, FALSE, TRUE); + + free(message); return TRUE; } diff --git a/src/tools/parser.c b/src/tools/parser.c index aa739330..fb21571c 100644 --- a/src/tools/parser.c +++ b/src/tools/parser.c @@ -48,7 +48,7 @@ * * inp - The line of input * min - The minimum allowed number of arguments - * max - The maximum allowed number of arguments + * max - The maximum allowed number of arguments, -1 for infinite * * Returns - An NULL terminated array of strings representing the arguments * of the command, or NULL if the validation fails. @@ -135,7 +135,7 @@ parse_args(const char *const inp, int min, int max, gboolean *result) int num = g_slist_length(tokens) - 1; // if num args not valid return NULL - if ((num < min) || (num > max)) { + if ((num < min) || ((max != -1) && (num > max))) { g_slist_free_full(tokens, free); g_free(copy); *result = FALSE; -- cgit 1.4.1-2-gfad0 From 4241917fbaa7da4c108236eaec27fdfff84d72fe Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Fri, 14 Feb 2020 10:06:25 +0100 Subject: xep-0308: add caution note We need to change the buffer structure first, so that we save the from field there. --- src/command/cmd_defs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/command/cmd_defs.c') diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 60fb262e..cc8f0a7a 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2374,7 +2374,7 @@ static struct cmd_t command_defs[] = "/correction |", "/correction char ") CMD_DESC( - "Settings regarding Last Message Correction (XEP-0308).") + "Settings regarding Last Message Correction (XEP-0308). Caution: We do not yet check the 'from' field. So it could happen that someone else is overwriting the actual message.") CMD_ARGS( { "on|off", "Enable/Disable support for last message correction."}, { "char", "Set character that will prefix corrected messages. Default: +"}) -- cgit 1.4.1-2-gfad0