Browse Source

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
pull/1044/head
Jorge Martin Espinosa 1 year ago committed by GitHub
parent
commit
2131af28d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      changelog.d/640.bugfix
  2. 2
      libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notification/NotificationService.kt
  3. 2
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt
  4. 1
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notification/RustNotificationService.kt
  5. 2
      libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/notification/FakeNotificationService.kt
  6. 8
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotifiableEventResolver.kt

1
changelog.d/640.bugfix

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

2
libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notification/NotificationService.kt

@ -21,5 +21,5 @@ import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.core.SessionId import io.element.android.libraries.matrix.api.core.SessionId
interface NotificationService { 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?>
} }

2
libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt

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

1
libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notification/RustNotificationService.kt

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

2
libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/notification/FakeNotificationService.kt

@ -23,7 +23,7 @@ import io.element.android.libraries.matrix.api.notification.NotificationData
import io.element.android.libraries.matrix.api.notification.NotificationService import io.element.android.libraries.matrix.api.notification.NotificationService
class FakeNotificationService : 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) return Result.success(null)
} }
} }

8
libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotifiableEventResolver.kt

@ -69,16 +69,12 @@ class NotifiableEventResolver @Inject constructor(
userId = sessionId, userId = sessionId,
roomId = roomId, roomId = roomId,
eventId = eventId, 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 { ).onFailure {
Timber.tag(loggerTag.value).e(it, "Unable to resolve event: $eventId.") Timber.tag(loggerTag.value).e(it, "Unable to resolve event: $eventId.")
}.getOrNull() }.getOrNull()
// TODO this notificationData is not always valid at the moment, sometimes the Rust SDK can't fetch the matching event // TODO this notificationData is not always valid at the moment, sometimes the Rust SDK can't fetch the matching event
return notificationData?.asNotifiableEvent(sessionId) return notificationData?.asNotifiableEvent(sessionId)
?: fallbackNotifiableEvent(sessionId, roomId, eventId)
} }
private fun NotificationData.asNotifiableEvent(userId: SessionId): NotifiableEvent? { private fun NotificationData.asNotifiableEvent(userId: SessionId): NotifiableEvent? {
@ -119,10 +115,10 @@ class NotifiableEventResolver @Inject constructor(
title = null, // TODO check if title is needed anymore title = null, // TODO check if title is needed anymore
) )
} else { } else {
null fallbackNotifiableEvent(userId, roomId, eventId)
} }
} }
else -> null else -> fallbackNotifiableEvent(userId, roomId, eventId)
} }
} }

Loading…
Cancel
Save