Merge pull request #4808 from k9mail/notification_logging

Add logging to K9NotificationStrategy
This commit is contained in:
cketti 2020-06-03 20:17:12 +02:00 committed by GitHub
commit 87cd417076
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 33 deletions

View file

@ -2767,6 +2767,7 @@ public class MessagingController {
LocalMessage message = loadMessage(folderServerId, messageServerId);
LocalFolder localFolder = message.getFolder();
if (notificationStrategy.shouldNotifyForMessage(account, localFolder, message, isOldMessage)) {
Timber.v("Creating notification for message %s:%s", localFolder.getName(), message.getUid());
// Notify with the localMessage so that we don't have to recalculate the content preview.
notificationController.addNewMailNotification(account, message, previousUnreadMessageCount);
}

View file

@ -5,9 +5,11 @@ import com.fsck.k9.K9
import com.fsck.k9.helper.Contacts
import com.fsck.k9.mail.Flag
import com.fsck.k9.mailstore.LocalFolder
import com.fsck.k9.mailstore.LocalFolder.isModeMismatch
import com.fsck.k9.mailstore.LocalMessage
import timber.log.Timber
class K9NotificationStrategy(val contacts: Contacts) : NotificationStrategy {
class K9NotificationStrategy(private val contacts: Contacts) : NotificationStrategy {
override fun shouldNotifyForMessage(
account: Account,
@ -19,51 +21,72 @@ class K9NotificationStrategy(val contacts: Contacts) : NotificationStrategy {
// If we don't even have an account name, don't show the notification.
// (This happens during initial account setup)
if (account.name == null) {
Timber.v("No notification: Missing account name")
return false
}
if (K9.isQuietTime && !K9.isNotificationDuringQuietTimeEnabled) {
if (!K9.isNotificationDuringQuietTimeEnabled && K9.isQuietTime) {
Timber.v("No notification: Quiet time is active")
return false
}
// Do not notify if the user does not have notifications enabled or if the message has
// been read.
if (!account.isNotifyNewMail || message.isSet(Flag.SEEN) || isOldMessage) {
if (!account.isNotifyNewMail) {
Timber.v("No notification: Notifications are disabled")
return false
}
val aDisplayMode = account.folderDisplayMode
val aNotifyMode = account.folderNotifyNewMailMode
val fDisplayClass = localFolder.displayClass
val fNotifyClass = localFolder.notifyClass
if (LocalFolder.isModeMismatch(aDisplayMode, fDisplayClass)) {
// Never notify a folder that isn't displayed
return false
}
if (LocalFolder.isModeMismatch(aNotifyMode, fNotifyClass)) {
// Do not notify folders in the wrong class
return false
}
// No notification for new messages in Trash, Drafts, Spam or Sent folder.
val folder = message.folder
if (folder != null) {
val folderId = folder.databaseId
if (folderId == account.trashFolderId ||
folderId == account.draftsFolderId ||
folderId == account.spamFolderId ||
folderId == account.sentFolderId
) {
return false
when (folder.databaseId) {
account.trashFolderId -> {
Timber.v("No notification: Message is in Trash folder")
return false
}
account.draftsFolderId -> {
Timber.v("No notification: Message is in Drafts folder")
return false
}
account.spamFolderId -> {
Timber.v("No notification: Message is in Spam folder")
return false
}
account.sentFolderId -> {
Timber.v("No notification: Message is in Sent folder")
return false
}
}
}
// Don't notify if the sender address matches one of our identities and the user chose not
// to be notified for such messages.
return if (account.isAnIdentity(message.from) && !account.isNotifySelfNewMail) {
false
} else !account.isNotifyContactsMailOnly || contacts.isAnyInContacts(message.from)
if (isModeMismatch(account.folderDisplayMode, localFolder.displayClass)) {
Timber.v("No notification: Message is in folder not being displayed")
return false
}
if (isModeMismatch(account.folderNotifyNewMailMode, localFolder.notifyClass)) {
Timber.v("No notification: Notifications are disabled for this folder class")
return false
}
if (isOldMessage) {
Timber.v("No notification: Message is old")
return false
}
if (message.isSet(Flag.SEEN)) {
Timber.v("No notification: Message is marked as read")
return false
}
if (!account.isNotifySelfNewMail && account.isAnIdentity(message.from)) {
Timber.v("No notification: Notifications for messages from yourself are disabled")
return false
}
if (account.isNotifyContactsMailOnly && !contacts.isAnyInContacts(message.from)) {
Timber.v("No notification: Message is not from a known contact")
return false
}
return true
}
}