Do not include release notes in chat exports.

This commit is contained in:
Greyson Parrelli
2025-12-11 14:07:18 -05:00
parent 10133b16b3
commit e930a0f8ac
24 changed files with 266 additions and 46 deletions

View File

@@ -3168,6 +3168,10 @@ class AttachmentTable(
}
private fun buildAttachmentsThatNeedUploadQuery(transferStateFilter: String = "$ARCHIVE_TRANSFER_STATE IN (${ArchiveTransferState.NONE.value}, ${ArchiveTransferState.TEMPORARY_FAILURE.value})"): String {
val notReleaseChannelClause = SignalStore.releaseChannel.releaseChannelRecipientId?.let {
"(${MessageTable.TABLE_NAME}.${MessageTable.FROM_RECIPIENT_ID} != ${it.toLong()}) AND"
} ?: ""
return """
$transferStateFilter AND
$DATA_FILE NOT NULL AND
@@ -3176,6 +3180,7 @@ class AttachmentTable(
$TRANSFER_STATE = $TRANSFER_PROGRESS_DONE AND
(${MessageTable.STORY_TYPE} = 0 OR ${MessageTable.STORY_TYPE} IS NULL) AND
(${MessageTable.TABLE_NAME}.${MessageTable.EXPIRES_IN} <= 0 OR ${MessageTable.TABLE_NAME}.${MessageTable.EXPIRES_IN} > ${ChatItemArchiveExporter.EXPIRATION_CUTOFF.inWholeMilliseconds}) AND
$notReleaseChannelClause
$CONTENT_TYPE != '${MediaUtil.LONG_TEXT}' AND
${MessageTable.TABLE_NAME}.${MessageTable.VIEW_ONCE} = 0
"""

View File

@@ -151,6 +151,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V294_RemoveLastReso
import org.thoughtcrime.securesms.database.helpers.migration.V295_AddLastRestoreKeyTypeTableIfMissingMigration
import org.thoughtcrime.securesms.database.helpers.migration.V296_RemovePollVoteConstraint
import org.thoughtcrime.securesms.database.helpers.migration.V297_AddPinnedMessageColumns
import org.thoughtcrime.securesms.database.helpers.migration.V298_DoNotBackupReleaseNotes
import org.thoughtcrime.securesms.database.SQLiteDatabase as SignalSqliteDatabase
/**
@@ -308,10 +309,11 @@ object SignalDatabaseMigrations {
294 to V294_RemoveLastResortKeyTupleColumnConstraintMigration,
295 to V295_AddLastRestoreKeyTypeTableIfMissingMigration,
296 to V296_RemovePollVoteConstraint,
297 to V297_AddPinnedMessageColumns
297 to V297_AddPinnedMessageColumns,
298 to V298_DoNotBackupReleaseNotes
)
const val DATABASE_VERSION = 297
const val DATABASE_VERSION = 298
@JvmStatic
fun migrate(context: Application, db: SignalSqliteDatabase, oldVersion: Int, newVersion: Int) {

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2025 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.database.helpers.migration
import android.app.Application
import org.signal.core.util.SqlUtil
import org.signal.core.util.logging.Log
import org.signal.core.util.requireLong
import org.thoughtcrime.securesms.database.KeyValueDatabase
import org.thoughtcrime.securesms.database.SQLiteDatabase
object V298_DoNotBackupReleaseNotes : SignalDatabaseMigration {
private val TAG = Log.tag(V298_DoNotBackupReleaseNotes::class.java)
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
val releaseNoteRecipientId = getReleaseNoteRecipientId(context) ?: return
migrateWithRecipientId(db, releaseNoteRecipientId)
}
fun migrateWithRecipientId(db: SQLiteDatabase, releaseNoteRecipientId: Long) {
db.execSQL(
"""
UPDATE attachment
SET archive_transfer_state = 0
WHERE message_id IN (
SELECT _id FROM message WHERE from_recipient_id = $releaseNoteRecipientId
)
"""
)
}
private fun getReleaseNoteRecipientId(context: Application): Long? {
return if (KeyValueDatabase.exists(context)) {
val keyValueDatabase = KeyValueDatabase.getInstance(context).readableDatabase
keyValueDatabase.query("key_value", arrayOf("value"), "key = ?", SqlUtil.buildArgs("releasechannel.recipient_id"), null, null, null).use { cursor ->
if (cursor.moveToFirst()) {
cursor.requireLong("value")
} else {
Log.w(TAG, "Release note channel recipient ID not found in KV database!")
null
}
}
} else {
Log.w(TAG, "Pre-KV database, not doing anything.")
null
}
}
}