Start integrating uptodate rust sdk and make it compile (WIP)
This commit is contained in:
parent
a4f9354e8a
commit
0f498a0290
34 changed files with 739 additions and 352 deletions
|
|
@ -31,6 +31,6 @@ object MatrixModule {
|
|||
@Provides
|
||||
@SingleIn(AppScope::class)
|
||||
fun providesRustAuthenticationService(baseDirectory: File): AuthenticationService {
|
||||
return AuthenticationService(baseDirectory.absolutePath)
|
||||
return AuthenticationService(baseDirectory.absolutePath, null)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,6 +158,12 @@ internal class RustRoomSummaryDataSource(
|
|||
clear()
|
||||
addAll(diff.values.map { buildSummaryForRoomListEntry(it) })
|
||||
}
|
||||
SlidingSyncViewRoomsListDiff.Pop -> {
|
||||
removeLastOrNull()
|
||||
}
|
||||
SlidingSyncViewRoomsListDiff.Clear -> {
|
||||
clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class RoomMessageFactory {
|
|||
eventId = EventId(eventTimelineItem.eventId() ?: ""),
|
||||
body = eventTimelineItem.content().asMessage()?.body() ?: "",
|
||||
sender = UserId(eventTimelineItem.sender()),
|
||||
originServerTs = eventTimelineItem.originServerTs()?.toLong() ?: 0L
|
||||
originServerTs = eventTimelineItem.timestamp().toLong()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import org.matrix.rustcomponents.sdk.TimelineListener
|
|||
|
||||
interface MatrixTimeline {
|
||||
var callback: Callback?
|
||||
val hasMoreToLoad: Boolean
|
||||
|
||||
interface Callback {
|
||||
fun onUpdatedTimelineItem(timelineItem: MatrixTimelineItem) = Unit
|
||||
|
|
@ -30,7 +29,7 @@ interface MatrixTimeline {
|
|||
}
|
||||
|
||||
fun timelineItems(): Flow<List<MatrixTimelineItem>>
|
||||
suspend fun paginateBackwards(count: Int): Result<Unit>
|
||||
suspend fun paginateBackwards(requestSize: Int, untilNumberOfItems: Int): Result<Unit>
|
||||
fun addListener(timelineListener: TimelineListener)
|
||||
fun initialize()
|
||||
fun dispose()
|
||||
|
|
|
|||
|
|
@ -18,15 +18,10 @@ package io.element.android.libraries.matrix.timeline
|
|||
|
||||
import org.matrix.rustcomponents.sdk.EventTimelineItem
|
||||
import org.matrix.rustcomponents.sdk.TimelineItem
|
||||
import org.matrix.rustcomponents.sdk.TimelineKey
|
||||
|
||||
sealed interface MatrixTimelineItem {
|
||||
data class Event(val event: EventTimelineItem) : MatrixTimelineItem {
|
||||
val uniqueId: String
|
||||
get() = when (val eventKey = event.key()) {
|
||||
is TimelineKey.TransactionId -> eventKey.txnId
|
||||
is TimelineKey.EventId -> eventKey.eventId
|
||||
}
|
||||
val uniqueId: String = event.uniqueIdentifier()
|
||||
}
|
||||
|
||||
object Virtual : MatrixTimelineItem
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.element.android.libraries.matrix.timeline
|
|||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.matrix.core.EventId
|
||||
import io.element.android.libraries.matrix.room.RustMatrixRoom
|
||||
import io.element.android.libraries.matrix.util.StoppableSpawnBag
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
|
@ -26,14 +27,14 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||
import kotlinx.coroutines.flow.sample
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.matrix.rustcomponents.sdk.PaginationOutcome
|
||||
import org.matrix.rustcomponents.sdk.PaginationOptions
|
||||
import org.matrix.rustcomponents.sdk.Room
|
||||
import org.matrix.rustcomponents.sdk.SlidingSyncRoom
|
||||
import org.matrix.rustcomponents.sdk.TimelineChange
|
||||
import org.matrix.rustcomponents.sdk.TimelineDiff
|
||||
import org.matrix.rustcomponents.sdk.TimelineListener
|
||||
import timber.log.Timber
|
||||
import java.util.Collections
|
||||
import java.util.*
|
||||
|
||||
class RustMatrixTimeline(
|
||||
private val matrixRoom: RustMatrixRoom,
|
||||
|
|
@ -45,20 +46,16 @@ class RustMatrixTimeline(
|
|||
|
||||
override var callback: MatrixTimeline.Callback? = null
|
||||
|
||||
private val paginationOutcome = MutableStateFlow(PaginationOutcome(true))
|
||||
private val timelineItems: MutableStateFlow<List<MatrixTimelineItem>> =
|
||||
MutableStateFlow(emptyList())
|
||||
|
||||
private val listenerTokens = StoppableSpawnBag()
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
override fun timelineItems(): Flow<List<MatrixTimelineItem>> {
|
||||
return timelineItems.sample(50)
|
||||
}
|
||||
|
||||
override val hasMoreToLoad: Boolean
|
||||
get() {
|
||||
return paginationOutcome.value.moreMessages
|
||||
}
|
||||
|
||||
private fun MutableList<MatrixTimelineItem>.applyDiff(diff: TimelineDiff) {
|
||||
when (diff.change()) {
|
||||
TimelineChange.PUSH -> {
|
||||
|
|
@ -107,12 +104,13 @@ class RustMatrixTimeline(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun paginateBackwards(count: Int): Result<Unit> = withContext(coroutineDispatchers.io) {
|
||||
if (!paginationOutcome.value.moreMessages) {
|
||||
return@withContext Result.failure(IllegalStateException("no more message"))
|
||||
}
|
||||
override suspend fun paginateBackwards(requestSize: Int, untilNumberOfItems: Int): Result<Unit> = withContext(coroutineDispatchers.io) {
|
||||
runCatching {
|
||||
paginationOutcome.value = room.paginateBackwards(count.toUShort())
|
||||
val paginationOptions = PaginationOptions.UntilNumItems(
|
||||
eventLimit = requestSize.toUShort(),
|
||||
items = untilNumberOfItems.toUShort()
|
||||
)
|
||||
room.paginateBackwards(paginationOptions)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -124,7 +122,7 @@ class RustMatrixTimeline(
|
|||
}
|
||||
|
||||
override fun addListener(timelineListener: TimelineListener) {
|
||||
slidingSyncRoom.addTimelineListener(timelineListener)
|
||||
listenerTokens += slidingSyncRoom.subscribeAndAddTimelineListener(timelineListener, settings = null)
|
||||
}
|
||||
|
||||
override fun initialize() {
|
||||
|
|
@ -132,7 +130,7 @@ class RustMatrixTimeline(
|
|||
}
|
||||
|
||||
override fun dispose() {
|
||||
slidingSyncRoom.removeTimeline()
|
||||
listenerTokens.dispose()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.util
|
||||
|
||||
import org.matrix.rustcomponents.sdk.StoppableSpawn
|
||||
import java.util.concurrent.CopyOnWriteArraySet
|
||||
|
||||
class StoppableSpawnBag(private val tokens: MutableSet<StoppableSpawn> = CopyOnWriteArraySet()) : Set<StoppableSpawn> by tokens {
|
||||
|
||||
operator fun plusAssign(stoppableSpawn: StoppableSpawn?) {
|
||||
if (stoppableSpawn == null) return
|
||||
tokens += stoppableSpawn
|
||||
}
|
||||
|
||||
fun dispose() {
|
||||
tokens.forEach { it.cancel() }
|
||||
tokens.clear()
|
||||
}
|
||||
}
|
||||
|
|
@ -29,14 +29,11 @@ class FakeMatrixTimeline : MatrixTimeline {
|
|||
get() = null
|
||||
set(value) {}
|
||||
|
||||
override val hasMoreToLoad: Boolean
|
||||
get() = true
|
||||
|
||||
override fun timelineItems(): Flow<List<MatrixTimelineItem>> {
|
||||
return emptyFlow()
|
||||
}
|
||||
|
||||
override suspend fun paginateBackwards(count: Int): Result<Unit> {
|
||||
override suspend fun paginateBackwards(requestSize: Int, untilNumberOfItems: Int): Result<Unit> {
|
||||
return Result.success(Unit)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue