mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 17:57:47 +00:00
Make the message trimming behaviour consistent across platform (#936)
* refactor: remove old trim behaviour and create new defaults * refactor: add in trimming by before time * refactor: remove old trim thread job, remove message processor scheduling trim thread * refactor: remove spacing * refactor: enable trimming by default * refactor: remove trim now option in chat preference
This commit is contained in:
@@ -151,6 +151,8 @@ interface StorageProtocol {
|
||||
fun getThreadIdForMms(mmsId: Long): Long
|
||||
fun getLastUpdated(threadID: Long): Long
|
||||
fun trimThread(threadID: Long, threadLimit: Int)
|
||||
fun trimThreadBefore(threadID: Long, timestamp: Long)
|
||||
fun getMessageCount(threadID: Long): Long
|
||||
|
||||
// Contacts
|
||||
fun getContactWithSessionID(sessionID: String): Contact?
|
||||
|
@@ -31,7 +31,6 @@ class JobQueue : JobDelegate {
|
||||
private val scope = CoroutineScope(Dispatchers.Default) + SupervisorJob()
|
||||
private val queue = Channel<Job>(UNLIMITED)
|
||||
private val pendingJobIds = mutableSetOf<String>()
|
||||
private val pendingTrimThreadIds = mutableSetOf<Long>()
|
||||
|
||||
private val openGroupChannels = mutableMapOf<String, Channel<Job>>()
|
||||
|
||||
@@ -115,15 +114,6 @@ class JobQueue : JobDelegate {
|
||||
val openGroupJob = processWithOpenGroupDispatcher(openGroupQueue, openGroupDispatcher, "openGroup")
|
||||
|
||||
while (isActive) {
|
||||
if (queue.isEmpty && pendingTrimThreadIds.isNotEmpty()) {
|
||||
// process trim thread jobs
|
||||
val pendingThreads = pendingTrimThreadIds.toList()
|
||||
pendingTrimThreadIds.clear()
|
||||
for (thread in pendingThreads) {
|
||||
Log.d("Loki", "Trimming thread $thread")
|
||||
queue.trySend(TrimThreadJob(thread, null))
|
||||
}
|
||||
}
|
||||
when (val job = queue.receive()) {
|
||||
is NotifyPNServerJob, is AttachmentUploadJob, is MessageSendJob -> {
|
||||
txQueue.send(job)
|
||||
@@ -165,10 +155,6 @@ class JobQueue : JobDelegate {
|
||||
val shared: JobQueue by lazy { JobQueue() }
|
||||
}
|
||||
|
||||
fun queueThreadForTrim(threadId: Long) {
|
||||
pendingTrimThreadIds += threadId
|
||||
}
|
||||
|
||||
fun add(job: Job) {
|
||||
addWithoutExecuting(job)
|
||||
queue.trySend(job) // offer always called on unlimited capacity
|
||||
|
@@ -15,14 +15,19 @@ class TrimThreadJob(val threadId: Long, val openGroupId: String?) : Job {
|
||||
const val KEY: String = "TrimThreadJob"
|
||||
const val THREAD_ID = "thread_id"
|
||||
const val OPEN_GROUP_ID = "open_group"
|
||||
|
||||
const val TRIM_TIME_LIMIT = 15552000000L // trim messages older than this
|
||||
const val THREAD_LENGTH_TRIGGER_SIZE = 2000
|
||||
}
|
||||
|
||||
override fun execute() {
|
||||
val context = MessagingModuleConfiguration.shared.context
|
||||
val trimmingEnabled = TextSecurePreferences.isThreadLengthTrimmingEnabled(context)
|
||||
val threadLengthLimit = TextSecurePreferences.getThreadTrimLength(context)
|
||||
if (trimmingEnabled) {
|
||||
MessagingModuleConfiguration.shared.storage.trimThread(threadId, threadLengthLimit)
|
||||
val storage = MessagingModuleConfiguration.shared.storage
|
||||
val messageCount = storage.getMessageCount(threadId)
|
||||
if (trimmingEnabled && !openGroupId.isNullOrEmpty() && messageCount >= THREAD_LENGTH_TRIGGER_SIZE) {
|
||||
val oldestMessageTime = System.currentTimeMillis() - TRIM_TIME_LIMIT
|
||||
storage.trimThreadBefore(threadId, oldestMessageTime)
|
||||
}
|
||||
delegate?.handleJobSucceeded(this)
|
||||
}
|
||||
|
@@ -117,7 +117,6 @@ interface TextSecurePreferences {
|
||||
fun getNotificationLedPattern(): String?
|
||||
fun getNotificationLedPatternCustom(): String?
|
||||
fun isThreadLengthTrimmingEnabled(): Boolean
|
||||
fun getThreadTrimLength(): Int
|
||||
fun isSystemEmojiPreferred(): Boolean
|
||||
fun getMobileMediaDownloadAllowed(): Set<String>?
|
||||
fun getWifiMediaDownloadAllowed(): Set<String>?
|
||||
@@ -175,7 +174,6 @@ interface TextSecurePreferences {
|
||||
|
||||
const val DISABLE_PASSPHRASE_PREF = "pref_disable_passphrase"
|
||||
const val LANGUAGE_PREF = "pref_language"
|
||||
const val THREAD_TRIM_LENGTH = "pref_trim_length"
|
||||
const val THREAD_TRIM_NOW = "pref_trim_now"
|
||||
const val LAST_VERSION_CODE_PREF = "last_version_code"
|
||||
const val RINGTONE_PREF = "pref_key_ringtone"
|
||||
@@ -705,12 +703,7 @@ interface TextSecurePreferences {
|
||||
|
||||
@JvmStatic
|
||||
fun isThreadLengthTrimmingEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, THREAD_TRIM_ENABLED, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getThreadTrimLength(context: Context): Int {
|
||||
return getStringPreference(context, THREAD_TRIM_LENGTH, "500")!!.toInt()
|
||||
return getBooleanPreference(context, THREAD_TRIM_ENABLED, true)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -1329,11 +1322,7 @@ class AppTextSecurePreferences @Inject constructor(
|
||||
}
|
||||
|
||||
override fun isThreadLengthTrimmingEnabled(): Boolean {
|
||||
return getBooleanPreference(TextSecurePreferences.THREAD_TRIM_ENABLED, false)
|
||||
}
|
||||
|
||||
override fun getThreadTrimLength(): Int {
|
||||
return getStringPreference(TextSecurePreferences.THREAD_TRIM_LENGTH, "500")!!.toInt()
|
||||
return getBooleanPreference(TextSecurePreferences.THREAD_TRIM_ENABLED, true)
|
||||
}
|
||||
|
||||
override fun isSystemEmojiPreferred(): Boolean {
|
||||
|
Reference in New Issue
Block a user