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

Unverified Commit d5fc337a authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #5632 from k9mail/MessageStore_message_count

Move LocalFolder.getMessageCount() to MessageStore
parents b59ef851 701b640d
Loading
Loading
Loading
Loading
+7 −15
Original line number Original line Diff line number Diff line
@@ -66,7 +66,6 @@ import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Part;
import com.fsck.k9.mail.Part;
import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mailstore.FolderDetailsAccessor;
import com.fsck.k9.mailstore.FolderDetailsAccessor;
import com.fsck.k9.mailstore.ListenableMessageStore;
import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.LocalStore;
import com.fsck.k9.mailstore.LocalStore;
@@ -1487,21 +1486,14 @@ public class MessagingController {
    }
    }


    private boolean messagesPendingSend(final Account account) {
    private boolean messagesPendingSend(final Account account) {
        try {
        Long outboxFolderId = account.getOutboxFolderId();
            LocalFolder localFolder = localStoreProvider.getInstance(account).getFolder(account.getOutboxFolderId());
        if (outboxFolderId == null) {
            if (!localFolder.exists()) {
            Timber.w("Could not get Outbox folder ID from Account");
            return false;
            return false;
        }
        }


            localFolder.open();
        MessageStore messageStore = messageStoreManager.getMessageStore(account);

        return messageStore.getMessageCount(outboxFolderId) > 0;
            if (localFolder.getMessageCount() > 0) {
                return true;
            }
        } catch (Exception e) {
            Timber.e(e, "Exception while checking for unsent messages");
        }
        return false;
    }
    }


    /**
    /**
+0 −28
Original line number Original line Diff line number Diff line
@@ -259,34 +259,6 @@ public class LocalFolder {
        });
        });
    }
    }


    public int getMessageCount() throws MessagingException {
        try {
            return this.localStore.getDatabase().execute(false, new DbCallback<Integer>() {
                @Override
                public Integer doDbWork(final SQLiteDatabase db) throws WrappedException {
                    try {
                        open();
                    } catch (MessagingException e) {
                        throw new WrappedException(e);
                    }
                    Cursor cursor = null;
                    try {
                        cursor = db.rawQuery(
                                "SELECT COUNT(id) FROM messages " +
                                "WHERE empty = 0 AND deleted = 0 and folder_id = ?",
                                new String[] { Long.toString(databaseId) });
                        cursor.moveToFirst();
                        return cursor.getInt(0);   //messagecount
                    } finally {
                        Utility.closeQuietly(cursor);
                    }
                }
            });
        } catch (WrappedException e) {
            throw (MessagingException) e.getCause();
        }
    }

    public MessageCounts getMessageCounts() throws MessagingException {
    public MessageCounts getMessageCounts() throws MessagingException {
        return new MessageCounts(getUnreadMessageCount(), getStarredMessageCount());
        return new MessageCounts(getUnreadMessageCount(), getStarredMessageCount());
    }
    }
+5 −0
Original line number Original line Diff line number Diff line
@@ -176,6 +176,11 @@ interface MessageStore {
     */
     */
    fun getFolderId(folderServerId: String): Long?
    fun getFolderId(folderServerId: String): Long?


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

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


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

    override fun getSize(): Long {
    override fun getSize(): Long {
        return databaseOperations.getSize()
        return databaseOperations.getSize()
    }
    }
+11 −0
Original line number Original line Diff line number Diff line
@@ -130,6 +130,17 @@ internal class RetrieveFolderOperations(private val lockableDatabase: LockableDa
            }
            }
        }
        }
    }
    }

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


private class CursorFolderAccessor(val cursor: Cursor) : FolderDetailsAccessor {
private class CursorFolderAccessor(val cursor: Cursor) : FolderDetailsAccessor {
Loading