making the noisy property immutable

This commit is contained in:
Adam Brown 2021-10-07 11:52:54 +01:00
parent c99dd4a615
commit db5d4ead38
6 changed files with 14 additions and 26 deletions

View file

@ -20,7 +20,7 @@ data class InviteNotifiableEvent(
override val eventId: String,
override val editedEventId: String?,
val roomId: String,
override var noisy: Boolean,
val noisy: Boolean,
val title: String,
val description: String,
val type: String?,

View file

@ -23,7 +23,6 @@ import java.io.Serializable
sealed interface NotifiableEvent : Serializable {
val eventId: String
val editedEventId: String?
var noisy: Boolean
var hasBeenDisplayed: Boolean
// Used to know if event should be replaced with the one coming from eventstream
var isPushGatewayEvent: Boolean

View file

@ -53,19 +53,19 @@ class NotifiableEventResolver @Inject constructor(
// private val eventDisplay = RiotEventDisplay(context)
fun resolveEvent(event: Event/*, roomState: RoomState?, bingRule: PushRule?*/, session: Session): NotifiableEvent? {
fun resolveEvent(event: Event/*, roomState: RoomState?, bingRule: PushRule?*/, session: Session, isNoisy: Boolean): NotifiableEvent? {
val roomID = event.roomId ?: return null
val eventId = event.eventId ?: return null
if (event.getClearType() == EventType.STATE_ROOM_MEMBER) {
return resolveStateRoomEvent(event, session)
return resolveStateRoomEvent(event, session, isNoisy)
}
val timelineEvent = session.getRoom(roomID)?.getTimeLineEvent(eventId) ?: return null
when (event.getClearType()) {
EventType.MESSAGE -> {
return resolveMessageEvent(timelineEvent, session)
return resolveMessageEvent(timelineEvent, session, isNoisy)
}
EventType.ENCRYPTED -> {
return resolveMessageEvent(timelineEvent, session)
return resolveMessageEvent(timelineEvent, session, isNoisy)
}
else -> {
// If the event can be displayed, display it as is
@ -111,24 +111,14 @@ class NotifiableEventResolver @Inject constructor(
avatarUrl = user.avatarUrl
)
)
val notifiableEvent = resolveMessageEvent(timelineEvent, session)
if (notifiableEvent == null) {
Timber.d("## Failed to resolve event")
// TODO
null
} else {
notifiableEvent.noisy = !notificationAction.soundName.isNullOrBlank()
notifiableEvent
}
resolveMessageEvent(timelineEvent, session, isNoisy = !notificationAction.soundName.isNullOrBlank())
} else {
Timber.d("Matched push rule is set to not notify")
null
}
}
private fun resolveMessageEvent(event: TimelineEvent, session: Session): NotifiableEvent? {
private fun resolveMessageEvent(event: TimelineEvent, session: Session, isNoisy: Boolean): NotifiableEvent {
// The event only contains an eventId, and roomId (type is m.room.*) , we need to get the displayable content (names, avatar, text, etc...)
val room = session.getRoom(event.root.roomId!! /*roomID cannot be null*/)
@ -143,7 +133,7 @@ class NotifiableEventResolver @Inject constructor(
eventId = event.root.eventId!!,
editedEventId = event.getEditedEventId(),
timestamp = event.root.originServerTs ?: 0,
noisy = false, // will be updated
noisy = isNoisy,
senderName = senderDisplayName,
senderId = event.root.senderId,
body = body.toString(),
@ -175,7 +165,7 @@ class NotifiableEventResolver @Inject constructor(
eventId = event.root.eventId!!,
editedEventId = event.getEditedEventId(),
timestamp = event.root.originServerTs ?: 0,
noisy = false, // will be updated
noisy = isNoisy,
senderName = senderDisplayName,
senderId = event.root.senderId,
body = body,
@ -198,7 +188,7 @@ class NotifiableEventResolver @Inject constructor(
}
}
private fun resolveStateRoomEvent(event: Event, session: Session): NotifiableEvent? {
private fun resolveStateRoomEvent(event: Event, session: Session, isNoisy: Boolean): NotifiableEvent? {
val content = event.content?.toModel<RoomMemberContent>() ?: return null
val roomId = event.roomId ?: return null
val dName = event.senderId?.let { session.getRoomMember(it, roomId)?.displayName }
@ -211,7 +201,7 @@ class NotifiableEventResolver @Inject constructor(
editedEventId = null,
roomId = roomId,
timestamp = event.originServerTs ?: 0,
noisy = false, // will be set later
noisy = isNoisy,
title = stringProvider.getString(R.string.notification_new_invitation),
description = body.toString(),
soundName = null, // will be set later

View file

@ -20,7 +20,7 @@ import org.matrix.android.sdk.api.session.events.model.EventType
data class NotifiableMessageEvent(
override val eventId: String,
override val editedEventId: String?,
override var noisy: Boolean,
val noisy: Boolean,
val timestamp: Long,
val senderName: String?,
val senderId: String?,

View file

@ -40,12 +40,11 @@ class PushRuleTriggerListener @Inject constructor(
val notificationAction = actions.toNotificationAction()
if (notificationAction.shouldNotify) {
val notifiableEvent = resolver.resolveEvent(event, safeSession)
val notifiableEvent = resolver.resolveEvent(event, safeSession, isNoisy = !notificationAction.soundName.isNullOrBlank())
if (notifiableEvent == null) {
Timber.v("## Failed to resolve event")
// TODO
} else {
notifiableEvent.noisy = !notificationAction.soundName.isNullOrBlank()
Timber.v("New event to notify")
notificationDrawerManager.onNotifiableEventReceived(notifiableEvent)
}

View file

@ -19,7 +19,7 @@ data class SimpleNotifiableEvent(
val matrixID: String?,
override val eventId: String,
override val editedEventId: String?,
override var noisy: Boolean,
val noisy: Boolean,
val title: String,
val description: String,
val type: String?,