Fix de-duping migration when resolving date conflicts.

This commit is contained in:
Greyson Parrelli 2023-05-12 09:45:02 -04:00
parent 2eff9e0230
commit 084cdd7200

View file

@ -236,7 +236,8 @@ object V191_UniqueMessageMigrationV2 : SignalDatabaseMigration {
.sortedByDescending { it.id }
.drop(1)
.forEach { duplicate ->
while (!isDateAvailable(db, duplicate.dateSent, duplicate.fromRecipientId, duplicate.threadId)) {
while (isDateTaken(db, candidateDateSent, duplicate.fromRecipientId, duplicate.threadId)) {
Log.d(TAG, "(date=$candidateDateSent, from=${duplicate.fromRecipientId}, thread=${duplicate.threadId} not available! Decrementing.")
candidateDateSent--
}
@ -252,7 +253,8 @@ object V191_UniqueMessageMigrationV2 : SignalDatabaseMigration {
}
}
private fun isDateAvailable(db: SQLiteDatabase, dateSent: Long, fromRecipientId: Long, threadId: Long): Boolean {
/** True if there already exists a message with the provided tuple, otherwise false. */
private fun isDateTaken(db: SQLiteDatabase, dateSent: Long, fromRecipientId: Long, threadId: Long): Boolean {
return db.rawQuery(
"""
SELECT EXISTS (