Store & submit spam reporting token from server.

This commit is contained in:
Nicholas
2023-02-02 10:03:56 -05:00
committed by Nicholas Tinsley
parent 6a8e82ef91
commit 72449fd73e
14 changed files with 128 additions and 21 deletions

View File

@@ -93,7 +93,8 @@ public class PushTable extends DatabaseTable {
cursor.getString(cursor.getColumnIndexOrThrow(SERVER_GUID)),
"",
true,
false);
false,
null);
}
} catch (IOException e) {
Log.w(TAG, e);
@@ -175,7 +176,8 @@ public class PushTable extends DatabaseTable {
serverGuid,
"",
true,
false);
false,
null);
} catch (IOException e) {
throw new AssertionError(e);
}

View File

@@ -186,6 +186,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
private const val NEEDS_PNI_SIGNATURE = "needs_pni_signature"
private const val UNREGISTERED_TIMESTAMP = "unregistered_timestamp"
private const val HIDDEN = "hidden"
const val REPORTING_TOKEN = "reporting_token"
@JvmField
val CREATE_TABLE =
@@ -246,7 +247,8 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
$DISTRIBUTION_LIST_ID INTEGER DEFAULT NULL,
$NEEDS_PNI_SIGNATURE INTEGER DEFAULT 0,
$UNREGISTERED_TIMESTAMP INTEGER DEFAULT 0,
$HIDDEN INTEGER DEFAULT 0
$HIDDEN INTEGER DEFAULT 0,
$REPORTING_TOKEN BLOB DEFAULT NULL
)
""".trimIndent()
@@ -308,7 +310,8 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
BADGES,
DISTRIBUTION_LIST_ID,
NEEDS_PNI_SIGNATURE,
HIDDEN
HIDDEN,
REPORTING_TOKEN
)
private val ID_PROJECTION = arrayOf(ID)
@@ -1721,6 +1724,31 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
return updated
}
fun setReportingToken(id: RecipientId, reportingToken: ByteArray) {
val values = ContentValues(1).apply {
put(REPORTING_TOKEN, reportingToken)
}
if (update(id, values)) {
ApplicationDependencies.getDatabaseObserver().notifyRecipientChanged(id)
}
}
fun getReportingToken(id: RecipientId): ByteArray? {
readableDatabase
.select(REPORTING_TOKEN)
.from(TABLE_NAME)
.where(ID_WHERE, id)
.run()
.use { cursor ->
if (cursor.moveToFirst()) {
return cursor.requireBlob(REPORTING_TOKEN)
} else {
return null
}
}
}
fun getSimilarRecipientIds(recipient: Recipient): List<RecipientId> {
val projection = SqlUtil.buildArgs(ID, "COALESCE(NULLIF($SYSTEM_JOINED_NAME, ''), NULLIF($PROFILE_JOINED_NAME, '')) AS checked_name")
val where = "checked_name = ? AND $HIDDEN = ?"

View File

@@ -33,6 +33,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V174_ReactionForeig
import org.thoughtcrime.securesms.database.helpers.migration.V175_FixFullTextSearchLink
import org.thoughtcrime.securesms.database.helpers.migration.V176_AddScheduledDateToQuoteIndex
import org.thoughtcrime.securesms.database.helpers.migration.V177_MessageSendLogTableCleanupMigration
import org.thoughtcrime.securesms.database.helpers.migration.V178_ReportingTokenColumnMigration
/**
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
@@ -41,7 +42,7 @@ object SignalDatabaseMigrations {
val TAG: String = Log.tag(SignalDatabaseMigrations.javaClass)
const val DATABASE_VERSION = 177
const val DATABASE_VERSION = 178
@JvmStatic
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
@@ -160,6 +161,10 @@ object SignalDatabaseMigrations {
if (oldVersion < 177) {
V177_MessageSendLogTableCleanupMigration.migrate(context, db, oldVersion, newVersion)
}
if (oldVersion < 178) {
V178_ReportingTokenColumnMigration.migrate(context, db, oldVersion, newVersion)
}
}
@JvmStatic

View File

@@ -0,0 +1,13 @@
package org.thoughtcrime.securesms.database.helpers.migration
import android.app.Application
import net.zetetic.database.sqlcipher.SQLiteDatabase
/**
* This adds a column to the Recipients table to store a spam reporting token.
*/
object V178_ReportingTokenColumnMigration : SignalDatabaseMigration {
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
db.execSQL("ALTER TABLE recipient ADD COLUMN reporting_token BLOB DEFAULT NULL")
}
}