Update rust sdk to 0.1.31: new notification api

This commit is contained in:
ganfra
2023-07-12 16:05:36 +02:00
parent 655c5a5ed5
commit d3a86bffee
3 changed files with 14 additions and 8 deletions

View File

@@ -94,8 +94,11 @@ class RustMatrixClient constructor(
client = client,
dispatchers = dispatchers,
)
private val notificationService = RustNotificationService(client)
private val notificationClient = client.notificationClient().use { builder ->
builder.finish()
}
private val notificationService = RustNotificationService(notificationClient)
private val clientDelegate = object : ClientDelegate {
override fun didReceiveAuthError(isSoftLogout: Boolean) {
@@ -250,6 +253,7 @@ class RustMatrixClient constructor(
client.setDelegate(null)
verificationService.destroy()
roomListService.destroy()
notificationClient.destroy()
client.destroy()
}

View File

@@ -27,12 +27,12 @@ import org.matrix.rustcomponents.sdk.use
class NotificationMapper {
private val timelineEventMapper = TimelineEventMapper()
fun map(notificationItem: NotificationItem): NotificationData {
fun map(roomId: RoomId, notificationItem: NotificationItem): NotificationData {
return notificationItem.use { item ->
NotificationData(
senderId = UserId(item.event.senderId()),
eventId = EventId(item.event.eventId()),
roomId = RoomId(item.roomInfo.id),
roomId = roomId,
senderAvatarUrl = item.senderInfo.avatarUrl,
senderDisplayName = item.senderInfo.displayName,
roomAvatarUrl = item.roomInfo.avatarUrl ?: item.senderInfo.avatarUrl.takeIf { item.roomInfo.isDirect },

View File

@@ -21,11 +21,11 @@ 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.notification.NotificationData
import io.element.android.libraries.matrix.api.notification.NotificationService
import org.matrix.rustcomponents.sdk.Client
import org.matrix.rustcomponents.sdk.NotificationClient
import org.matrix.rustcomponents.sdk.use
class RustNotificationService(
private val client: Client,
private val notificationClient: NotificationClient,
) : NotificationService {
private val notificationMapper: NotificationMapper = NotificationMapper()
@@ -36,8 +36,10 @@ class RustNotificationService(
filterByPushRules: Boolean,
): Result<NotificationData?> {
return runCatching {
val item = client.getNotificationItem(roomId.value, eventId.value, filterByPushRules)
item?.use(notificationMapper::map)
val item = notificationClient.getNotification(roomId.value, eventId.value)
item?.use {
notificationMapper.map(roomId, it)
}
}
}
}