From 00fc6708cc9ac8f51f2de0cad060bb149ad29f7d Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 12 Jun 2020 18:09:37 +0200 Subject: [PATCH] Change MessagingController.deleteMessagesSynchronous() to use folder ID --- .../k9/controller/MessagingController.java | 57 ++++++------------- .../NotificationActionService.java | 2 +- .../com/fsck/k9/external/MessageProvider.java | 2 +- .../fsck/k9/fragment/MessageListFragment.java | 2 +- .../ui/messageview/MessageViewFragment.java | 2 +- 5 files changed, 22 insertions(+), 43 deletions(-) diff --git a/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java b/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java index 0651c3f48..63e614221 100644 --- a/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -1857,7 +1857,7 @@ public class MessagingController { String uid = localFolder.getMessageUidById(id); if (uid != null) { MessageReference messageReference = new MessageReference(account.getUuid(), folderId, uid, null); - deleteMessage(messageReference, null); + deleteMessage(messageReference); } } catch (MessagingException me) { Timber.e(me, "Error deleting draft"); @@ -1865,26 +1865,18 @@ public class MessagingController { } public void deleteThreads(final List messages) { - actOnMessagesGroupedByAccountAndFolder(messages, new MessageActor() { - @Override - public void act(final Account account, final LocalFolder messageFolder, - final List accountMessages) { - suppressMessages(account, accountMessages); - - putBackground("deleteThreads", null, new Runnable() { - @Override - public void run() { - deleteThreadsSynchronous(account, messageFolder.getServerId(), accountMessages); - } - }); - } + actOnMessagesGroupedByAccountAndFolder(messages, (account, messageFolder, accountMessages) -> { + suppressMessages(account, accountMessages); + putBackground("deleteThreads", null, () -> + deleteThreadsSynchronous(account, messageFolder.getDatabaseId(), accountMessages) + ); }); } - private void deleteThreadsSynchronous(Account account, String folderServerId, List messages) { + private void deleteThreadsSynchronous(Account account, long folderId, List messages) { try { List messagesToDelete = collectMessagesInThreads(account, messages); - deleteMessagesSynchronous(account, folderServerId, messagesToDelete, null); + deleteMessagesSynchronous(account, folderId, messagesToDelete); } catch (MessagingException e) { Timber.e(e, "Something went wrong while deleting threads"); } @@ -1908,26 +1900,16 @@ public class MessagingController { return messagesInThreads; } - public void deleteMessage(MessageReference message, final MessagingListener listener) { - deleteMessages(Collections.singletonList(message), listener); + public void deleteMessage(MessageReference message) { + deleteMessages(Collections.singletonList(message)); } - public void deleteMessages(List messages, final MessagingListener listener) { - actOnMessagesGroupedByAccountAndFolder(messages, new MessageActor() { - - @Override - public void act(final Account account, final LocalFolder messageFolder, - final List accountMessages) { - suppressMessages(account, accountMessages); - - putBackground("deleteMessages", null, new Runnable() { - @Override - public void run() { - deleteMessagesSynchronous(account, messageFolder.getServerId(), accountMessages, listener); - } - }); - } - + public void deleteMessages(List messages) { + actOnMessagesGroupedByAccountAndFolder(messages, (account, messageFolder, accountMessages) -> { + suppressMessages(account, accountMessages); + putBackground("deleteMessages", null, () -> + deleteMessagesSynchronous(account, messageFolder.getDatabaseId(), accountMessages) + ); }); } @@ -1960,9 +1942,7 @@ public class MessagingController { } - private void deleteMessagesSynchronous(final Account account, final String folder, - final List messages, - MessagingListener listener) { + private void deleteMessagesSynchronous(Account account, long folderId, List messages) { try { List localOnlyMessages = new ArrayList<>(); List syncedMessages = new ArrayList<>(); @@ -1980,9 +1960,8 @@ public class MessagingController { Backend backend = getBackend(account); LocalStore localStore = localStoreProvider.getInstance(account); - LocalFolder localFolder = localStore.getFolder(folder); + LocalFolder localFolder = localStore.getFolder(folderId); localFolder.open(); - long folderId = localFolder.getDatabaseId(); Map uidMap = null; Long trashFolderId = account.getTrashFolderId(); diff --git a/app/core/src/main/java/com/fsck/k9/notification/NotificationActionService.java b/app/core/src/main/java/com/fsck/k9/notification/NotificationActionService.java index 755f1cd91..a0453579e 100644 --- a/app/core/src/main/java/com/fsck/k9/notification/NotificationActionService.java +++ b/app/core/src/main/java/com/fsck/k9/notification/NotificationActionService.java @@ -181,7 +181,7 @@ public class NotificationActionService extends Service { List messageReferenceStrings = intent.getStringArrayListExtra(EXTRA_MESSAGE_REFERENCES); List messageReferences = toMessageReferenceList(messageReferenceStrings); - controller.deleteMessages(messageReferences, null); + controller.deleteMessages(messageReferences); } private void archiveMessages(Intent intent, Account account, MessagingController controller) { diff --git a/app/k9mail/src/main/java/com/fsck/k9/external/MessageProvider.java b/app/k9mail/src/main/java/com/fsck/k9/external/MessageProvider.java index beb5113c7..320b83e10 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/external/MessageProvider.java +++ b/app/k9mail/src/main/java/com/fsck/k9/external/MessageProvider.java @@ -166,7 +166,7 @@ public class MessageProvider extends ContentProvider { if (myAccount != null) { MessageReference messageReference = new MessageReference(myAccount.getUuid(), folderId, msgUid, null); MessagingController controller = MessagingController.getInstance(getContext()); - controller.deleteMessage(messageReference, null); + controller.deleteMessage(messageReference); } // FIXME return the actual number of deleted messages diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.java b/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.java index c404e43d6..84df692fd 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.java +++ b/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.java @@ -727,7 +727,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener if (showingThreadedList) { messagingController.deleteThreads(messages); } else { - messagingController.deleteMessages(messages, null); + messagingController.deleteMessages(messages); } } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java index c1840306d..349f06a26 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java @@ -317,7 +317,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF mFragmentListener.disableDeleteAction(); LocalMessage messageToDelete = mMessage; mFragmentListener.showNextMessageOrReturn(); - mController.deleteMessage(mMessageReference, null); + mController.deleteMessage(mMessageReference); } }