Ensure default chat folder exists.

This commit is contained in:
Michelle Tang
2025-05-21 11:33:13 -04:00
committed by GitHub
parent 4f6bedf323
commit 7dc4cb4ce7
5 changed files with 77 additions and 4 deletions

View File

@@ -129,6 +129,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V271_AddNotificatio
import org.thoughtcrime.securesms.database.helpers.migration.V272_UpdateUnreadCountIndices
import org.thoughtcrime.securesms.database.helpers.migration.V273_FixUnreadOriginalMessages
import org.thoughtcrime.securesms.database.helpers.migration.V274_BackupMediaSnapshotLastSeenOnRemote
import org.thoughtcrime.securesms.database.helpers.migration.V275_EnsureDefaultAllChatsFolder
import org.thoughtcrime.securesms.database.SQLiteDatabase as SignalSqliteDatabase
/**
@@ -263,10 +264,11 @@ object SignalDatabaseMigrations {
271 to V271_AddNotificationProfileIdColumn,
272 to V272_UpdateUnreadCountIndices,
273 to V273_FixUnreadOriginalMessages,
274 to V274_BackupMediaSnapshotLastSeenOnRemote
274 to V274_BackupMediaSnapshotLastSeenOnRemote,
275 to V275_EnsureDefaultAllChatsFolder
)
const val DATABASE_VERSION = 274
const val DATABASE_VERSION = 275
@JvmStatic
fun migrate(context: Application, db: SignalSqliteDatabase, oldVersion: Int, newVersion: Int) {

View File

@@ -1,7 +1,7 @@
package org.thoughtcrime.securesms.database.helpers.migration
import android.app.Application
import org.thoughtcrime.securesms.database.ChatFolderTables
import androidx.core.content.contentValuesOf
import org.thoughtcrime.securesms.database.SQLiteDatabase
/**
@@ -42,6 +42,16 @@ object V253_CreateChatFolderTables : SignalDatabaseMigration {
db.execSQL("CREATE INDEX chat_folder_membership_thread_id_index ON chat_folder_membership (thread_id)")
db.execSQL("CREATE INDEX chat_folder_membership_membership_type_index ON chat_folder_membership (membership_type)")
ChatFolderTables.insertInitialChatFoldersAtCreationTime(db)
db.insert(
"chat_folder",
null,
contentValuesOf(
"position" to 0,
"folder_type" to 0,
"show_individual" to 1,
"show_groups" to 1,
"show_muted" to 1
)
)
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2025 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.database.helpers.migration
import android.app.Application
import org.signal.core.util.Base64
import org.thoughtcrime.securesms.database.SQLiteDatabase
import org.thoughtcrime.securesms.storage.StorageSyncHelper
import java.util.UUID
/**
* Ensures that there is a default 'All chat' within chat folders.
*/
object V275_EnsureDefaultAllChatsFolder : SignalDatabaseMigration {
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
db.execSQL(
"""
INSERT INTO chat_folder(position, folder_type, show_individual, show_groups, show_muted, chat_folder_id, storage_service_id)
SELECT '0', '0', '1', '1', '1', '${UUID.randomUUID()}', '${Base64.encodeWithPadding(StorageSyncHelper.generateKey())}'
WHERE NOT EXISTS (
SELECT 1
FROM chat_folder
WHERE folder_type = 0
LIMIT 1
);
""".trimIndent()
)
}
}