|
|
|
@ -4,6 +4,7 @@ import android.content.ContentValues
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.database.Cursor
|
|
|
|
|
import org.session.libsession.messaging.messages.ExpirationConfiguration
|
|
|
|
|
import org.session.libsession.messaging.messages.ExpirationDatabaseConfiguration
|
|
|
|
|
import org.session.libsession.utilities.GroupUtil.CLOSED_GROUP_PREFIX
|
|
|
|
|
import org.session.libsession.utilities.GroupUtil.OPEN_GROUP_INBOX_PREFIX
|
|
|
|
|
import org.session.libsession.utilities.GroupUtil.OPEN_GROUP_PREFIX
|
|
|
|
@ -14,23 +15,19 @@ class ExpirationConfigurationDatabase(context: Context, helper: SQLCipherOpenHel
|
|
|
|
|
companion object {
|
|
|
|
|
const val TABLE_NAME = "expiration_configuration"
|
|
|
|
|
const val THREAD_ID = "thread_id"
|
|
|
|
|
const val DURATION_SECONDS = "duration_seconds"
|
|
|
|
|
const val EXPIRATION_TYPE = "expiration_type"
|
|
|
|
|
const val UPDATED_TIMESTAMP_MS = "updated_timestamp_ms"
|
|
|
|
|
|
|
|
|
|
@JvmField
|
|
|
|
|
val CREATE_EXPIRATION_CONFIGURATION_TABLE_COMMAND = """
|
|
|
|
|
CREATE TABLE $TABLE_NAME (
|
|
|
|
|
$THREAD_ID INTEGER NOT NULL PRIMARY KEY ON CONFLICT REPLACE,
|
|
|
|
|
$DURATION_SECONDS INTEGER NOT NULL,
|
|
|
|
|
$EXPIRATION_TYPE INTEGER DEFAULT NULL,
|
|
|
|
|
$UPDATED_TIMESTAMP_MS INTEGER DEFAULT NULL
|
|
|
|
|
)
|
|
|
|
|
""".trimIndent()
|
|
|
|
|
|
|
|
|
|
@JvmField
|
|
|
|
|
val MIGRATE_GROUP_CONVERSATION_EXPIRY_TYPE_COMMAND = """
|
|
|
|
|
INSERT INTO $TABLE_NAME ($THREAD_ID, $DURATION_SECONDS, $EXPIRATION_TYPE) SELECT ${ThreadDatabase.TABLE_NAME}.${ThreadDatabase.ID}, ${RecipientDatabase.EXPIRE_MESSAGES}, 1
|
|
|
|
|
INSERT INTO $TABLE_NAME ($THREAD_ID) SELECT ${ThreadDatabase.TABLE_NAME}.${ThreadDatabase.ID}, ${RecipientDatabase.EXPIRE_MESSAGES}, 1
|
|
|
|
|
FROM ${ThreadDatabase.TABLE_NAME}, ${RecipientDatabase.TABLE_NAME}
|
|
|
|
|
WHERE ${ThreadDatabase.TABLE_NAME}.${ThreadDatabase.ADDRESS} LIKE '$CLOSED_GROUP_PREFIX%'
|
|
|
|
|
AND EXISTS (SELECT ${RecipientDatabase.EXPIRE_MESSAGES} FROM ${RecipientDatabase.TABLE_NAME} WHERE ${ThreadDatabase.TABLE_NAME}.${ThreadDatabase.ADDRESS} = ${RecipientDatabase.TABLE_NAME}.${RecipientDatabase.ADDRESS} AND ${RecipientDatabase.EXPIRE_MESSAGES} > 0)
|
|
|
|
@ -38,7 +35,7 @@ class ExpirationConfigurationDatabase(context: Context, helper: SQLCipherOpenHel
|
|
|
|
|
|
|
|
|
|
@JvmField
|
|
|
|
|
val MIGRATE_ONE_TO_ONE_CONVERSATION_EXPIRY_TYPE_COMMAND = """
|
|
|
|
|
INSERT INTO $TABLE_NAME ($THREAD_ID, $DURATION_SECONDS, $EXPIRATION_TYPE) SELECT ${ThreadDatabase.TABLE_NAME}.${ThreadDatabase.ID}, ${RecipientDatabase.EXPIRE_MESSAGES}, 2
|
|
|
|
|
INSERT INTO $TABLE_NAME ($THREAD_ID) SELECT ${ThreadDatabase.TABLE_NAME}.${ThreadDatabase.ID}, ${RecipientDatabase.EXPIRE_MESSAGES}, 2
|
|
|
|
|
FROM ${ThreadDatabase.TABLE_NAME}, ${RecipientDatabase.TABLE_NAME}
|
|
|
|
|
WHERE ${ThreadDatabase.TABLE_NAME}.${ThreadDatabase.ADDRESS} NOT LIKE '$CLOSED_GROUP_PREFIX%'
|
|
|
|
|
AND ${ThreadDatabase.TABLE_NAME}.${ThreadDatabase.ADDRESS} NOT LIKE '$OPEN_GROUP_PREFIX%'
|
|
|
|
@ -46,21 +43,19 @@ class ExpirationConfigurationDatabase(context: Context, helper: SQLCipherOpenHel
|
|
|
|
|
AND EXISTS (SELECT ${RecipientDatabase.EXPIRE_MESSAGES} FROM ${RecipientDatabase.TABLE_NAME} WHERE ${ThreadDatabase.TABLE_NAME}.${ThreadDatabase.ADDRESS} = ${RecipientDatabase.TABLE_NAME}.${RecipientDatabase.ADDRESS} AND ${RecipientDatabase.EXPIRE_MESSAGES} > 0)
|
|
|
|
|
""".trimIndent()
|
|
|
|
|
|
|
|
|
|
private fun readExpirationConfiguration(cursor: Cursor): ExpirationConfiguration {
|
|
|
|
|
return ExpirationConfiguration(
|
|
|
|
|
private fun readExpirationConfiguration(cursor: Cursor): ExpirationDatabaseConfiguration {
|
|
|
|
|
return ExpirationDatabaseConfiguration(
|
|
|
|
|
threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID)),
|
|
|
|
|
durationSeconds = cursor.getInt(cursor.getColumnIndexOrThrow(DURATION_SECONDS)),
|
|
|
|
|
expirationTypeValue = cursor.getInt(cursor.getColumnIndexOrThrow(EXPIRATION_TYPE)),
|
|
|
|
|
updatedTimestampMs = cursor.getLong(cursor.getColumnIndexOrThrow(UPDATED_TIMESTAMP_MS))
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun getExpirationConfiguration(threadId: Long): ExpirationConfiguration? {
|
|
|
|
|
fun getExpirationConfiguration(threadId: Long): ExpirationDatabaseConfiguration? {
|
|
|
|
|
val query = "$THREAD_ID = ?"
|
|
|
|
|
val args = arrayOf("$threadId")
|
|
|
|
|
|
|
|
|
|
val configurations: MutableList<ExpirationConfiguration> = mutableListOf()
|
|
|
|
|
val configurations: MutableList<ExpirationDatabaseConfiguration> = mutableListOf()
|
|
|
|
|
|
|
|
|
|
readableDatabase.query(TABLE_NAME, null, query, args, null, null, null).use { cursor ->
|
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
@ -76,8 +71,6 @@ class ExpirationConfigurationDatabase(context: Context, helper: SQLCipherOpenHel
|
|
|
|
|
try {
|
|
|
|
|
val values = ContentValues().apply {
|
|
|
|
|
put(THREAD_ID, configuration.threadId)
|
|
|
|
|
put(DURATION_SECONDS, configuration.durationSeconds)
|
|
|
|
|
put(EXPIRATION_TYPE, configuration.expirationTypeValue)
|
|
|
|
|
put(UPDATED_TIMESTAMP_MS, configuration.updatedTimestampMs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|