Skip to content

Commit

Permalink
Limit wallpaper uploading to media tier.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtang-signal authored and greyson-signal committed Dec 12, 2024
1 parent e45a3fb commit 57502fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.thoughtcrime.securesms.database.RecipientTable
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.database.ThreadTable

fun ThreadTable.getThreadsForBackup(db: SignalDatabase): ChatArchiveExporter {
fun ThreadTable.getThreadsForBackup(db: SignalDatabase, includeImageWallpapers: Boolean): ChatArchiveExporter {
//language=sql
val query = """
SELECT
Expand All @@ -40,7 +40,7 @@ fun ThreadTable.getThreadsForBackup(db: SignalDatabase): ChatArchiveExporter {
"""
val cursor = readableDatabase.query(query)

return ChatArchiveExporter(cursor, db)
return ChatArchiveExporter(cursor, db, includeImageWallpapers)
}

fun ThreadTable.getThreadGroupStatus(messageIds: Collection<Long>): Map<Long, Boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.thoughtcrime.securesms.database.model.databaseprotos.Wallpaper
import java.io.Closeable
import kotlin.time.Duration.Companion.seconds

class ChatArchiveExporter(private val cursor: Cursor, private val db: SignalDatabase) : Iterator<Chat>, Closeable {
class ChatArchiveExporter(private val cursor: Cursor, private val db: SignalDatabase, private val includeImageWallpapers: Boolean) : Iterator<Chat>, Closeable {
override fun hasNext(): Boolean {
return cursor.count > 0 && !cursor.isLast
}
Expand All @@ -40,7 +40,14 @@ class ChatArchiveExporter(private val cursor: Cursor, private val db: SignalData
}

val chatWallpaper: Wallpaper? = cursor.requireBlob(RecipientTable.WALLPAPER)?.let { serializedWallpaper ->
Wallpaper.ADAPTER.decodeOrNull(serializedWallpaper)
val wallpaper = Wallpaper.ADAPTER.decodeOrNull(serializedWallpaper)
val isImageWallpaper = wallpaper?.file_ != null

if (includeImageWallpapers || !isImageWallpaper) {
wallpaper
} else {
null
}
}

return Chat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ package org.thoughtcrime.securesms.backup.v2.processor
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.backup.v2.ExportState
import org.thoughtcrime.securesms.backup.v2.ImportState
import org.thoughtcrime.securesms.backup.v2.MessageBackupTier
import org.thoughtcrime.securesms.backup.v2.database.getThreadsForBackup
import org.thoughtcrime.securesms.backup.v2.importer.ChatArchiveImporter
import org.thoughtcrime.securesms.backup.v2.proto.Chat
import org.thoughtcrime.securesms.backup.v2.proto.Frame
import org.thoughtcrime.securesms.backup.v2.stream.BackupFrameEmitter
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.recipients.RecipientId

/**
Expand All @@ -23,7 +25,10 @@ object ChatArchiveProcessor {
val TAG = Log.tag(ChatArchiveProcessor::class.java)

fun export(db: SignalDatabase, exportState: ExportState, emitter: BackupFrameEmitter) {
db.threadTable.getThreadsForBackup(db).use { reader ->
val includeImageWallpapers = SignalStore.backup.backupTier == MessageBackupTier.PAID
Log.i(TAG, "Including wallpapers: $includeImageWallpapers")

db.threadTable.getThreadsForBackup(db, includeImageWallpapers).use { reader ->
for (chat in reader) {
if (exportState.recipientIds.contains(chat.recipientId)) {
exportState.threadIds.add(chat.id)
Expand Down

0 comments on commit 57502fb

Please sign in to comment.