Use folder database ID for PendingMarkAllAsRead

This commit is contained in:
cketti 2020-04-24 23:34:21 +02:00
parent c98943e983
commit 4e2d084401
3 changed files with 21 additions and 19 deletions

View file

@ -955,13 +955,18 @@ public class MessagingController {
}
void processPendingMarkAllAsRead(PendingMarkAllAsRead command, Account account) throws MessagingException {
String folder = command.folder;
LocalFolder localFolder = null;
LocalStore localStore = localStoreProvider.getInstance(account);
LocalFolder localFolder = localStore.getFolder(command.folderId);
String folderServerId;
try {
LocalStore localStore = localStoreProvider.getInstance(account);
localFolder = localStore.getFolder(folder);
localFolder.open();
List<? extends Message> messages = localFolder.getMessages(null, false);
folderServerId = localFolder.getServerId();
Timber.i("Marking all messages in %s:%s as read", account, folderServerId);
// TODO: Make this one database UPDATE operation
List<LocalMessage> messages = localFolder.getMessages(null, false);
for (Message message : messages) {
if (!message.isSet(Flag.SEEN)) {
message.setFlag(Flag.SEEN, true);
@ -969,22 +974,20 @@ public class MessagingController {
}
for (MessagingListener l : getListeners()) {
l.folderStatusChanged(account, folder);
l.folderStatusChanged(account, folderServerId);
}
} finally {
closeFolder(localFolder);
localFolder.close();
}
Backend backend = getBackend(account);
if (backend.getSupportsSeenFlag()) {
backend.markAllAsRead(folder);
backend.markAllAsRead(folderServerId);
}
}
public void markAllMessagesRead(final Account account, final String folder) {
Timber.i("Marking all messages in %s:%s as read", account.getDescription(), folder);
PendingCommand command = PendingMarkAllAsRead.create(folder);
public void markAllMessagesRead(Account account, long folderId) {
PendingCommand command = PendingMarkAllAsRead.create(folderId);
queuePendingCommand(account, command);
processPendingCommands(account);
}

View file

@ -178,16 +178,15 @@ public class MessagingControllerCommands {
}
public static class PendingMarkAllAsRead extends PendingCommand {
public final String folder;
public final long folderId;
public static PendingMarkAllAsRead create(String folder) {
checkNotNull(folder);
return new PendingMarkAllAsRead(folder);
public static PendingMarkAllAsRead create(long folderId) {
return new PendingMarkAllAsRead(folderId);
}
private PendingMarkAllAsRead(String folder) {
this.folder = folder;
private PendingMarkAllAsRead(long folderId) {
this.folderId = folderId;
}
@Override

View file

@ -2343,7 +2343,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
private void markAllAsRead() {
if (isMarkAllAsReadSupported()) {
messagingController.markAllMessagesRead(account, folderServerId);
messagingController.markAllMessagesRead(account, currentFolder.databaseId);
}
}