mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Fix backup support for account wallpapers.
This commit is contained in:
@@ -53,10 +53,11 @@ class ArchiveImportExportTests {
|
||||
|
||||
@Test
|
||||
fun temp() {
|
||||
runTests { it == "chat_item_standard_message_standard_attachments_02.binproto" }
|
||||
runTests { it == "account_data_01.binproto" }
|
||||
}
|
||||
|
||||
@Test
|
||||
// Passing
|
||||
// @Test
|
||||
fun accountData() {
|
||||
runTests { it.startsWith("account_data_") }
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ import org.signal.core.util.toInt
|
||||
import org.thoughtcrime.securesms.attachments.AttachmentId
|
||||
import org.thoughtcrime.securesms.backup.v2.ImportState
|
||||
import org.thoughtcrime.securesms.backup.v2.proto.Chat
|
||||
import org.thoughtcrime.securesms.backup.v2.proto.ChatStyle
|
||||
import org.thoughtcrime.securesms.backup.v2.util.ChatStyleConverter
|
||||
import org.thoughtcrime.securesms.backup.v2.util.parseChatWallpaper
|
||||
import org.thoughtcrime.securesms.backup.v2.util.toLocal
|
||||
import org.thoughtcrime.securesms.backup.v2.util.toLocalAttachment
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors
|
||||
@@ -29,10 +29,7 @@ import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.database.ThreadTable
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.ChatColor
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.Wallpaper
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaper
|
||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaperFactory
|
||||
import org.thoughtcrime.securesms.wallpaper.UriChatWallpaper
|
||||
import java.io.Closeable
|
||||
|
||||
@@ -78,13 +75,7 @@ fun ThreadTable.restoreFromBackup(chat: Chat, recipientId: RecipientId, importSt
|
||||
}
|
||||
}
|
||||
|
||||
val chatWallpaper = chat.style?.parseChatWallpaper(wallpaperAttachmentId)?.let {
|
||||
if (chat.style.dimWallpaperInDarkMode) {
|
||||
ChatWallpaperFactory.updateWithDimming(it, ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
val chatWallpaper = chat.style?.parseChatWallpaper(wallpaperAttachmentId)
|
||||
|
||||
val threadId = writableDatabase
|
||||
.insertInto(ThreadTable.TABLE_NAME)
|
||||
@@ -161,15 +152,3 @@ class ChatExportIterator(private val cursor: Cursor, private val db: SignalDatab
|
||||
cursor.close()
|
||||
}
|
||||
}
|
||||
|
||||
private fun ChatStyle.parseChatWallpaper(wallpaperAttachmentId: AttachmentId?): ChatWallpaper? {
|
||||
if (this.wallpaperPreset != null) {
|
||||
return this.wallpaperPreset.toLocal()
|
||||
}
|
||||
|
||||
if (wallpaperAttachmentId != null) {
|
||||
return UriChatWallpaper(PartAuthority.getAttachmentDataUri(wallpaperAttachmentId), 0f)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -8,14 +8,18 @@ package org.thoughtcrime.securesms.backup.v2.processor
|
||||
import okio.ByteString.Companion.EMPTY
|
||||
import okio.ByteString.Companion.toByteString
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.attachments.AttachmentId
|
||||
import org.thoughtcrime.securesms.backup.v2.ImportState
|
||||
import org.thoughtcrime.securesms.backup.v2.database.restoreSelfFromBackup
|
||||
import org.thoughtcrime.securesms.backup.v2.database.restoreWallpaperAttachment
|
||||
import org.thoughtcrime.securesms.backup.v2.proto.AccountData
|
||||
import org.thoughtcrime.securesms.backup.v2.proto.ChatStyle
|
||||
import org.thoughtcrime.securesms.backup.v2.proto.Frame
|
||||
import org.thoughtcrime.securesms.backup.v2.stream.BackupFrameEmitter
|
||||
import org.thoughtcrime.securesms.backup.v2.util.ChatStyleConverter
|
||||
import org.thoughtcrime.securesms.backup.v2.util.parseChatWallpaper
|
||||
import org.thoughtcrime.securesms.backup.v2.util.toLocal
|
||||
import org.thoughtcrime.securesms.backup.v2.util.toLocalAttachment
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository
|
||||
import org.thoughtcrime.securesms.components.settings.app.usernamelinks.UsernameQrCodeColorScheme
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors
|
||||
@@ -156,11 +160,17 @@ object AccountDataProcessor {
|
||||
if (settings.defaultChatStyle != null) {
|
||||
val chatColors = settings.defaultChatStyle.toLocal(importState)
|
||||
SignalStore.chatColors.chatColors = chatColors
|
||||
if (SignalStore.wallpaper.wallpaper != null) {
|
||||
SignalStore.wallpaper.setDimInDarkTheme(settings.defaultChatStyle.dimWallpaperInDarkMode)
|
||||
|
||||
val wallpaperAttachmentId: AttachmentId? = settings.defaultChatStyle.wallpaperPhoto?.let { filePointer ->
|
||||
filePointer.toLocalAttachment(importState)?.let {
|
||||
SignalDatabase.attachments.restoreWallpaperAttachment(it)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO [backup] wallpaper
|
||||
SignalStore.wallpaper.wallpaper = settings.defaultChatStyle.parseChatWallpaper(wallpaperAttachmentId)
|
||||
} else {
|
||||
SignalStore.chatColors.chatColors = null
|
||||
SignalStore.wallpaper.wallpaper = null
|
||||
}
|
||||
|
||||
if (accountData.donationSubscriberData != null) {
|
||||
|
||||
@@ -13,11 +13,14 @@ import org.thoughtcrime.securesms.conversation.colors.ChatColors
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColorsPalette
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.Wallpaper
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority
|
||||
import org.thoughtcrime.securesms.mms.PartUriParser
|
||||
import org.thoughtcrime.securesms.util.UriUtil
|
||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaper
|
||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaperFactory
|
||||
import org.thoughtcrime.securesms.wallpaper.GradientChatWallpaper
|
||||
import org.thoughtcrime.securesms.wallpaper.SingleColorChatWallpaper
|
||||
import org.thoughtcrime.securesms.wallpaper.UriChatWallpaper
|
||||
|
||||
/**
|
||||
* Contains a collection of methods to chat styles to and from their archive format.
|
||||
@@ -174,6 +177,22 @@ fun ChatStyle.WallpaperPreset.toLocal(): ChatWallpaper? {
|
||||
}
|
||||
}
|
||||
|
||||
fun ChatStyle.parseChatWallpaper(wallpaperAttachmentId: AttachmentId?): ChatWallpaper? {
|
||||
val chatWallpaper = if (this.wallpaperPreset != null) {
|
||||
this.wallpaperPreset.toLocal()
|
||||
} else if (wallpaperAttachmentId != null) {
|
||||
UriChatWallpaper(PartAuthority.getAttachmentDataUri(wallpaperAttachmentId), 0f)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
return if (chatWallpaper != null && this.dimWallpaperInDarkMode) {
|
||||
ChatWallpaperFactory.updateWithDimming(chatWallpaper, ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME)
|
||||
} else {
|
||||
chatWallpaper
|
||||
}
|
||||
}
|
||||
|
||||
private fun Int.toRemoteWallpaperPreset(): ChatStyle.WallpaperPreset {
|
||||
return when (this) {
|
||||
SingleColorChatWallpaper.BLUSH.color -> ChatStyle.WallpaperPreset.SOLID_BLUSH
|
||||
|
||||
Reference in New Issue
Block a user