about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-04-10 14:59:27 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-04-10 14:59:27 +0200
commitb2eea969dbf9f1c7556ccfb5ccc60dd0724199a3 (patch)
treefd4cb831d1e8af848218f96d5df261e3a8f2fb4d
parente1b8fb24c39f2f1f90ce48324983310bfbf16346 (diff)
downloadprofani-tty-b2eea969dbf9f1c7556ccfb5ccc60dd0724199a3.tar.gz
Fix error in getting previous chatlog
Our search was too broad, and thus incorrect.

One of the various mistakes it can cause was
https://github.com/profanity-im/profanity/issues/1308

Fix https://github.com/profanity-im/profanity/issues/1308
-rw-r--r--src/database.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/database.c b/src/database.c
index c02392be..ddff84cc 100644
--- a/src/database.c
+++ b/src/database.c
@@ -215,12 +215,16 @@ log_database_get_previous_chat(const gchar *const contact_barejid)
 {
 	sqlite3_stmt *stmt = NULL;
     char *query;
+    const char *jid = connection_get_fulljid();
+    Jid *myjid = jid_create(jid);
 
-    if (asprintf(&query, "SELECT * FROM (SELECT `message`, `timestamp`, `from_jid`, `type` from `ChatLogs` WHERE `from_jid` = '%s' OR `to_jid` = '%s' ORDER BY `timestamp` DESC LIMIT 10) ORDER BY `timestamp` ASC;", contact_barejid, contact_barejid) == -1) {
+    if (asprintf(&query, "SELECT * FROM (SELECT `message`, `timestamp`, `from_jid`, `type` from `ChatLogs` WHERE (`from_jid` = '%s' AND `to_jid` = '%s') OR (`from_jid` = '%s' AND `to_jid` = '%s') ORDER BY `timestamp` DESC LIMIT 10) ORDER BY `timestamp` ASC;", contact_barejid, myjid->barejid, myjid->barejid, contact_barejid) == -1) {
         log_error("log_database_get_previous_chat(): SQL query. could not allocate memory");
         return NULL;
     }
 
+    jid_destroy(myjid);
+
 	int rc = sqlite3_prepare_v2(g_chatlog_database, query, -1, &stmt, NULL);
 	if( rc!=SQLITE_OK ) {
         log_error("log_database_get_previous_chat(): unknown SQLite error");