From e6e8416aec53b131a365f24aaf4a4cdf6dd61746 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 22 May 2018 12:08:24 -0400 Subject: [PATCH] Use correct recipient for message search results. Previously, we'd always use the recipient of the message record, which was incorrect for messages sent to groups. Now we always use the recipient for the matching thread record. Fixes #7823 --- .../securesms/database/SearchDatabase.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/SearchDatabase.java b/src/org/thoughtcrime/securesms/database/SearchDatabase.java index 430e257f91..d5c4c0cd8e 100644 --- a/src/org/thoughtcrime/securesms/database/SearchDatabase.java +++ b/src/org/thoughtcrime/securesms/database/SearchDatabase.java @@ -53,23 +53,25 @@ public class SearchDatabase extends Database { private static final String MESSAGES_QUERY = "SELECT " + - MmsSmsColumns.ADDRESS + ", " + + ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.ADDRESS + ", " + "snippet(" + SMS_FTS_TABLE_NAME + ", -1, '', '', '...', 7) AS " + SNIPPET + ", " + - SmsDatabase.DATE_RECEIVED + " AS " + MmsSmsColumns.NORMALIZED_DATE_RECEIVED + ", " + + SmsDatabase.TABLE_NAME + "." + SmsDatabase.DATE_RECEIVED + " AS " + MmsSmsColumns.NORMALIZED_DATE_RECEIVED + ", " + MmsSmsColumns.THREAD_ID + ", " + "bm25(" + SMS_FTS_TABLE_NAME + ") AS " + RANK + " " + "FROM " + SmsDatabase.TABLE_NAME + " " + "INNER JOIN " + SMS_FTS_TABLE_NAME + " ON " + SMS_FTS_TABLE_NAME + "." + ID + " = " + SmsDatabase.TABLE_NAME + "." + SmsDatabase.ID + " " + + "INNER JOIN " + ThreadDatabase.TABLE_NAME + " ON " + SmsDatabase.TABLE_NAME + "." + MmsSmsColumns.THREAD_ID + " = " + ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.ID + " " + "WHERE " + SMS_FTS_TABLE_NAME + " MATCH ? " + "UNION ALL " + "SELECT " + - MmsSmsColumns.ADDRESS + ", " + + ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.ADDRESS + ", " + "snippet(" + MMS_FTS_TABLE_NAME + ", -1, '', '', '...', 7) AS " + SNIPPET + ", " + - MmsDatabase.DATE_RECEIVED + " AS " + MmsSmsColumns.NORMALIZED_DATE_RECEIVED + ", " + + MmsDatabase.TABLE_NAME + "." + MmsDatabase.DATE_RECEIVED + " AS " + MmsSmsColumns.NORMALIZED_DATE_RECEIVED + ", " + MmsSmsColumns.THREAD_ID + ", " + "bm25(" + MMS_FTS_TABLE_NAME + ") AS " + RANK + " " + "FROM " + MmsDatabase.TABLE_NAME + " " + "INNER JOIN " + MMS_FTS_TABLE_NAME + " ON " + MMS_FTS_TABLE_NAME + "." + ID + " = " + MmsDatabase.TABLE_NAME + "." + MmsDatabase.ID + " " + + "INNER JOIN " + ThreadDatabase.TABLE_NAME + " ON " + MmsDatabase.TABLE_NAME + "." + MmsSmsColumns.THREAD_ID + " = " + ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.ID + " " + "WHERE " + MMS_FTS_TABLE_NAME + " MATCH ? " + "ORDER BY rank " + "LIMIT 500";