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

Commit 5e178294 authored by cketti's avatar cketti
Browse files

Rewrite `MessageCountsProvider.getUnreadMessageCount()` to not use `LocalStore`

parent 4cc16436
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -31,7 +31,8 @@ val controllerModule = module {
        DefaultMessageCountsProvider(
            preferences = get(),
            accountSearchConditions = get(),
            localStoreProvider = get()
            localStoreProvider = get(),
            messageStoreManager = get()
        )
    }
}
+10 −6
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import com.fsck.k9.Account
import com.fsck.k9.Preferences
import com.fsck.k9.mail.MessagingException
import com.fsck.k9.mailstore.LocalStoreProvider
import com.fsck.k9.mailstore.MessageStoreManager
import com.fsck.k9.search.AccountSearchConditions
import com.fsck.k9.search.LocalSearch
import com.fsck.k9.search.SearchAccount
@@ -21,7 +22,8 @@ data class MessageCounts(val unread: Int, val starred: Int)
internal class DefaultMessageCountsProvider(
    private val preferences: Preferences,
    private val accountSearchConditions: AccountSearchConditions,
    private val localStoreProvider: LocalStoreProvider
    private val localStoreProvider: LocalStoreProvider,
    private val messageStoreManager: MessageStoreManager
) : MessageCountsProvider {
    override fun getMessageCounts(account: Account): MessageCounts {
        return try {
@@ -55,11 +57,13 @@ internal class DefaultMessageCountsProvider(

    override fun getUnreadMessageCount(account: Account, folderId: Long): Int {
        return try {
            val localStore = localStoreProvider.getInstance(account)
            val localFolder = localStore.getFolder(folderId)

            localFolder.unreadMessageCount
        } catch (e: MessagingException) {
            val messageStore = messageStoreManager.getMessageStore(account)
            return if (folderId == account.outboxFolderId) {
                messageStore.getMessageCount(folderId)
            } else {
                messageStore.getUnreadMessageCount(folderId)
            }
        } catch (e: Exception) {
            Timber.e(e, "Unable to getUnreadMessageCount for account: %s, folder: %d", account, folderId)
            0
        }
+5 −0
Original line number Diff line number Diff line
@@ -221,6 +221,11 @@ interface MessageStore {
     */
    fun getMessageCount(folderId: Long): Int

    /**
     * Retrieve the number of unread messages in a folder.
     */
    fun getUnreadMessageCount(folderId: Long): Int

    /**
     * Update a folder's name and type.
     */
+4 −0
Original line number Diff line number Diff line
@@ -176,6 +176,10 @@ class K9MessageStore(
        return retrieveFolderOperations.getMessageCount(folderId)
    }

    override fun getUnreadMessageCount(folderId: Long): Int {
        return retrieveFolderOperations.getUnreadMessageCount(folderId)
    }

    override fun getSize(): Long {
        return databaseOperations.getSize()
    }
+11 −0
Original line number Diff line number Diff line
@@ -159,6 +159,17 @@ $displayModeSelection
        }
    }

    fun getUnreadMessageCount(folderId: Long): Int {
        return lockableDatabase.execute(false) { db ->
            db.rawQuery(
                "SELECT COUNT(id) FROM messages WHERE empty = 0 AND deleted = 0 AND read = 0 AND folder_id = ?",
                arrayOf(folderId.toString())
            ).use { cursor ->
                if (cursor.moveToFirst()) cursor.getInt(0) else 0
            }
        }
    }

    fun hasMoreMessages(folderId: Long): MoreMessages {
        return getFolder(folderId) { it.moreMessages } ?: throw FolderNotFoundException(folderId)
    }
Loading