Enable filter push notifications by push rules (#1041)

* Enable filter push notifications by push rules

* Remove unused `filterByPushRules` parameter

* Use fallback notification only for items not filetered by the push rules

* Fix tests
This commit is contained in:
Jorge Martin Espinosa
2023-08-09 14:12:39 +02:00
committed by GitHub
parent 3f1d241b48
commit 4e94d4da6b
6 changed files with 6 additions and 10 deletions

1
changelog.d/640.bugfix Normal file
View File

@@ -0,0 +1 @@
Filter push notifications using push rules.

View File

@@ -21,5 +21,5 @@ import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.core.SessionId
interface NotificationService {
suspend fun getNotification(userId: SessionId, roomId: RoomId, eventId: EventId, filterByPushRules: Boolean): Result<NotificationData?>
suspend fun getNotification(userId: SessionId, roomId: RoomId, eventId: EventId): Result<NotificationData?>
}

View File

@@ -100,7 +100,7 @@ class RustMatrixClient constructor(
dispatchers = dispatchers,
)
private val notificationClient = client.notificationClient().use { builder ->
builder.finish()
builder.filterByPushRules().finish()
}
private val notificationService = RustNotificationService(sessionId, notificationClient, dispatchers, clock)

View File

@@ -39,7 +39,6 @@ class RustNotificationService(
userId: SessionId,
roomId: RoomId,
eventId: EventId,
filterByPushRules: Boolean,
): Result<NotificationData?> = withContext(dispatchers.io) {
runCatching {
val item = notificationClient.getNotification(roomId.value, eventId.value)

View File

@@ -23,7 +23,7 @@ import io.element.android.libraries.matrix.api.notification.NotificationData
import io.element.android.libraries.matrix.api.notification.NotificationService
class FakeNotificationService : NotificationService {
override suspend fun getNotification(userId: SessionId, roomId: RoomId, eventId: EventId, filterByPushRules: Boolean): Result<NotificationData?> {
override suspend fun getNotification(userId: SessionId, roomId: RoomId, eventId: EventId): Result<NotificationData?> {
return Result.success(null)
}
}

View File

@@ -69,16 +69,12 @@ class NotifiableEventResolver @Inject constructor(
userId = sessionId,
roomId = roomId,
eventId = eventId,
// FIXME should be true in the future, but right now it's broken
// (https://github.com/vector-im/element-x-android/issues/640#issuecomment-1612913658)
filterByPushRules = false,
).onFailure {
Timber.tag(loggerTag.value).e(it, "Unable to resolve event: $eventId.")
}.getOrNull()
// TODO this notificationData is not always valid at the moment, sometimes the Rust SDK can't fetch the matching event
return notificationData?.asNotifiableEvent(sessionId)
?: fallbackNotifiableEvent(sessionId, roomId, eventId)
}
private fun NotificationData.asNotifiableEvent(userId: SessionId): NotifiableEvent? {
@@ -119,10 +115,10 @@ class NotifiableEventResolver @Inject constructor(
title = null, // TODO check if title is needed anymore
)
} else {
null
fallbackNotifiableEvent(userId, roomId, eventId)
}
}
else -> null
else -> fallbackNotifiableEvent(userId, roomId, eventId)
}
}