Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 588bf907 authored by dandarnell's avatar dandarnell Committed by GitHub
Browse files

Merge pull request #9866 from...

Merge pull request #9866 from rafaeltonholo/uplift/beta/9852/outbox-state-entry-not-found-enforce-outbox

uplift(beta): enforce always one outbox folder per account and remove outboxFolderId from preferences
parents a9d75ec4 a947f002
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -54,7 +54,7 @@ internal class AccountCreator(
        }
        }
    }
    }


    private fun create(account: Account): String {
    private suspend fun create(account: Account): String {
        val newAccount = preferences.newAccount(account.uuid)
        val newAccount = preferences.newAccount(account.uuid)


        newAccount.email = account.emailAddress
        newAccount.email = account.emailAddress
+0 −4
Original line number Original line Diff line number Diff line
@@ -163,10 +163,6 @@ open class LegacyAccount(
    @set:Synchronized
    @set:Synchronized
    var inboxFolderId: Long? = null
    var inboxFolderId: Long? = null


    @get:Synchronized
    @set:Synchronized
    var outboxFolderId: Long? = null

    @get:Synchronized
    @get:Synchronized
    @set:Synchronized
    @set:Synchronized
    var draftsFolderId: Long? = null
    var draftsFolderId: Long? = null
+0 −1
Original line number Original line Diff line number Diff line
@@ -52,7 +52,6 @@ data class LegacyAccountWrapper(
    val importedArchiveFolder: String? = null,
    val importedArchiveFolder: String? = null,
    val importedSpamFolder: String? = null,
    val importedSpamFolder: String? = null,
    val inboxFolderId: Long? = null,
    val inboxFolderId: Long? = null,
    val outboxFolderId: Long? = null,
    val draftsFolderId: Long? = null,
    val draftsFolderId: Long? = null,
    val sentFolderId: Long? = null,
    val sentFolderId: Long? = null,
    val trashFolderId: Long? = null,
    val trashFolderId: Long? = null,
+0 −1
Original line number Original line Diff line number Diff line
@@ -127,7 +127,6 @@ class LegacyAccountWrapperTest {
                importedArchiveFolder = null,
                importedArchiveFolder = null,
                importedSpamFolder = null,
                importedSpamFolder = null,
                inboxFolderId = null,
                inboxFolderId = null,
                outboxFolderId = null,
                draftsFolderId = null,
                draftsFolderId = null,
                sentFolderId = null,
                sentFolderId = null,
                trashFolderId = null,
                trashFolderId = null,
+62 −0
Original line number Original line Diff line number Diff line
@file:OptIn(ExperimentalTime::class)

package net.thunderbird.core.common.cache

import kotlin.time.Clock
import kotlin.time.Duration
import kotlin.time.Duration.Companion.hours
import kotlin.time.ExperimentalTime
import kotlin.time.Instant

class TimeLimitedCache<TKey : Any, TValue : Any?>(
    private val clock: Clock = Clock.System,
    private val cache: MutableMap<TKey, Entry<TValue>> = mutableMapOf(),
) : Cache<TKey, TimeLimitedCache.Entry<TValue>> {
    companion object {
        private val DEFAULT_EXPIRATION_TIME = 1.hours
    }

    override fun get(key: TKey): Entry<TValue>? {
        recycle(key)
        return cache[key]
    }

    fun getValue(key: TKey): TValue? = get(key)?.value

    fun set(key: TKey, value: TValue, expiresIn: Duration = DEFAULT_EXPIRATION_TIME) {
        set(key, Entry(value, creationTime = clock.now(), expiresIn))
    }

    override fun set(key: TKey, value: Entry<TValue>) {
        cache[key] = value
    }

    override fun hasKey(key: TKey): Boolean {
        recycle(key)
        return key in cache
    }

    override fun clear() {
        cache.clear()
    }

    fun clearExpired() {
        cache.entries.removeAll { (_, entry) ->
            entry.expiresAt < clock.now()
        }
    }

    private fun recycle(key: TKey) {
        val entry = cache[key] ?: return
        if (entry.expiresAt < clock.now()) {
            cache.remove(key)
        }
    }

    data class Entry<TValue : Any?>(
        val value: TValue,
        val creationTime: Instant,
        val expiresIn: Duration,
        val expiresAt: Instant = creationTime + expiresIn,
    )
}
Loading