mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 18:00:02 +01:00
Remove cruft around SignalAccountRecord.
This commit is contained in:
@@ -17,8 +17,11 @@ import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.delete
|
||||
import org.signal.core.util.exists
|
||||
import org.signal.core.util.forEach
|
||||
import org.signal.core.util.hasUnknownFields
|
||||
import org.signal.core.util.isNotEmpty
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.core.util.nullIfBlank
|
||||
import org.signal.core.util.nullIfEmpty
|
||||
import org.signal.core.util.optionalString
|
||||
import org.signal.core.util.or
|
||||
import org.signal.core.util.orNull
|
||||
@@ -1024,12 +1027,13 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
}
|
||||
|
||||
fun applyStorageSyncAccountUpdate(update: StorageRecordUpdate<SignalAccountRecord>) {
|
||||
val profileName = ProfileName.fromParts(update.new.givenName.orElse(null), update.new.familyName.orElse(null))
|
||||
val localKey = ProfileKeyUtil.profileKeyOptional(update.old.profileKey.orElse(null))
|
||||
val remoteKey = ProfileKeyUtil.profileKeyOptional(update.new.profileKey.orElse(null))
|
||||
val profileKey: String? = remoteKey.or(localKey).map { obj: ProfileKey -> obj.serialize() }.map { source: ByteArray? -> Base64.encodeWithPadding(source!!) }.orElse(null)
|
||||
if (!remoteKey.isPresent) {
|
||||
Log.w(TAG, "Got an empty profile key while applying an account record update! The parsed local key is ${if (localKey.isPresent) "present" else "not present"}. The raw local key is ${if (update.old.profileKey.isPresent) "present" else "not present"}. The resulting key is ${if (profileKey != null) "present" else "not present"}.")
|
||||
val profileName = ProfileName.fromParts(update.new.proto.givenName, update.new.proto.familyName)
|
||||
val localKey = update.old.proto.profileKey.nullIfEmpty()?.toByteArray()?.let { ProfileKeyUtil.profileKeyOrNull(it) }
|
||||
val remoteKey = update.new.proto.profileKey.nullIfEmpty()?.toByteArray()?.let { ProfileKeyUtil.profileKeyOrNull(it) }
|
||||
val profileKey: String? = (remoteKey ?: localKey)?.let { Base64.encodeWithPadding(it.serialize()) }
|
||||
|
||||
if (remoteKey == null) {
|
||||
Log.w(TAG, "Got an empty profile key while applying an account record update! The parsed local key is ${if (localKey != null) "present" else "not present"}. The raw local key is ${if (update.old.proto.profileKey.isNotEmpty()) "present" else "not present"}. The resulting key is ${if (profileKey != null) "present" else "not present"}.")
|
||||
}
|
||||
|
||||
val values = ContentValues().apply {
|
||||
@@ -1043,21 +1047,21 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
Log.w(TAG, "Avoided attempt to apply null profile key in account record update!")
|
||||
}
|
||||
|
||||
put(USERNAME, update.new.username)
|
||||
put(USERNAME, update.new.proto.username.nullIfBlank())
|
||||
put(STORAGE_SERVICE_ID, Base64.encodeWithPadding(update.new.id.raw))
|
||||
|
||||
if (update.new.hasUnknownFields()) {
|
||||
put(STORAGE_SERVICE_PROTO, Base64.encodeWithPadding(Objects.requireNonNull(update.new.serializeUnknownFields())))
|
||||
if (update.new.proto.hasUnknownFields()) {
|
||||
put(STORAGE_SERVICE_PROTO, Base64.encodeWithPadding(update.new.serializeUnknownFields()!!))
|
||||
} else {
|
||||
putNull(STORAGE_SERVICE_PROTO)
|
||||
}
|
||||
}
|
||||
|
||||
if (update.new.username != null) {
|
||||
if (update.new.proto.username.nullIfBlank() != null) {
|
||||
writableDatabase
|
||||
.update(TABLE_NAME)
|
||||
.values(USERNAME to null)
|
||||
.where("$USERNAME = ?", update.new.username!!)
|
||||
.where("$USERNAME = ?", update.new.proto.username)
|
||||
.run()
|
||||
}
|
||||
|
||||
|
||||
@@ -71,10 +71,11 @@ import org.thoughtcrime.securesms.util.LRUCache
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.thoughtcrime.securesms.util.isScheduled
|
||||
import org.whispersystems.signalservice.api.storage.SignalAccountRecord
|
||||
import org.whispersystems.signalservice.api.storage.SignalAccountRecord.PinnedConversation
|
||||
import org.whispersystems.signalservice.api.storage.SignalContactRecord
|
||||
import org.whispersystems.signalservice.api.storage.SignalGroupV1Record
|
||||
import org.whispersystems.signalservice.api.storage.SignalGroupV2Record
|
||||
import org.whispersystems.signalservice.api.storage.toSignalServiceAddress
|
||||
import org.whispersystems.signalservice.internal.storage.protos.AccountRecord
|
||||
import java.io.Closeable
|
||||
import java.io.IOException
|
||||
import java.util.Collections
|
||||
@@ -1522,7 +1523,7 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
||||
|
||||
fun applyStorageSyncUpdate(recipientId: RecipientId, record: SignalAccountRecord) {
|
||||
writableDatabase.withinTransaction { db ->
|
||||
applyStorageSyncUpdate(recipientId, record.isNoteToSelfArchived, record.isNoteToSelfForcedUnread)
|
||||
applyStorageSyncUpdate(recipientId, record.proto.noteToSelfArchived, record.proto.noteToSelfMarkedUnread)
|
||||
|
||||
db.updateAll(TABLE_NAME)
|
||||
.values(PINNED to 0)
|
||||
@@ -1530,19 +1531,19 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
||||
|
||||
var pinnedPosition = 1
|
||||
|
||||
for (pinned: PinnedConversation in record.pinnedConversations) {
|
||||
val pinnedRecipient: Recipient? = if (pinned.contact.isPresent) {
|
||||
Recipient.externalPush(pinned.contact.get())
|
||||
} else if (pinned.groupV1Id.isPresent) {
|
||||
for (pinned: AccountRecord.PinnedConversation in record.proto.pinnedConversations) {
|
||||
val pinnedRecipient: Recipient? = if (pinned.contact != null) {
|
||||
Recipient.externalPush(pinned.contact!!.toSignalServiceAddress())
|
||||
} else if (pinned.legacyGroupId != null) {
|
||||
try {
|
||||
Recipient.externalGroupExact(GroupId.v1(pinned.groupV1Id.get()))
|
||||
Recipient.externalGroupExact(GroupId.v1(pinned.legacyGroupId!!.toByteArray()))
|
||||
} catch (e: BadGroupIdException) {
|
||||
Log.w(TAG, "Failed to parse pinned groupV1 ID!", e)
|
||||
null
|
||||
}
|
||||
} else if (pinned.groupV2MasterKey.isPresent) {
|
||||
} else if (pinned.groupMasterKey != null) {
|
||||
try {
|
||||
Recipient.externalGroupExact(GroupId.v2(GroupMasterKey(pinned.groupV2MasterKey.get())))
|
||||
Recipient.externalGroupExact(GroupId.v2(GroupMasterKey(pinned.groupMasterKey!!.toByteArray())))
|
||||
} catch (e: InvalidInputException) {
|
||||
Log.w(TAG, "Failed to parse pinned groupV2 master key!", e)
|
||||
null
|
||||
|
||||
Reference in New Issue
Block a user