Add inbox delivery status migration

Fixes #4799
Closes #4809

// FREEBIE
This commit is contained in:
haffenloher 2015-12-04 22:47:33 +01:00 committed by Moxie Marlinspike
parent b99c4e3e39
commit b41364c709

View file

@ -70,7 +70,8 @@ public class DatabaseFactory {
private static final int INTRODUCED_CONVERSATION_LIST_THUMBNAILS_VERSION = 23;
private static final int INTRODUCED_ARCHIVE_VERSION = 24;
private static final int INTRODUCED_CONVERSATION_LIST_STATUS_VERSION = 25;
private static final int DATABASE_VERSION = 25;
private static final int MIGRATED_CONVERSATION_LIST_STATUS_VERSION = 26;
private static final int DATABASE_VERSION = 26;
private static final String DATABASE_NAME = "messages.db";
private static final Object lock = new Object();
@ -790,6 +791,28 @@ public class DatabaseFactory {
db.execSQL("ALTER TABLE thread ADD COLUMN delivery_receipt_count INTEGER DEFAULT 0");
}
if (oldVersion < MIGRATED_CONVERSATION_LIST_STATUS_VERSION) {
Cursor threadCursor = db.query("thread", new String[] {"_id"}, null, null, null, null, null);
while (threadCursor != null && threadCursor.moveToNext()) {
long threadId = threadCursor.getLong(threadCursor.getColumnIndexOrThrow("_id"));
Cursor cursor = db.rawQuery("SELECT DISTINCT date AS date_received, status, " +
"delivery_receipt_count FROM sms WHERE (thread_id = ?1) " +
"UNION ALL SELECT DISTINCT date_received, -1 AS status, " +
"delivery_receipt_count FROM mms WHERE (thread_id = ?1) " +
"ORDER BY date_received DESC LIMIT 1", new String[]{threadId + ""});
if (cursor != null && cursor.moveToNext()) {
int status = cursor.getInt(cursor.getColumnIndexOrThrow("status"));
int receiptCount = cursor.getInt(cursor.getColumnIndexOrThrow("delivery_receipt_count"));
db.execSQL("UPDATE thread SET status = ?, delivery_receipt_count = ? WHERE _id = ?",
new String[]{status + "", receiptCount + "", threadId + ""});
}
}
}
db.setTransactionSuccessful();
db.endTransaction();
}