mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-03 15:05:24 +00:00
refactor: refactor ExpirationConfigurationDatabase to return a specific db config after removing config values that are in shared lib
This commit is contained in:
parent
87d76b21da
commit
7f4db64a5a
@ -111,7 +111,7 @@ class ExpirationSettingsViewModel(
|
||||
if (typeValue == 0) {
|
||||
typeValue = ExpirationType.DELETE_AFTER_READ_VALUE
|
||||
}
|
||||
val expiryType = typeValue.expiry()
|
||||
val expiryType = typeValue.expiryType()
|
||||
val expirationTimer = _selectedExpirationTimer.value?.value?.toIntOrNull() ?: 0
|
||||
val address = recipient.value?.address
|
||||
if (address == null || (expirationConfig?.typeRadioIndex() == typeValue && expirationConfig?.durationSeconds == expirationTimer)) {
|
||||
@ -188,7 +188,7 @@ fun ExpirationConfiguration?.typeRadioIndex(): Int {
|
||||
return if (expirationType == )
|
||||
}
|
||||
|
||||
fun Int.expiry(): ExpirationType? {
|
||||
fun Int.expiryType(): ExpirationType? {
|
||||
if (this == -1) return null
|
||||
TODO()
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package org.session.libsession.messaging.messages
|
||||
|
||||
import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType
|
||||
|
||||
class ExpirationConfiguration(
|
||||
data class ExpirationConfiguration(
|
||||
val threadId: Long = -1,
|
||||
val durationSeconds: Int = 0,
|
||||
val expirationType: ExpirationType? = null,
|
||||
@ -14,4 +14,9 @@ class ExpirationConfiguration(
|
||||
val isNewConfigEnabled = false /* TODO: System.currentTimeMillis() > 1_676_851_200_000 // 13/02/2023 */
|
||||
const val LAST_READ_TEST = 1673587663000L
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class ExpirationDatabaseConfiguration(
|
||||
val threadId: Long = -1,
|
||||
val updatedTimestampMs: Long
|
||||
)
|
Loading…
Reference in New Issue
Block a user