From a47b589e72baf17584112386d69ae326fa8917e6 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Tue, 15 Mar 2022 17:51:02 +0300 Subject: [PATCH] Code review fixes. --- .../matrix/android/sdk/api/session/events/model/Event.kt | 2 ++ .../app/features/notifications/NotifiableEventResolver.kt | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt index c0ca40bc73..5e74ab09ab 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt @@ -406,3 +406,5 @@ fun Event.isInvitation(): Boolean = type == EventType.STATE_ROOM_MEMBER && fun Event.getPollContent(): MessagePollContent? { return content.toModel() } + +fun Event.supportsNotification() = this.getClearType() in EventType.MESSAGE + EventType.POLL_START diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt index 0897eace8c..3c9b985df5 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt @@ -31,6 +31,7 @@ import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.isEdition import org.matrix.android.sdk.api.session.events.model.isImageMessage +import org.matrix.android.sdk.api.session.events.model.supportsNotification import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomMemberContent @@ -94,7 +95,7 @@ class NotifiableEventResolver @Inject constructor( } suspend fun resolveInMemoryEvent(session: Session, event: Event, canBeReplaced: Boolean): NotifiableEvent? { - if (event.getClearType() !in listOf(EventType.MESSAGE, EventType.POLL_START)) return null + if (!event.supportsNotification()) return null // Ignore message edition if (event.isEdition()) return null @@ -154,7 +155,7 @@ class NotifiableEventResolver @Inject constructor( // only convert encrypted messages to NotifiableMessageEvents when (event.root.getClearType()) { EventType.MESSAGE, - EventType.POLL_START -> { + in EventType.POLL_START -> { val body = displayableEventFormatter.format(event, isDm = room.roomSummary()?.isDirect.orFalse(), appendAuthor = false).toString() val roomName = room.roomSummary()?.displayName ?: "" val senderDisplayName = event.senderInfo.disambiguatedDisplayName @@ -186,7 +187,7 @@ class NotifiableEventResolver @Inject constructor( soundName = null ) } - else -> null + else -> null } } }