Tweak the way messages are marked as read on opening
Update the message object and cache right away. Do the rest in a single background operation.
This commit is contained in:
parent
3f1911783e
commit
78d6e23362
1 changed files with 35 additions and 22 deletions
|
@ -1272,34 +1272,47 @@ public class MessagingController {
|
|||
}
|
||||
|
||||
public void markMessageAsOpened(Account account, LocalMessage message) {
|
||||
put("markMessageAsOpened", null, () -> {
|
||||
markMessageAsOpenedBlocking(account, message);
|
||||
threadPool.execute(() ->
|
||||
notificationController.removeNewMailNotification(account, message.makeMessageReference())
|
||||
);
|
||||
|
||||
if (message.isSet(Flag.SEEN)) {
|
||||
// Nothing to do if the message is already marked as read
|
||||
return;
|
||||
}
|
||||
|
||||
boolean markMessageAsRead = account.isMarkMessageAsReadOnView();
|
||||
if (markMessageAsRead) {
|
||||
// Mark the message itself as read right away
|
||||
try {
|
||||
message.setFlagInternal(Flag.SEEN, true);
|
||||
} catch (MessagingException e) {
|
||||
Timber.e(e, "Error while marking message as read");
|
||||
}
|
||||
|
||||
// Also mark the message as read in the cache
|
||||
List<Long> messageIds = Collections.singletonList(message.getDatabaseId());
|
||||
setFlagInCache(account, messageIds, Flag.SEEN, true);
|
||||
}
|
||||
|
||||
putBackground("markMessageAsOpened", null, () -> {
|
||||
markMessageAsOpenedBlocking(account, message, markMessageAsRead);
|
||||
});
|
||||
}
|
||||
|
||||
private void markMessageAsOpenedBlocking(Account account, LocalMessage message) {
|
||||
notificationController.removeNewMailNotification(account,message.makeMessageReference());
|
||||
|
||||
if (!message.isSet(Flag.SEEN)) {
|
||||
if (account.isMarkMessageAsReadOnView()) {
|
||||
markMessageAsReadOnView(account, message);
|
||||
} else {
|
||||
// Marking a message as read will automatically mark it as "not new". But if we don't mark the message
|
||||
// as read on opening, we have to manually mark it as "not new".
|
||||
markMessageAsNotNew(account, message);
|
||||
}
|
||||
private void markMessageAsOpenedBlocking(Account account, LocalMessage message, boolean markMessageAsRead) {
|
||||
if (markMessageAsRead) {
|
||||
markMessageAsRead(account, message);
|
||||
} else {
|
||||
// Marking a message as read will automatically mark it as "not new". But if we don't mark the message
|
||||
// as read on opening, we have to manually mark it as "not new".
|
||||
markMessageAsNotNew(account, message);
|
||||
}
|
||||
}
|
||||
|
||||
private void markMessageAsReadOnView(Account account, LocalMessage message) {
|
||||
try {
|
||||
List<Long> messageIds = Collections.singletonList(message.getDatabaseId());
|
||||
setFlag(account, messageIds, Flag.SEEN, true);
|
||||
|
||||
message.setFlagInternal(Flag.SEEN, true);
|
||||
} catch (MessagingException e) {
|
||||
Timber.e(e, "Error while marking message as read");
|
||||
}
|
||||
private void markMessageAsRead(Account account, LocalMessage message) {
|
||||
List<Long> messageIds = Collections.singletonList(message.getDatabaseId());
|
||||
setFlagSynchronous(account, messageIds, Flag.SEEN, true, false);
|
||||
}
|
||||
|
||||
private void markMessageAsNotNew(Account account, LocalMessage message) {
|
||||
|
|
Loading…
Reference in a new issue