Protect call to getNotificationItem
This commit is contained in:
committed by
Benoit Marty
parent
dae0cae8bb
commit
62db96476d
@@ -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?>
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -16,23 +16,30 @@
|
||||
|
||||
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(
|
||||
basePath = File(baseDirectory, "sessions").absolutePath,
|
||||
userId = userId
|
||||
).use {
|
||||
// TODO Not implemented yet, see https://github.com/matrix-org/matrix-rust-sdk/issues/1628
|
||||
it.getNotificationItem(roomId, eventId)?.let { notificationItem ->
|
||||
notificationMapper.map(notificationItem)
|
||||
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 {
|
||||
// TODO Not implemented yet, see https://github.com/matrix-org/matrix-rust-sdk/issues/1628
|
||||
it.getNotificationItem(roomId, eventId)?.let { notificationItem ->
|
||||
notificationMapper.map(notificationItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user