Browse Source

Protect call to getNotificationItem

test/jme/compound-poc
Benoit Marty 1 year ago committed by Benoit Marty
parent
commit
7ff72d480c
  1. 2
      libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notification/NotificationService.kt
  2. 2
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt
  3. 11
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notification/RustNotificationService.kt
  4. 4
      libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/notification/FakeNotificationService.kt

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

@ -17,5 +17,5 @@ @@ -17,5 +17,5 @@
package io.element.android.libraries.matrix.api.notification
interface NotificationService {
fun getNotification(userId: String, roomId: String, eventId: String): NotificationData?
suspend fun getNotification(userId: String, roomId: String, eventId: String): Result<NotificationData?>
}

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

@ -68,7 +68,7 @@ class RustMatrixClient constructor( @@ -68,7 +68,7 @@ class RustMatrixClient constructor(
client = client,
dispatchers = dispatchers,
)
private val notificationService = RustNotificationService(baseDirectory)
private val notificationService = RustNotificationService(baseDirectory, dispatchers)
private var slidingSyncUpdateJob: Job? = null
private val clientDelegate = object : ClientDelegate {

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

@ -16,17 +16,22 @@ @@ -16,17 +16,22 @@
package io.element.android.libraries.matrix.impl.notification
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.matrix.api.notification.NotificationData
import io.element.android.libraries.matrix.api.notification.NotificationService
import kotlinx.coroutines.withContext
import java.io.File
class RustNotificationService(
private val baseDirectory: File,
private val dispatchers: CoroutineDispatchers,
) : NotificationService {
private val notificationMapper: NotificationMapper = NotificationMapper()
override fun getNotification(userId: String, roomId: String, eventId: String): NotificationData? {
return org.matrix.rustcomponents.sdk.NotificationService(
override suspend fun getNotification(userId: String, roomId: String, eventId: String): Result<NotificationData?> {
return withContext(dispatchers.io) {
runCatching {
org.matrix.rustcomponents.sdk.NotificationService(
basePath = File(baseDirectory, "sessions").absolutePath,
userId = userId
).use {
@ -36,4 +41,6 @@ class RustNotificationService( @@ -36,4 +41,6 @@ class RustNotificationService(
}
}
}
}
}
}

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

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

Loading…
Cancel
Save