From aefeb01cdd2b9f0aada6d2ad94211c1de2177be7 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 27 Sep 2023 10:12:04 +0200 Subject: [PATCH] Reduce the number of fallback notification. Only used now when message cannot be decrypted. Also avoid using `else` in this `when` block. --- .../notifications/NotifiableEventResolver.kt | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotifiableEventResolver.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotifiableEventResolver.kt index c93d517e89..9951698b88 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotifiableEventResolver.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotifiableEventResolver.kt @@ -114,10 +114,63 @@ class NotifiableEventResolver @Inject constructor( title = null, // TODO check if title is needed anymore ) } else { - fallbackNotifiableEvent(userId, roomId, eventId) + Timber.tag(loggerTag.value).d("Ignoring notification state event for membership ${content.membershipState}") + null } } - else -> fallbackNotifiableEvent(userId, roomId, eventId) + NotificationContent.MessageLike.CallAnswer, + NotificationContent.MessageLike.CallCandidates, + NotificationContent.MessageLike.CallHangup, + NotificationContent.MessageLike.CallInvite -> null.also { + Timber.tag(loggerTag.value).d("Ignoring notification for call ${content.javaClass.simpleName}") + } + NotificationContent.MessageLike.KeyVerificationAccept, + NotificationContent.MessageLike.KeyVerificationCancel, + NotificationContent.MessageLike.KeyVerificationDone, + NotificationContent.MessageLike.KeyVerificationKey, + NotificationContent.MessageLike.KeyVerificationMac, + NotificationContent.MessageLike.KeyVerificationReady, + NotificationContent.MessageLike.KeyVerificationStart -> null.also { + Timber.tag(loggerTag.value).d("Ignoring notification for verification ${content.javaClass.simpleName}") + } + is NotificationContent.MessageLike.Poll -> null.also { + // TODO Polls: handle notification rendering + Timber.tag(loggerTag.value).d("Ignoring notification for poll") + } + is NotificationContent.MessageLike.ReactionContent -> null.also { + Timber.tag(loggerTag.value).d("Ignoring notification for reaction") + } + NotificationContent.MessageLike.RoomEncrypted -> fallbackNotifiableEvent(userId, roomId, eventId).also { + Timber.tag(loggerTag.value).w("Notification with encrypted content -> fallback") + } + NotificationContent.MessageLike.RoomRedaction -> null.also { + Timber.tag(loggerTag.value).d("Ignoring notification for redaction") + } + NotificationContent.MessageLike.Sticker -> null.also { + Timber.tag(loggerTag.value).d("Ignoring notification for sticker") + } + NotificationContent.StateEvent.PolicyRuleRoom, + NotificationContent.StateEvent.PolicyRuleServer, + NotificationContent.StateEvent.PolicyRuleUser, + NotificationContent.StateEvent.RoomAliases, + NotificationContent.StateEvent.RoomAvatar, + NotificationContent.StateEvent.RoomCanonicalAlias, + NotificationContent.StateEvent.RoomCreate, + NotificationContent.StateEvent.RoomEncryption, + NotificationContent.StateEvent.RoomGuestAccess, + NotificationContent.StateEvent.RoomHistoryVisibility, + NotificationContent.StateEvent.RoomJoinRules, + NotificationContent.StateEvent.RoomName, + NotificationContent.StateEvent.RoomPinnedEvents, + NotificationContent.StateEvent.RoomPowerLevels, + NotificationContent.StateEvent.RoomServerAcl, + NotificationContent.StateEvent.RoomThirdPartyInvite, + NotificationContent.StateEvent.RoomTombstone, + NotificationContent.StateEvent.RoomTopic, + NotificationContent.StateEvent.SpaceChild, + NotificationContent.StateEvent.SpaceParent -> null.also { + Timber.tag(loggerTag.value).d("Ignoring notification for state event ${content.javaClass.simpleName}") + } } }