fix(history): address PR #116 review feedback
All checks were successful
CI Code / Check coding style (pull_request) Successful in 33s
CI Code / Check spelling (pull_request) Successful in 20s
CI Code / Code Coverage (pull_request) Successful in 2m44s
CI Code / Linux (debian) (pull_request) Successful in 4m40s
CI Code / Linux (ubuntu) (pull_request) Successful in 4m55s
CI Code / Linux (arch) (pull_request) Successful in 5m42s

- 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
This commit is contained in:
2026-05-16 17:16:44 +03:00
parent 102c32c744
commit d8ce4ca80e
5 changed files with 21 additions and 35 deletions

View File

@@ -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);