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

Commit ae2c9331 authored by Matt Johnston's avatar Matt Johnston Committed by Jesse Vincent
Browse files

Destroy all messages in one sqlite transaction

parent 0d0415e7
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -1005,13 +1005,19 @@ public class MessagingController implements Runnable {
             * Remove any messages that are in the local store but no longer on the remote store or are too old
             */
            if (account.syncRemoteDeletions()) {
                ArrayList<Message> destroyMessages = new ArrayList<Message>();
                for (Message localMessage : localMessages) {
                    if (remoteUidMap.get(localMessage.getUid()) == null) {
                        localMessage.destroy();
                        destroyMessages.add(localMessage);
                    }
                }


                localFolder.destroyMessages(destroyMessages.toArray(EMPTY_MESSAGE_ARRAY));

                for (Message destroyMessage : destroyMessages) {
                    for (MessagingListener l : getListeners(listener)) {
                            l.synchronizeMailboxRemovedMessage(account, folder, localMessage);
                        }
                        l.synchronizeMailboxRemovedMessage(account, folder, destroyMessage);
                    }
                }
            }
+21 −0
Original line number Diff line number Diff line
@@ -2020,6 +2020,27 @@ public class LocalStore extends Store implements Serializable {
            appendMessages(messages, false);
        }

        public void destroyMessages(final Message[] messages) throws MessagingException {
                try {
                    database.execute(true, new DbCallback<Void>() {
                        @Override
                        public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
                            for (Message message : messages) {
                                try {
                                    message.destroy();
                                } catch (MessagingException e) {
                                    throw new WrappedException(e);
                                }
                            }
                            return null;
                        }
                    });
                } catch (MessagingException e) {
                    throw new WrappedException(e);
                }
        }


        /**
         * The method differs slightly from the contract; If an incoming message already has a uid
         * assigned and it matches the uid of an existing message then this message will replace the