From b670778aa357c1f36ac07caf6034193e6ddded3f Mon Sep 17 00:00:00 2001 From: "jabber.developer2" Date: Sat, 16 May 2026 17:16:44 +0300 Subject: [PATCH] fix(history): address PR #116 review feedback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - console: drop orphaned `Chat logging (/logging chat)` lines from cons_logging_setting() and cons_privacy_setting() — the /logging chat subcommand was removed, PREF_CHLOG now tracks PREF_HISTORY implicitly - command: deprecate /logging command. It now prints a single notice pointing to /history; CMD_PREAMBLE trimmed (min_args=0, no setting_func, syntax/args/examples dropped); subcommand 'group' removed from autocomplete - sqlite: gate LMC merge in _sqlite_get_previous_chat() on PREF_CORRECTION_ALLOW. When /correction is off, return original and correction rows as separate messages instead of merging via COALESCE/LEFT JOIN — matches the flatfile load path and the PR's stated semantics for /correction off --- src/command/cmd_ac.c | 2 -- src/command/cmd_defs.c | 11 +++-------- src/command/cmd_funcs.c | 12 +----------- src/database_sqlite.c | 21 +++++++++++++++++---- src/ui/console.c | 10 ---------- 5 files changed, 21 insertions(+), 35 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 93de95aa..acab53b5 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1147,8 +1147,6 @@ cmd_ac_init(void) autocomplete_add(status_state_ac, "xa"); autocomplete_add(status_state_ac, "dnd"); - autocomplete_add(logging_ac, "group"); - autocomplete_add(privacy_ac, "logging"); autocomplete_add(privacy_ac, "os"); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index d225c2fd..432770e0 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1660,19 +1660,14 @@ static const struct cmd_t command_defs[] = { }, { CMD_PREAMBLE("/logging", - parse_args, 2, 3, &cons_logging_setting) + parse_args, 0, 3, NULL) CMD_MAINFUNC(cmd_logging) CMD_TAGS( CMD_TAG_CHAT) CMD_SYN( - "/logging group on|off") + "/logging") CMD_DESC( - "Configure groupchat (MUC) logging. " - "Regular chat logging is controlled by /history.") - CMD_ARGS( - { "group on|off", "Enable/Disable groupchat (room) logging." }) - CMD_EXAMPLES( - "/logging group off") + "Deprecated. Use '/history' instead.") }, { CMD_PREAMBLE("/states", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 007b9f59..2a49415e 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -6731,17 +6731,7 @@ cmd_privacy(ProfWin* window, const char* const command, gchar** args) gboolean cmd_logging(ProfWin* window, const char* const command, gchar** args) { - if (args[0] == NULL) { - cons_logging_setting(); - return TRUE; - } - - if (g_strcmp0(args[0], "group") == 0 && args[1] != NULL) { - _cmd_set_boolean_preference(args[1], "Groupchat logging", PREF_GRLOG); - return TRUE; - } - - cons_bad_cmd_usage(command); + cons_show("The '/logging' command is deprecated, use '/history' instead."); return TRUE; } diff --git a/src/database_sqlite.c b/src/database_sqlite.c index 446b14cb..31f6dc93 100644 --- a/src/database_sqlite.c +++ b/src/database_sqlite.c @@ -384,16 +384,29 @@ _sqlite_get_previous_chat(const gchar* const contact_barejid, const gchar* start const gchar* sort2 = !flip ? "ASC" : "DESC"; GDateTime* now = g_date_time_new_now_local(); auto_gchar gchar* end_date_fmt = end_time ? g_strdup(end_time) : g_date_time_format_iso8601(now); + + // When LMC is disabled, return original and correction rows as separate + // messages instead of merging the correction text into the original. + // Otherwise the user sees corrected text in history even with + // /correction off. + const gboolean lmc_allowed = prefs_get_boolean(PREF_CORRECTION_ALLOW); + const char* msg_expr = lmc_allowed ? "COALESCE(B.`message`, A.`message`)" : "A.`message`"; + const char* join_clause = lmc_allowed + ? "LEFT JOIN `ChatLogs` AS B ON (A.`replaced_by_db_id` = B.`id` AND A.`from_jid` = B.`from_jid`) " + : ""; + const char* replaces_filter = lmc_allowed ? "(A.`replaces_db_id` IS NULL) AND " : ""; + auto_sqlite gchar* query = sqlite3_mprintf("SELECT * FROM (" - "SELECT COALESCE(B.`message`, A.`message`) AS message, " + "SELECT %s AS message, " "A.`timestamp`, A.`from_jid`, A.`from_resource`, A.`to_jid`, A.`to_resource`, A.`type`, A.`encryption`, A.`stanza_id` FROM `ChatLogs` AS A " - "LEFT JOIN `ChatLogs` AS B ON (A.`replaced_by_db_id` = B.`id` AND A.`from_jid` = B.`from_jid`) " - "WHERE (A.`replaces_db_id` IS NULL) " - "AND ((A.`from_jid` = %Q AND A.`to_jid` = %Q) OR (A.`from_jid` = %Q AND A.`to_jid` = %Q)) " + "%s" + "WHERE %s" + "((A.`from_jid` = %Q AND A.`to_jid` = %Q) OR (A.`from_jid` = %Q AND A.`to_jid` = %Q)) " "AND A.`timestamp` < %Q " "AND (%Q IS NULL OR A.`timestamp` > %Q) " "ORDER BY A.`timestamp` %s LIMIT %d) " "ORDER BY `timestamp` %s;", + msg_expr, join_clause, replaces_filter, contact_barejid, myjid->barejid, myjid->barejid, contact_barejid, end_date_fmt, start_time, start_time, sort1, MESSAGES_TO_RETRIEVE, sort2); g_date_time_unref(now); diff --git a/src/ui/console.c b/src/ui/console.c index e6c3a96c..72e6d8fa 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1951,11 +1951,6 @@ cons_log_setting(void) void cons_logging_setting(void) { - if (prefs_get_boolean(PREF_CHLOG)) - cons_show("Chat logging (/logging chat) : ON"); - else - cons_show("Chat logging (/logging chat) : OFF"); - if (prefs_get_boolean(PREF_GRLOG)) cons_show("Groupchat logging (/logging group) : ON"); else @@ -2862,11 +2857,6 @@ cons_privacy_setting(void) { cons_show("Database logging : %s", prefs_get_string(PREF_DBLOG)); - if (prefs_get_boolean(PREF_CHLOG)) { - cons_show("Chat logging (/logging chat) : ON"); - } else { - cons_show("Chat logging (/logging chat) : OFF"); - } if (prefs_get_boolean(PREF_HISTORY)) { cons_show("Chat history (/history) : ON"); } else {