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

Commit 7d40596a authored by Jesse Vincent's avatar Jesse Vincent
Browse files

split apart "delete messages older than" for later reuse

parent f56afdbf
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -3438,19 +3438,13 @@ public class LocalStore extends Store implements Serializable, LocalStoreMigrati
            throw new MessagingException("Cannot call getUidFromMessageId on LocalFolder");
        }

        public void deleteMessagesOlderThan(long cutoff) throws MessagingException
        private void deleteMessagesWhere(final String whereClause, final String[] params)  throws MessagingException
        {
            final String where = "folder_id = ? and date < ?";
            final String[] params = new String[]
            {
                Long.toString(mFolderId), Long.toString(cutoff)
            };

            open(OpenMode.READ_ONLY);
            Message[] messages  = LocalStore.this.getMessages(
                                      null,
                                      this,
                                      "SELECT " + GET_MESSAGES_COLS + "FROM messages WHERE " + where,
                                      "SELECT " + GET_MESSAGES_COLS + "FROM messages WHERE " + whereClause,
                                      params);

            for (Message message : messages)
@@ -3462,13 +3456,25 @@ public class LocalStore extends Store implements Serializable, LocalStoreMigrati
                @Override
                public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException
                {
                    db.execSQL("DELETE FROM messages WHERE " + where, params);
                    db.execSQL("DELETE FROM messages WHERE " + whereClause, params);
                    return null;
                }
            });
            resetUnreadAndFlaggedCounts();
        }

        public void deleteMessagesOlderThan(long cutoff) throws MessagingException
        {
            final String where = "folder_id = ? and date < ?";
            final String[] params = new String[]
            {
                Long.toString(mFolderId), Long.toString(cutoff)
            };

            deleteMessagesWhere(where, params);
        }


        private void resetUnreadAndFlaggedCounts()
        {
            try