Open message from notification in Unified Inbox if possible
This commit is contained in:
parent
b05c0ea5c4
commit
91c0787fa5
2 changed files with 38 additions and 16 deletions
|
@ -35,7 +35,9 @@ internal class K9NotificationActionCreator(
|
|||
messageReference: MessageReference,
|
||||
notificationId: Int
|
||||
): PendingIntent {
|
||||
val intent = createMessageViewIntent(messageReference)
|
||||
val openInUnifiedInbox = K9.isShowUnifiedInbox && isIncludedInUnifiedInbox(messageReference)
|
||||
val intent = createMessageViewIntent(messageReference, openInUnifiedInbox)
|
||||
|
||||
return PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
|
||||
|
@ -226,8 +228,8 @@ internal class K9NotificationActionCreator(
|
|||
)
|
||||
}
|
||||
|
||||
private fun createMessageViewIntent(message: MessageReference): Intent {
|
||||
return MessageList.actionDisplayMessageIntent(context, message)
|
||||
private fun createMessageViewIntent(message: MessageReference, openInUnifiedInbox: Boolean): Intent {
|
||||
return MessageList.actionDisplayMessageIntent(context, message, openInUnifiedInbox)
|
||||
}
|
||||
|
||||
private fun createUnifiedInboxIntent(account: Account): Intent {
|
||||
|
@ -246,4 +248,9 @@ internal class K9NotificationActionCreator(
|
|||
val messageStore = messageStoreManager.getMessageStore(account)
|
||||
return messageStore.areAllIncludedInUnifiedInbox(folderIds)
|
||||
}
|
||||
|
||||
private fun isIncludedInUnifiedInbox(messageReference: MessageReference): Boolean {
|
||||
val messageStore = messageStoreManager.getMessageStore(messageReference.accountUuid)
|
||||
return messageStore.areAllIncludedInUnifiedInbox(listOf(messageReference.folderId))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -463,6 +463,22 @@ open class MessageList :
|
|||
search = search,
|
||||
noThreading = true
|
||||
)
|
||||
} else if (intent.hasExtra(EXTRA_MESSAGE_REFERENCE)) {
|
||||
val messageReferenceString = intent.getStringExtra(EXTRA_MESSAGE_REFERENCE)
|
||||
val messageReference = MessageReference.parse(messageReferenceString)
|
||||
|
||||
if (messageReference != null) {
|
||||
val search = if (intent.hasExtra(EXTRA_SEARCH)) {
|
||||
ParcelableUtil.unmarshall(intent.getByteArrayExtra(EXTRA_SEARCH), LocalSearch.CREATOR)
|
||||
} else {
|
||||
messageReference.toLocalSearch()
|
||||
}
|
||||
|
||||
return LaunchData(
|
||||
search = search,
|
||||
messageReference = messageReference
|
||||
)
|
||||
}
|
||||
} else if (intent.hasExtra(EXTRA_SEARCH)) {
|
||||
// regular LocalSearch object was passed
|
||||
val search = ParcelableUtil.unmarshall(intent.getByteArrayExtra(EXTRA_SEARCH), LocalSearch.CREATOR)
|
||||
|
@ -472,16 +488,6 @@ open class MessageList :
|
|||
}
|
||||
|
||||
return LaunchData(search = search, account = account, noThreading = noThreading)
|
||||
} else if (intent.hasExtra(EXTRA_MESSAGE_REFERENCE)) {
|
||||
val messageReferenceString = intent.getStringExtra(EXTRA_MESSAGE_REFERENCE)
|
||||
val messageReference = MessageReference.parse(messageReferenceString)
|
||||
|
||||
if (messageReference != null) {
|
||||
return LaunchData(
|
||||
search = messageReference.toLocalSearch(),
|
||||
messageReference = messageReference
|
||||
)
|
||||
}
|
||||
} else if (intent.hasExtra("account")) {
|
||||
val accountUuid = intent.getStringExtra("account")
|
||||
if (accountUuid != null) {
|
||||
|
@ -1741,12 +1747,21 @@ open class MessageList :
|
|||
return intentDisplaySearch(context, search, noThreading = false, newTask = true, clearTop = true)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun actionDisplayMessageIntent(context: Context?, messageReference: MessageReference): Intent {
|
||||
fun actionDisplayMessageIntent(
|
||||
context: Context,
|
||||
messageReference: MessageReference,
|
||||
openInUnifiedInbox: Boolean = false
|
||||
): Intent {
|
||||
return Intent(context, MessageList::class.java).apply {
|
||||
putExtra(EXTRA_MESSAGE_REFERENCE, messageReference.toIdentityString())
|
||||
|
||||
if (openInUnifiedInbox) {
|
||||
val search = SearchAccount.createUnifiedInboxAccount().relatedSearch
|
||||
putExtra(EXTRA_SEARCH, ParcelableUtil.marshall(search))
|
||||
}
|
||||
|
||||
addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
putExtra(EXTRA_MESSAGE_REFERENCE, messageReference.toIdentityString())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue