Add new My Story privacy settings.

This commit is contained in:
Cody Henthorne
2022-06-24 10:51:26 -04:00
parent ebc556801e
commit 9bc25132c3
58 changed files with 935 additions and 242 deletions

View File

@@ -55,11 +55,22 @@ fun Cursor.isNull(column: String): Boolean {
return CursorUtil.isNull(this, column)
}
inline fun <T> Cursor.readToList(mapper: (Cursor) -> T): List<T> {
fun <T> Cursor.requireObject(column: String, serializer: LongSerializer<T>): T {
return serializer.deserialize(CursorUtil.requireLong(this, column))
}
fun <T> Cursor.requireObject(column: String, serializer: StringSerializer<T>): T {
return serializer.deserialize(CursorUtil.requireString(this, column))
}
inline fun <T> Cursor.readToList(predicate: (T) -> Boolean = { true }, mapper: (Cursor) -> T): List<T> {
val list = mutableListOf<T>()
use {
while (moveToNext()) {
list += mapper(this)
val record = mapper(this)
if (predicate(record)) {
list += mapper(this)
}
}
}
return list

View File

@@ -7,6 +7,23 @@ import androidx.core.content.contentValuesOf
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteQueryBuilder
/**
* Begins a transaction on the `this` database, runs the provided [block] providing the `this` value as it's argument
* within the transaction, and then ends the transaction successfully.
*
* @return The value returned by [block] if any
*/
fun <T : SupportSQLiteDatabase, R> T.withinTransaction(block: (T) -> R): R {
beginTransaction()
try {
val toReturn = block(this)
setTransactionSuccessful()
return toReturn
} finally {
endTransaction()
}
}
fun SupportSQLiteDatabase.getTableRowCount(table: String): Int {
return this.query("SELECT COUNT(*) FROM $table").use {
if (it.moveToFirst()) {
@@ -224,4 +241,3 @@ class DeleteBuilderPart2(
return db.delete(tableName, where, whereArgs)
}
}

View File

@@ -0,0 +1,13 @@
package org.signal.core.util
/**
* Generic serialization interface for use with database and store operations.
*/
interface Serializer<T, R> {
fun serialize(data: T): R
fun deserialize(data: R): T
}
interface StringSerializer<T> : Serializer<T, String>
interface LongSerializer<T> : Serializer<T, Long>