|
|
@ -26,10 +26,10 @@ import kotlinx.coroutines.channels.trySendBlocking |
|
|
|
import kotlinx.coroutines.flow.Flow |
|
|
|
import kotlinx.coroutines.flow.Flow |
|
|
|
import kotlinx.coroutines.flow.buffer |
|
|
|
import kotlinx.coroutines.flow.buffer |
|
|
|
import kotlinx.coroutines.flow.callbackFlow |
|
|
|
import kotlinx.coroutines.flow.callbackFlow |
|
|
|
|
|
|
|
import kotlinx.coroutines.flow.catch |
|
|
|
import org.matrix.rustcomponents.sdk.BackPaginationStatus |
|
|
|
import org.matrix.rustcomponents.sdk.BackPaginationStatus |
|
|
|
import org.matrix.rustcomponents.sdk.BackPaginationStatusListener |
|
|
|
import org.matrix.rustcomponents.sdk.BackPaginationStatusListener |
|
|
|
import org.matrix.rustcomponents.sdk.Room |
|
|
|
import org.matrix.rustcomponents.sdk.Room |
|
|
|
import org.matrix.rustcomponents.sdk.RoomTimelineListenerResult |
|
|
|
|
|
|
|
import org.matrix.rustcomponents.sdk.TimelineDiff |
|
|
|
import org.matrix.rustcomponents.sdk.TimelineDiff |
|
|
|
import org.matrix.rustcomponents.sdk.TimelineItem |
|
|
|
import org.matrix.rustcomponents.sdk.TimelineItem |
|
|
|
import org.matrix.rustcomponents.sdk.TimelineListener |
|
|
|
import org.matrix.rustcomponents.sdk.TimelineListener |
|
|
@ -42,20 +42,21 @@ internal fun Room.timelineDiffFlow(onInitialList: suspend (List<TimelineItem>) - |
|
|
|
trySendBlocking(diff) |
|
|
|
trySendBlocking(diff) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
var result: RoomTimelineListenerResult? = null |
|
|
|
val roomId = id() |
|
|
|
val roomId = tryOrNull { id() } |
|
|
|
|
|
|
|
Timber.d("Open timelineDiffFlow for room $roomId") |
|
|
|
Timber.d("Open timelineDiffFlow for room $roomId") |
|
|
|
|
|
|
|
val result = addTimelineListener(listener) |
|
|
|
try { |
|
|
|
try { |
|
|
|
result = addTimelineListener(listener) |
|
|
|
|
|
|
|
onInitialList(result.items) |
|
|
|
onInitialList(result.items) |
|
|
|
} catch (exception: Exception) { |
|
|
|
} catch (exception: Exception) { |
|
|
|
Timber.d(exception, "Catch failure in timelineDiffFlow of room $roomId") |
|
|
|
Timber.d(exception, "Catch failure in timelineDiffFlow of room $roomId") |
|
|
|
} |
|
|
|
} |
|
|
|
awaitClose { |
|
|
|
awaitClose { |
|
|
|
Timber.d("Close timelineDiffFlow for room $roomId") |
|
|
|
Timber.d("Close timelineDiffFlow for room $roomId") |
|
|
|
result?.itemsStream?.cancelAndDestroy() |
|
|
|
result.itemsStream.cancelAndDestroy() |
|
|
|
result?.items?.destroyAll() |
|
|
|
result.items.destroyAll() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}.catch { |
|
|
|
|
|
|
|
Timber.d(it, "timelineDiffFlow() failed") |
|
|
|
}.buffer(Channel.UNLIMITED) |
|
|
|
}.buffer(Channel.UNLIMITED) |
|
|
|
|
|
|
|
|
|
|
|
internal fun Room.backPaginationStatusFlow(): Flow<BackPaginationStatus> = |
|
|
|
internal fun Room.backPaginationStatusFlow(): Flow<BackPaginationStatus> = |
|
|
|