Protect call to getNotificationItem
This commit is contained in:
parent
dae0cae8bb
commit
62db96476d
4 changed files with 19 additions and 12 deletions
|
|
@ -17,5 +17,5 @@
|
||||||
package io.element.android.libraries.matrix.api.notification
|
package io.element.android.libraries.matrix.api.notification
|
||||||
|
|
||||||
interface NotificationService {
|
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,
|
client = client,
|
||||||
dispatchers = dispatchers,
|
dispatchers = dispatchers,
|
||||||
)
|
)
|
||||||
private val notificationService = RustNotificationService(baseDirectory)
|
private val notificationService = RustNotificationService(baseDirectory, dispatchers)
|
||||||
private var slidingSyncUpdateJob: Job? = null
|
private var slidingSyncUpdateJob: Job? = null
|
||||||
|
|
||||||
private val clientDelegate = object : ClientDelegate {
|
private val clientDelegate = object : ClientDelegate {
|
||||||
|
|
|
||||||
|
|
@ -16,23 +16,30 @@
|
||||||
|
|
||||||
package io.element.android.libraries.matrix.impl.notification
|
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.NotificationData
|
||||||
import io.element.android.libraries.matrix.api.notification.NotificationService
|
import io.element.android.libraries.matrix.api.notification.NotificationService
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class RustNotificationService(
|
class RustNotificationService(
|
||||||
private val baseDirectory: File,
|
private val baseDirectory: File,
|
||||||
|
private val dispatchers: CoroutineDispatchers,
|
||||||
) : NotificationService {
|
) : NotificationService {
|
||||||
private val notificationMapper: NotificationMapper = NotificationMapper()
|
private val notificationMapper: NotificationMapper = NotificationMapper()
|
||||||
|
|
||||||
override fun getNotification(userId: String, roomId: String, eventId: String): NotificationData? {
|
override suspend fun getNotification(userId: String, roomId: String, eventId: String): Result<NotificationData?> {
|
||||||
return org.matrix.rustcomponents.sdk.NotificationService(
|
return withContext(dispatchers.io) {
|
||||||
basePath = File(baseDirectory, "sessions").absolutePath,
|
runCatching {
|
||||||
userId = userId
|
org.matrix.rustcomponents.sdk.NotificationService(
|
||||||
).use {
|
basePath = File(baseDirectory, "sessions").absolutePath,
|
||||||
// TODO Not implemented yet, see https://github.com/matrix-org/matrix-rust-sdk/issues/1628
|
userId = userId
|
||||||
it.getNotificationItem(roomId, eventId)?.let { notificationItem ->
|
).use {
|
||||||
notificationMapper.map(notificationItem)
|
// 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
|
import io.element.android.libraries.matrix.api.notification.NotificationService
|
||||||
|
|
||||||
class FakeNotificationService : NotificationService {
|
class FakeNotificationService : NotificationService {
|
||||||
override fun getNotification(userId: String, roomId: String, eventId: String): NotificationData? {
|
override suspend fun getNotification(userId: String, roomId: String, eventId: String): Result<NotificationData?> {
|
||||||
return null
|
return Result.success(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue