Fix problem with direct share

Fixes #6968
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-09-15 10:36:33 -07:00
parent b6aedd330e
commit 260383ac21

View File

@ -23,6 +23,7 @@ import android.database.MergeCursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@ -327,15 +328,7 @@ public class ThreadDatabase extends Database {
selectionArgs[i++] = DelimiterUtil.escape(address.serialize(), ' '); selectionArgs[i++] = DelimiterUtil.escape(address.serialize(), ' ');
} }
String projection = Util.join(COMBINED_THREAD_RECIPIENT_GROUP_PROJECTION, ","); String query = createQuery(selection);
String query = "SELECT " + projection + " FROM " + TABLE_NAME +
" LEFT OUTER JOIN " + RecipientDatabase.TABLE_NAME +
" ON " + TABLE_NAME + "." + ADDRESS + " = " + RecipientDatabase.TABLE_NAME + "." + RecipientDatabase.ADDRESS +
" LEFT OUTER JOIN " + GroupDatabase.TABLE_NAME +
" ON " + TABLE_NAME + "." + ADDRESS + " = " + GroupDatabase.TABLE_NAME + "." + GroupDatabase.GROUP_ID +
" WHERE " + selection +
" ORDER BY " + TABLE_NAME + "." + DATE + " DESC";
cursors.add(db.rawQuery(query, selectionArgs)); cursors.add(db.rawQuery(query, selectionArgs));
} }
@ -353,16 +346,9 @@ public class ThreadDatabase extends Database {
} }
private Cursor getConversationList(String archived) { private Cursor getConversationList(String archived) {
String projection = Util.join(COMBINED_THREAD_RECIPIENT_GROUP_PROJECTION, ",");
SQLiteDatabase db = databaseHelper.getReadableDatabase(); SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT " + projection + " FROM " + TABLE_NAME + String query = createQuery(ARCHIVED + " = ? AND " + MESSAGE_COUNT + " != 0");
" LEFT OUTER JOIN " + RecipientDatabase.TABLE_NAME + Cursor cursor = db.rawQuery(query, new String[]{archived});
" ON " + TABLE_NAME + "." + ADDRESS + " = " + RecipientDatabase.TABLE_NAME + "." + RecipientDatabase.ADDRESS +
" LEFT OUTER JOIN " + GroupDatabase.TABLE_NAME +
" ON " + TABLE_NAME + "." + ADDRESS + " = " + GroupDatabase.TABLE_NAME + "." + GroupDatabase.GROUP_ID +
" WHERE " + ARCHIVED + " = ? AND " + MESSAGE_COUNT + " != 0" +
" ORDER BY " + TABLE_NAME + "." + DATE + " DESC",
new String[] {archived});
setNotifyConverationListListeners(cursor); setNotifyConverationListListeners(cursor);
@ -371,13 +357,9 @@ public class ThreadDatabase extends Database {
public Cursor getDirectShareList() { public Cursor getDirectShareList() {
SQLiteDatabase db = databaseHelper.getReadableDatabase(); SQLiteDatabase db = databaseHelper.getReadableDatabase();
String projection = Util.join(COMBINED_THREAD_RECIPIENT_GROUP_PROJECTION, ","); String query = createQuery(MESSAGE_COUNT + " != 0");
return db.rawQuery("SELECT " + projection + " FROM " + TABLE_NAME + return db.rawQuery(query, null);
" LEFT OUTER JOIN " + RecipientDatabase.TABLE_NAME +
" ON " + TABLE_NAME + "." + ADDRESS + " = " + RecipientDatabase.TABLE_NAME + "." + ADDRESS +
" ORDER BY " + TABLE_NAME + "." + DATE + " DESC",
null);
} }
public int getArchivedConversationListCount() { public int getArchivedConversationListCount() {
@ -592,6 +574,17 @@ public class ThreadDatabase extends Database {
return thumbnail != null ? thumbnail.getThumbnailUri() : null; return thumbnail != null ? thumbnail.getThumbnailUri() : null;
} }
private @NonNull String createQuery(@NonNull String where) {
String projection = Util.join(COMBINED_THREAD_RECIPIENT_GROUP_PROJECTION, ",");
return "SELECT " + projection + " FROM " + TABLE_NAME +
" LEFT OUTER JOIN " + RecipientDatabase.TABLE_NAME +
" ON " + TABLE_NAME + "." + ADDRESS + " = " + RecipientDatabase.TABLE_NAME + "." + RecipientDatabase.ADDRESS +
" LEFT OUTER JOIN " + GroupDatabase.TABLE_NAME +
" ON " + TABLE_NAME + "." + ADDRESS + " = " + GroupDatabase.TABLE_NAME + "." + GroupDatabase.GROUP_ID +
" WHERE " + where +
" ORDER BY " + TABLE_NAME + "." + DATE + " DESC";
}
public static interface ProgressListener { public static interface ProgressListener {
public void onProgress(int complete, int total); public void onProgress(int complete, int total);
} }