Make epoch optional in backups and storage service.

This commit is contained in:
emir-signal
2025-08-08 10:50:24 -04:00
committed by Greyson Parrelli
parent 47faefaff7
commit c4c9fd9f65
7 changed files with 17 additions and 14 deletions

View File

@@ -6,7 +6,6 @@
package org.thoughtcrime.securesms.backup.v2.database
import android.database.Cursor
import okio.ByteString
import okio.ByteString.Companion.toByteString
import org.signal.core.util.nullIfEmpty
import org.signal.ringrtc.CallLinkState
@@ -41,7 +40,7 @@ class CallLinkArchiveExporter(private val cursor: Cursor) : Iterator<ArchiveReci
id = callLink.recipientId.toLong(),
callLink = CallLink(
rootKey = callLink.credentials!!.linkKeyBytes.toByteString(),
epoch = callLink.credentials.epochBytes?.toByteString() ?: ByteString.EMPTY,
epoch = callLink.credentials.epochBytes?.takeIf { it.isNotEmpty() }?.toByteString(),
adminKey = callLink.credentials.adminPassBytes?.toByteString()?.nullIfEmpty(),
name = callLink.state.name,
expirationMs = expirationTime.takeIf { it != Long.MAX_VALUE }?.clampToValidBackupRange() ?: 0,

View File

@@ -7,7 +7,6 @@ package org.thoughtcrime.securesms.backup.v2.importer
import org.signal.core.util.isEmpty
import org.signal.core.util.logging.Log
import org.signal.core.util.nullIfEmpty
import org.signal.ringrtc.CallLinkRootKey
import org.signal.ringrtc.CallLinkState
import org.thoughtcrime.securesms.backup.v2.ArchiveCallLink
@@ -45,7 +44,7 @@ object CallLinkArchiveImporter {
roomId = CallLinkRoomId.fromCallLinkRootKey(rootKey),
credentials = CallLinkCredentials(
callLink.rootKey.toByteArray(),
callLink.epoch?.nullIfEmpty()?.toByteArray(),
callLink.epoch?.toByteArray(),
callLink.adminKey?.toByteArray()
),
state = SignalCallLinkState(

View File

@@ -28,12 +28,14 @@ import org.thoughtcrime.securesms.calls.log.CallLogRow
import org.thoughtcrime.securesms.conversation.colors.AvatarColor
import org.thoughtcrime.securesms.conversation.colors.AvatarColorHash
import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.jobs.CallLinkUpdateSendJob
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.recipients.RecipientId
import org.thoughtcrime.securesms.service.webrtc.links.CallLinkCredentials
import org.thoughtcrime.securesms.service.webrtc.links.CallLinkRoomId
import org.thoughtcrime.securesms.service.webrtc.links.SignalCallLinkState
import org.whispersystems.signalservice.api.storage.StorageId
import org.whispersystems.signalservice.internal.push.SyncMessage
import java.time.Instant
import java.time.temporal.ChronoUnit
@@ -214,7 +216,14 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
return getCallLinkByRoomId(roomId)!!
} else {
if (callLink.credentials?.epoch != callLinkEpoch) {
overwriteEpoch(callLink, callLinkEpoch)
val modifiedCallLink = overwriteEpoch(callLink, callLinkEpoch)
AppDependencies.jobManager.add(
CallLinkUpdateSendJob(
callLink.credentials!!.roomId,
SyncMessage.CallLinkUpdate.Type.UPDATE
)
)
modifiedCallLink
} else {
callLink
}

View File

@@ -71,6 +71,7 @@ class CallLinkUpdateSendJob private constructor(
val callLinkUpdate = CallLinkUpdate(
rootKey = callLink.credentials.linkKeyBytes.toByteString(),
adminPasskey = callLink.credentials.adminPassBytes?.toByteString(),
epoch = callLink.credentials.epochBytes?.toByteString(),
type = callLinkUpdateType
)

View File

@@ -5,7 +5,6 @@
package org.thoughtcrime.securesms.storage
import okio.ByteString
import okio.ByteString.Companion.toByteString
import org.signal.core.util.isNotEmpty
import org.signal.core.util.logging.Log
@@ -48,10 +47,9 @@ class CallLinkRecordProcessor : DefaultStorageRecordProcessor<SignalCallLinkReco
val callLink = SignalDatabase.callLinks.getCallLinkByRoomId(roomId)
if (callLink != null && callLink.credentials?.adminPassBytes != null) {
val epochBytes = callLink.credentials.epochBytes
return SignalCallLinkRecord.newBuilder(null).apply {
rootKey = callRootKey.keyBytes.toByteString()
epoch = epochBytes?.toByteString() ?: ByteString.EMPTY
epoch = callLink.credentials.epochBytes?.toByteString()
adminPasskey = callLink.credentials.adminPassBytes.toByteString()
deletedAtTimestampMs = callLink.deletionTimestamp
}.build().toSignalCallLinkRecord(StorageId.forCallLink(keyGenerator.generate())).toOptional()
@@ -92,11 +90,7 @@ class CallLinkRecordProcessor : DefaultStorageRecordProcessor<SignalCallLinkReco
private fun insertOrUpdateRecord(record: SignalCallLinkRecord) {
val rootKey = CallLinkRootKey(record.proto.rootKey.toByteArray())
val epoch = if (record.proto.epoch.isNotEmpty()) {
CallLinkEpoch.fromBytes(record.proto.epoch.toByteArray())
} else {
null
}
val epoch = record.proto.epoch?.let { CallLinkEpoch.fromBytes(it.toByteArray()) }
SignalDatabase.callLinks.insertOrUpdateCallLinkByRootKey(
callLinkRootKey = rootKey,

View File

@@ -269,6 +269,7 @@ object StorageSyncModels {
return SignalCallLinkRecord.newBuilder(null).apply {
rootKey = callLink.credentials.linkKeyBytes.toByteString()
epoch = callLink.credentials.epochBytes?.toByteString()
adminPasskey = adminPassword.toByteString()
deletedAtTimestampMs = deletedTimestamp
}.build().toSignalCallLinkRecord(StorageId.forCallLink(rawStorageId))

View File

@@ -306,7 +306,7 @@ message CallLinkRecord {
bytes rootKey = 1;
bytes adminPasskey = 2;
uint64 deletedAtTimestampMs = 3;
bytes epoch = 4;
optional bytes epoch = 4;
}
message Recipient {