mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 18:00:02 +01:00
Remove avatar color from CallLink table.
This commit is contained in:
committed by
Cody Henthorne
parent
b9835584d8
commit
51222738df
@@ -18,7 +18,6 @@ import org.signal.core.util.requireInt
|
||||
import org.signal.core.util.requireLong
|
||||
import org.signal.core.util.requireNonNullBlob
|
||||
import org.signal.core.util.requireNonNullString
|
||||
import org.signal.core.util.requireString
|
||||
import org.signal.core.util.select
|
||||
import org.signal.core.util.update
|
||||
import org.signal.core.util.withinTransaction
|
||||
@@ -53,7 +52,6 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
const val RESTRICTIONS = "restrictions"
|
||||
const val REVOKED = "revoked"
|
||||
const val EXPIRATION = "expiration"
|
||||
const val AVATAR_COLOR = "avatar_color"
|
||||
const val RECIPIENT_ID = "recipient_id"
|
||||
|
||||
//language=sql
|
||||
@@ -67,7 +65,6 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
$RESTRICTIONS INTEGER NOT NULL,
|
||||
$REVOKED INTEGER NOT NULL,
|
||||
$EXPIRATION INTEGER NOT NULL,
|
||||
$AVATAR_COLOR TEXT NOT NULL,
|
||||
$RECIPIENT_ID INTEGER UNIQUE REFERENCES ${RecipientTable.TABLE_NAME} (${RecipientTable.ID}) ON DELETE CASCADE
|
||||
)
|
||||
"""
|
||||
@@ -76,7 +73,7 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
return contentValuesOf(
|
||||
NAME to name,
|
||||
RESTRICTIONS to restrictions.mapToInt(),
|
||||
EXPIRATION to expiration.toEpochMilli(),
|
||||
EXPIRATION to if (expiration == Instant.MAX) -1L else expiration.toEpochMilli(),
|
||||
REVOKED to revoked
|
||||
)
|
||||
}
|
||||
@@ -94,7 +91,7 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
callLink: CallLink
|
||||
) {
|
||||
writableDatabase.withinTransaction { db ->
|
||||
val recipientId = SignalDatabase.recipients.getOrInsertFromCallLinkRoomId(callLink.roomId, callLink.avatarColor)
|
||||
val recipientId = SignalDatabase.recipients.getOrInsertFromCallLinkRoomId(callLink.roomId)
|
||||
|
||||
db
|
||||
.insertInto(TABLE_NAME)
|
||||
@@ -174,8 +171,7 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
linkKeyBytes = callLinkRootKey.keyBytes,
|
||||
adminPassBytes = null
|
||||
),
|
||||
state = SignalCallLinkState(),
|
||||
avatarColor = AvatarColorHash.forCallLink(callLinkRootKey.keyBytes)
|
||||
state = SignalCallLinkState()
|
||||
)
|
||||
|
||||
insertCallLink(link)
|
||||
@@ -194,8 +190,7 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
recipientId = RecipientId.UNKNOWN,
|
||||
roomId = callLinkRoomId,
|
||||
credentials = null,
|
||||
state = SignalCallLinkState(),
|
||||
avatarColor = AvatarColor.random()
|
||||
state = SignalCallLinkState()
|
||||
)
|
||||
insertCallLink(link)
|
||||
return getCallLinkByRoomId(callLinkRoomId)!!
|
||||
@@ -327,8 +322,7 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
RECIPIENT_ID to data.recipientId.takeIf { it != RecipientId.UNKNOWN }?.toLong(),
|
||||
ROOM_ID to data.roomId.serialize(),
|
||||
ROOT_KEY to data.credentials?.linkKeyBytes,
|
||||
ADMIN_KEY to data.credentials?.adminPassBytes,
|
||||
AVATAR_COLOR to data.avatarColor.serialize()
|
||||
ADMIN_KEY to data.credentials?.adminPassBytes
|
||||
).apply {
|
||||
putAll(data.state.serialize())
|
||||
}
|
||||
@@ -356,9 +350,14 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
name = data.requireNonNullString(NAME),
|
||||
restrictions = data.requireInt(RESTRICTIONS).mapToRestrictions(),
|
||||
revoked = data.requireBoolean(REVOKED),
|
||||
expiration = Instant.ofEpochMilli(data.requireLong(EXPIRATION)).truncatedTo(ChronoUnit.DAYS)
|
||||
),
|
||||
avatarColor = AvatarColor.deserialize(data.requireString(AVATAR_COLOR))
|
||||
expiration = data.requireLong(EXPIRATION).let {
|
||||
if (it == -1L) {
|
||||
Instant.MAX
|
||||
} else {
|
||||
Instant.ofEpochMilli(it).truncatedTo(ChronoUnit.DAYS)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -375,9 +374,10 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
val recipientId: RecipientId,
|
||||
val roomId: CallLinkRoomId,
|
||||
val credentials: CallLinkCredentials?,
|
||||
val state: SignalCallLinkState,
|
||||
val avatarColor: AvatarColor
|
||||
)
|
||||
val state: SignalCallLinkState
|
||||
) {
|
||||
val avatarColor: AvatarColor = credentials?.let { AvatarColorHash.forCallLink(it.linkKeyBytes) } ?: AvatarColor.UNKNOWN
|
||||
}
|
||||
|
||||
override fun remapRecipient(fromId: RecipientId, toId: RecipientId) {
|
||||
writableDatabase.update(TABLE_NAME)
|
||||
|
||||
@@ -568,15 +568,14 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
).recipientId
|
||||
}
|
||||
|
||||
fun getOrInsertFromCallLinkRoomId(callLinkRoomId: CallLinkRoomId, avatarColor: AvatarColor): RecipientId {
|
||||
fun getOrInsertFromCallLinkRoomId(callLinkRoomId: CallLinkRoomId): RecipientId {
|
||||
return getOrInsertByColumn(
|
||||
CALL_LINK_ROOM_ID,
|
||||
callLinkRoomId.serialize(),
|
||||
contentValuesOf(
|
||||
GROUP_TYPE to GroupType.CALL_LINK.id,
|
||||
CALL_LINK_ROOM_ID to callLinkRoomId.serialize(),
|
||||
PROFILE_SHARING to 1,
|
||||
AVATAR_COLOR to avatarColor.serialize()
|
||||
PROFILE_SHARING to 1
|
||||
)
|
||||
).recipientId
|
||||
}
|
||||
|
||||
@@ -1794,7 +1794,8 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
||||
recipientSettings,
|
||||
null,
|
||||
false,
|
||||
group.isActive
|
||||
group.isActive,
|
||||
null
|
||||
)
|
||||
Recipient(recipientId, details, false)
|
||||
} ?: Recipient.live(recipientId).get()
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V193_BackCallLinksW
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V194_KyberPreKeyMigration
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V195_GroupMemberForeignKeyMigration
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V196_BackCallLinksWithRecipientV2
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V197_DropAvatarColorFromCallLinks
|
||||
|
||||
/**
|
||||
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
|
||||
@@ -60,7 +61,7 @@ object SignalDatabaseMigrations {
|
||||
|
||||
val TAG: String = Log.tag(SignalDatabaseMigrations.javaClass)
|
||||
|
||||
const val DATABASE_VERSION = 196
|
||||
const val DATABASE_VERSION = 197
|
||||
|
||||
@JvmStatic
|
||||
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
@@ -255,6 +256,10 @@ object SignalDatabaseMigrations {
|
||||
if (oldVersion < 196) {
|
||||
V196_BackCallLinksWithRecipientV2.migrate(context, db, oldVersion, newVersion)
|
||||
}
|
||||
|
||||
if (oldVersion < 197) {
|
||||
V197_DropAvatarColorFromCallLinks.migrate(context, db, oldVersion, newVersion)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2023 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.thoughtcrime.securesms.database.helpers.migration
|
||||
|
||||
import android.app.Application
|
||||
import net.zetetic.database.sqlcipher.SQLiteDatabase
|
||||
|
||||
/**
|
||||
* Because getting the color is a simple modulo operation, there is no need to store it in the database.
|
||||
*/
|
||||
object V197_DropAvatarColorFromCallLinks : SignalDatabaseMigration {
|
||||
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
db.execSQL("ALTER TABLE call_link DROP COLUMN avatar_color")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user