Reuse event.supportsNotification extension

This commit is contained in:
Florian Renaud 2023-02-24 09:26:50 +01:00
parent b6ac915805
commit 9d7758c9e3
2 changed files with 7 additions and 10 deletions

View File

@ -39,7 +39,8 @@ class EventMatchCondition(
override fun technicalDescription() = "'$key' matches '$pattern'" override fun technicalDescription() = "'$key' matches '$pattern'"
fun isSatisfied(event: Event): Boolean { fun isSatisfied(event: Event): Boolean {
val rawJson: Map<*, *> = event.mxDecryptionResult?.payload ?: MoshiProvider.providesMoshi().adapter(Event::class.java).toJsonValue(event) as? Map<*, *> val rawJson: Map<*, *> = event.mxDecryptionResult?.payload
?: MoshiProvider.providesMoshi().adapter(Event::class.java).toJsonValue(event) as? Map<*, *>
?: return false ?: return false
val value = extractField(rawJson, key) ?: return false val value = extractField(rawJson, key) ?: return false

View File

@ -66,9 +66,6 @@ class NotifiableEventResolver @Inject constructor(
private val buildMeta: BuildMeta, private val buildMeta: BuildMeta,
) { ) {
private val nonEncryptedNotifiableEventTypes: List<String> =
listOf(EventType.MESSAGE) + EventType.POLL_START.values + EventType.POLL_END.values + EventType.STATE_ROOM_BEACON_INFO.values
suspend fun resolveEvent(event: Event, session: Session, isNoisy: Boolean): NotifiableEvent? { suspend fun resolveEvent(event: Event, session: Session, isNoisy: Boolean): NotifiableEvent? {
val roomID = event.roomId ?: return null val roomID = event.roomId ?: return null
val eventId = event.eventId ?: return null val eventId = event.eventId ?: return null
@ -76,9 +73,8 @@ class NotifiableEventResolver @Inject constructor(
return resolveStateRoomEvent(event, session, canBeReplaced = false, isNoisy = isNoisy) return resolveStateRoomEvent(event, session, canBeReplaced = false, isNoisy = isNoisy)
} }
val timelineEvent = session.getRoom(roomID)?.getTimelineEvent(eventId) ?: return null val timelineEvent = session.getRoom(roomID)?.getTimelineEvent(eventId) ?: return null
return when (event.getClearType()) { return when {
in nonEncryptedNotifiableEventTypes, event.supportsNotification() || event.type == EventType.ENCRYPTED -> {
EventType.ENCRYPTED -> {
resolveMessageEvent(timelineEvent, session, canBeReplaced = false, isNoisy = isNoisy) resolveMessageEvent(timelineEvent, session, canBeReplaced = false, isNoisy = isNoisy)
} }
else -> { else -> {
@ -163,8 +159,8 @@ class NotifiableEventResolver @Inject constructor(
} else { } else {
event.attemptToDecryptIfNeeded(session) event.attemptToDecryptIfNeeded(session)
// only convert encrypted messages to NotifiableMessageEvents // only convert encrypted messages to NotifiableMessageEvents
when (event.root.getClearType()) { when {
in nonEncryptedNotifiableEventTypes -> { event.root.supportsNotification() -> {
val body = displayableEventFormatter.format(event, isDm = room.roomSummary()?.isDirect.orFalse(), appendAuthor = false).toString() val body = displayableEventFormatter.format(event, isDm = room.roomSummary()?.isDirect.orFalse(), appendAuthor = false).toString()
val roomName = room.roomSummary()?.displayName ?: "" val roomName = room.roomSummary()?.displayName ?: ""
val senderDisplayName = event.senderInfo.disambiguatedDisplayName val senderDisplayName = event.senderInfo.disambiguatedDisplayName