mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Add notification profile id for backupsv2.
This commit is contained in:
@@ -11,12 +11,14 @@ import org.signal.core.util.logging.Log
|
||||
import org.signal.core.util.requireBoolean
|
||||
import org.signal.core.util.requireInt
|
||||
import org.signal.core.util.requireLong
|
||||
import org.signal.core.util.requireNonNullString
|
||||
import org.signal.core.util.requireString
|
||||
import org.signal.core.util.toInt
|
||||
import org.signal.core.util.update
|
||||
import org.thoughtcrime.securesms.conversation.colors.AvatarColor
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.thoughtcrime.securesms.notifications.profiles.NotificationProfile
|
||||
import org.thoughtcrime.securesms.notifications.profiles.NotificationProfileId
|
||||
import org.thoughtcrime.securesms.notifications.profiles.NotificationProfileSchedule
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import java.time.DayOfWeek
|
||||
@@ -46,6 +48,7 @@ class NotificationProfileTables(context: Context, databaseHelper: SignalDatabase
|
||||
const val CREATED_AT = "created_at"
|
||||
const val ALLOW_ALL_CALLS = "allow_all_calls"
|
||||
const val ALLOW_ALL_MENTIONS = "allow_all_mentions"
|
||||
const val NOTIFICATION_PROFILE_ID = "notification_profile_id"
|
||||
|
||||
val CREATE_TABLE = """
|
||||
CREATE TABLE $TABLE_NAME (
|
||||
@@ -55,7 +58,8 @@ class NotificationProfileTables(context: Context, databaseHelper: SignalDatabase
|
||||
$COLOR TEXT NOT NULL,
|
||||
$CREATED_AT INTEGER NOT NULL,
|
||||
$ALLOW_ALL_CALLS INTEGER NOT NULL DEFAULT 0,
|
||||
$ALLOW_ALL_MENTIONS INTEGER NOT NULL DEFAULT 0
|
||||
$ALLOW_ALL_MENTIONS INTEGER NOT NULL DEFAULT 0,
|
||||
$NOTIFICATION_PROFILE_ID TEXT DEFAULT NULL
|
||||
)
|
||||
"""
|
||||
}
|
||||
@@ -110,12 +114,14 @@ class NotificationProfileTables(context: Context, databaseHelper: SignalDatabase
|
||||
|
||||
db.beginTransaction()
|
||||
try {
|
||||
val notificationProfileId = NotificationProfileId.generate()
|
||||
val profileValues = ContentValues().apply {
|
||||
put(NotificationProfileTable.NAME, name)
|
||||
put(NotificationProfileTable.EMOJI, emoji)
|
||||
put(NotificationProfileTable.COLOR, color.serialize())
|
||||
put(NotificationProfileTable.CREATED_AT, createdAt)
|
||||
put(NotificationProfileTable.ALLOW_ALL_CALLS, 1)
|
||||
put(NotificationProfileTable.NOTIFICATION_PROFILE_ID, notificationProfileId.serialize())
|
||||
}
|
||||
|
||||
val profileId = db.insert(NotificationProfileTable.TABLE_NAME, null, profileValues)
|
||||
@@ -140,7 +146,8 @@ class NotificationProfileTables(context: Context, databaseHelper: SignalDatabase
|
||||
emoji = emoji,
|
||||
createdAt = createdAt,
|
||||
schedule = getProfileSchedule(profileId),
|
||||
allowAllCalls = true
|
||||
allowAllCalls = true,
|
||||
notificationProfileId = notificationProfileId
|
||||
)
|
||||
)
|
||||
} finally {
|
||||
@@ -323,7 +330,8 @@ class NotificationProfileTables(context: Context, databaseHelper: SignalDatabase
|
||||
allowAllCalls = cursor.requireBoolean(NotificationProfileTable.ALLOW_ALL_CALLS),
|
||||
allowAllMentions = cursor.requireBoolean(NotificationProfileTable.ALLOW_ALL_MENTIONS),
|
||||
schedule = getProfileSchedule(profileId),
|
||||
allowedMembers = getProfileAllowedMembers(profileId)
|
||||
allowedMembers = getProfileAllowedMembers(profileId),
|
||||
notificationProfileId = NotificationProfileId.from(cursor.requireNonNullString(NotificationProfileTable.NOTIFICATION_PROFILE_ID))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -125,6 +125,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V267_FixGroupInvita
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V268_FixInAppPaymentsErrorStateConsistency
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V269_BackupMediaSnapshotChanges
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V270_FixChatFolderColumnsForStorageSync
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V271_AddNotificationProfileIdColumn
|
||||
import org.thoughtcrime.securesms.database.SQLiteDatabase as SignalSqliteDatabase
|
||||
|
||||
/**
|
||||
@@ -255,10 +256,11 @@ object SignalDatabaseMigrations {
|
||||
267 to V267_FixGroupInvitationDeclinedUpdate,
|
||||
268 to V268_FixInAppPaymentsErrorStateConsistency,
|
||||
269 to V269_BackupMediaSnapshotChanges,
|
||||
270 to V270_FixChatFolderColumnsForStorageSync
|
||||
270 to V270_FixChatFolderColumnsForStorageSync,
|
||||
271 to V271_AddNotificationProfileIdColumn
|
||||
)
|
||||
|
||||
const val DATABASE_VERSION = 270
|
||||
const val DATABASE_VERSION = 271
|
||||
|
||||
@JvmStatic
|
||||
fun migrate(context: Application, db: SignalSqliteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.readToList
|
||||
import org.signal.core.util.requireLong
|
||||
import org.thoughtcrime.securesms.database.SQLiteDatabase
|
||||
import java.util.UUID
|
||||
|
||||
/**
|
||||
* Add notification_profile_id column to Notification Profiles to support backups.
|
||||
*/
|
||||
@Suppress("ClassName")
|
||||
object V271_AddNotificationProfileIdColumn : SignalDatabaseMigration {
|
||||
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
db.execSQL("ALTER TABLE notification_profile ADD COLUMN notification_profile_id TEXT DEFAULT NULL")
|
||||
|
||||
db.rawQuery("SELECT _id FROM notification_profile")
|
||||
.readToList { it.requireLong("_id") }
|
||||
.forEach { id ->
|
||||
db.execSQL("UPDATE notification_profile SET notification_profile_id = '${UUID.randomUUID()}' WHERE _id = $id")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user