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'"
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
val value = extractField(rawJson, key) ?: return false

View File

@ -66,9 +66,6 @@ class NotifiableEventResolver @Inject constructor(
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? {
val roomID = event.roomId ?: return null
val eventId = event.eventId ?: return null
@ -76,9 +73,8 @@ class NotifiableEventResolver @Inject constructor(
return resolveStateRoomEvent(event, session, canBeReplaced = false, isNoisy = isNoisy)
}
val timelineEvent = session.getRoom(roomID)?.getTimelineEvent(eventId) ?: return null
return when (event.getClearType()) {
in nonEncryptedNotifiableEventTypes,
EventType.ENCRYPTED -> {
return when {
event.supportsNotification() || event.type == EventType.ENCRYPTED -> {
resolveMessageEvent(timelineEvent, session, canBeReplaced = false, isNoisy = isNoisy)
}
else -> {
@ -163,8 +159,8 @@ class NotifiableEventResolver @Inject constructor(
} else {
event.attemptToDecryptIfNeeded(session)
// only convert encrypted messages to NotifiableMessageEvents
when (event.root.getClearType()) {
in nonEncryptedNotifiableEventTypes -> {
when {
event.root.supportsNotification() -> {
val body = displayableEventFormatter.format(event, isDm = room.roomSummary()?.isDirect.orFalse(), appendAuthor = false).toString()
val roomName = room.roomSummary()?.displayName ?: ""
val senderDisplayName = event.senderInfo.disambiguatedDisplayName