Only mark a message as read when it is the active message
Previously we marked a message as read when loading it for viewing. But with swiping between messages we could now load a message before it is considered the active message.
This commit is contained in:
parent
de6d4197f2
commit
3e90e92b2e
2 changed files with 54 additions and 8 deletions
|
@ -1309,9 +1309,6 @@ public class MessagingController {
|
|||
fp.add(FetchProfile.Item.BODY);
|
||||
localFolder.fetch(Collections.singletonList(message), fp, null);
|
||||
|
||||
notificationController.removeNewMailNotification(account, message.makeMessageReference());
|
||||
markMessageAsOpened(account, message);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
@ -1333,7 +1330,15 @@ public class MessagingController {
|
|||
return message;
|
||||
}
|
||||
|
||||
private void markMessageAsOpened(Account account, LocalMessage message) throws MessagingException {
|
||||
public void markMessageAsOpened(Account account, LocalMessage message) {
|
||||
put("markMessageAsOpened", null, () -> {
|
||||
markMessageAsOpenedBlocking(account, message);
|
||||
});
|
||||
}
|
||||
|
||||
private void markMessageAsOpenedBlocking(Account account, LocalMessage message) {
|
||||
notificationController.removeNewMailNotification(account,message.makeMessageReference());
|
||||
|
||||
if (!message.isSet(Flag.SEEN)) {
|
||||
if (account.isMarkMessageAsReadOnView()) {
|
||||
markMessageAsReadOnView(account, message);
|
||||
|
@ -1345,11 +1350,15 @@ public class MessagingController {
|
|||
}
|
||||
}
|
||||
|
||||
private void markMessageAsReadOnView(Account account, LocalMessage message) throws MessagingException {
|
||||
List<Long> messageIds = Collections.singletonList(message.getDatabaseId());
|
||||
setFlag(account, messageIds, Flag.SEEN, true);
|
||||
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);
|
||||
message.setFlagInternal(Flag.SEEN, true);
|
||||
} catch (MessagingException e) {
|
||||
Timber.e(e, "Error while marking message as read");
|
||||
}
|
||||
}
|
||||
|
||||
private void markMessageAsNotNew(Account account, LocalMessage message) {
|
||||
|
|
|
@ -89,6 +89,7 @@ class MessageViewFragment :
|
|||
|
||||
private var currentAttachmentViewInfo: AttachmentViewInfo? = null
|
||||
private var isDeleteMenuItemDisabled: Boolean = false
|
||||
private var wasMessageMarkedAsOpened: Boolean = false
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
|
@ -108,6 +109,10 @@ class MessageViewFragment :
|
|||
messageReference = MessageReference.parse(arguments?.getString(ARG_REFERENCE))
|
||||
?: error("Invalid argument '$ARG_REFERENCE'")
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
wasMessageMarkedAsOpened = savedInstanceState.getBoolean(STATE_WAS_MESSAGE_MARKED_AS_OPENED)
|
||||
}
|
||||
|
||||
messageCryptoPresenter = MessageCryptoPresenter(messageCryptoMvpView)
|
||||
messageLoaderHelper = messageLoaderHelperFactory.createForMessageView(
|
||||
context = requireContext().applicationContext,
|
||||
|
@ -164,8 +169,24 @@ class MessageViewFragment :
|
|||
invalidateMenu()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putBoolean(STATE_WAS_MESSAGE_MARKED_AS_OPENED, wasMessageMarkedAsOpened)
|
||||
}
|
||||
|
||||
override fun setMenuVisibility(menuVisible: Boolean) {
|
||||
super.setMenuVisibility(menuVisible)
|
||||
|
||||
// When the menu is hidden, the message associated with this fragment is no longer active. If the user returns
|
||||
// to it, we want to mark the message as opened again.
|
||||
if (!menuVisible) {
|
||||
wasMessageMarkedAsOpened = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
markMessageAsOpened()
|
||||
messageCryptoPresenter.onResume()
|
||||
}
|
||||
|
||||
|
@ -737,6 +758,15 @@ class MessageViewFragment :
|
|||
messageTopView.refreshAttachmentThumbnail(attachment)
|
||||
}
|
||||
|
||||
private fun markMessageAsOpened() {
|
||||
val message = message ?: return
|
||||
|
||||
if (!wasMessageMarkedAsOpened) {
|
||||
messagingController.markMessageAsOpened(account, message)
|
||||
wasMessageMarkedAsOpened = true
|
||||
}
|
||||
}
|
||||
|
||||
private val messageCryptoMvpView: MessageCryptoMvpView = object : MessageCryptoMvpView {
|
||||
override fun redisplayMessage() {
|
||||
messageLoaderHelper.asyncReloadMessage()
|
||||
|
@ -807,6 +837,11 @@ class MessageViewFragment :
|
|||
displayHeaderForLoadingMessage(message)
|
||||
messageTopView.setToLoadingState()
|
||||
showProgressThreshold = null
|
||||
|
||||
// Only mark the message as opened when the fragment is resumed, i.e. when this is the active message.
|
||||
if (isResumed) {
|
||||
markMessageAsOpened()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMessageDataLoadFailed() {
|
||||
|
@ -908,6 +943,8 @@ class MessageViewFragment :
|
|||
|
||||
private const val ARG_REFERENCE = "reference"
|
||||
|
||||
private const val STATE_WAS_MESSAGE_MARKED_AS_OPENED = "wasMessageMarkedAsOpened"
|
||||
|
||||
private const val ACTIVITY_CHOOSE_FOLDER_MOVE = 1
|
||||
private const val ACTIVITY_CHOOSE_FOLDER_COPY = 2
|
||||
private const val REQUEST_CODE_CREATE_DOCUMENT = 3
|
||||
|
|
Loading…
Reference in a new issue