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

View file

@ -27,12 +27,12 @@ import org.matrix.rustcomponents.sdk.use
class NotificationMapper { class NotificationMapper {
private val timelineEventMapper = TimelineEventMapper() private val timelineEventMapper = TimelineEventMapper()
fun map(notificationItem: NotificationItem): NotificationData { fun map(roomId: RoomId, notificationItem: NotificationItem): NotificationData {
return notificationItem.use { item -> return notificationItem.use { item ->
NotificationData( NotificationData(
senderId = UserId(item.event.senderId()), senderId = UserId(item.event.senderId()),
eventId = EventId(item.event.eventId()), eventId = EventId(item.event.eventId()),
roomId = RoomId(item.roomInfo.id), roomId = roomId,
senderAvatarUrl = item.senderInfo.avatarUrl, senderAvatarUrl = item.senderInfo.avatarUrl,
senderDisplayName = item.senderInfo.displayName, senderDisplayName = item.senderInfo.displayName,
roomAvatarUrl = item.roomInfo.avatarUrl ?: item.senderInfo.avatarUrl.takeIf { item.roomInfo.isDirect }, 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.core.SessionId
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 org.matrix.rustcomponents.sdk.Client import org.matrix.rustcomponents.sdk.NotificationClient
import org.matrix.rustcomponents.sdk.use import org.matrix.rustcomponents.sdk.use
class RustNotificationService( class RustNotificationService(
private val client: Client, private val notificationClient: NotificationClient,
) : NotificationService { ) : NotificationService {
private val notificationMapper: NotificationMapper = NotificationMapper() private val notificationMapper: NotificationMapper = NotificationMapper()
@ -36,8 +36,10 @@ class RustNotificationService(
filterByPushRules: Boolean, filterByPushRules: Boolean,
): Result<NotificationData?> { ): Result<NotificationData?> {
return runCatching { return runCatching {
val item = client.getNotificationItem(roomId.value, eventId.value, filterByPushRules) val item = notificationClient.getNotification(roomId.value, eventId.value)
item?.use(notificationMapper::map) item?.use {
notificationMapper.map(roomId, it)
}
} }
} }
} }