Add ability to swipe between media when opened from the timeline.

This commit is contained in:
Benoit Marty 2025-01-28 09:58:34 +01:00
parent 9219b95e99
commit fdf40120a7
20 changed files with 485 additions and 82 deletions

View file

@ -118,8 +118,9 @@ interface MatrixRoom : Closeable {
/**
* Create a new timeline for the media events of the room.
* @param eventId The event to focus on, if any.
*/
suspend fun mediaTimeline(): Result<Timeline>
suspend fun mediaTimeline(eventId: EventId?): Result<Timeline>
fun destroy()

View file

@ -253,11 +253,21 @@ class RustMatrixRoom(
}
}
override suspend fun mediaTimeline(): Result<Timeline> = withContext(roomDispatcher) {
override suspend fun mediaTimeline(
eventId: EventId?,
): Result<Timeline> = withContext(roomDispatcher) {
val focus = if (eventId != null) {
TimelineFocus.Event(
eventId = eventId.value,
numContextEvents = 50u,
)
} else {
TimelineFocus.Live
}
runCatching {
innerRoom.timelineWithConfiguration(
configuration = TimelineConfiguration(
focus = TimelineFocus.Live,
focus = focus,
allowedMessageTypes = AllowedMessageTypes.Only(
types = listOf(
RoomMessageEventMessageType.FILE,
@ -270,7 +280,7 @@ class RustMatrixRoom(
dateDividerMode = DateDividerMode.MONTHLY,
)
).let { inner ->
createTimeline(inner, mode = Timeline.Mode.MEDIA)
createTimeline(inner, mode = if (eventId != null) Timeline.Mode.FOCUSED_ON_EVENT else Timeline.Mode.MEDIA)
}
}.onFailure {
if (it is CancellationException) {

View file

@ -137,7 +137,7 @@ class FakeMatrixRoom(
private val getMembersResult: (Int) -> Result<List<RoomMember>> = { lambdaError() },
private val timelineFocusedOnEventResult: (EventId) -> Result<Timeline> = { lambdaError() },
private val pinnedEventsTimelineResult: () -> Result<Timeline> = { lambdaError() },
private val mediaTimelineResult: () -> Result<Timeline> = { lambdaError() },
private val mediaTimelineResult: (EventId?) -> Result<Timeline> = { lambdaError() },
private val setSendQueueEnabledLambda: (Boolean) -> Unit = { _: Boolean -> },
private val saveComposerDraftLambda: (ComposerDraft) -> Result<Unit> = { _: ComposerDraft -> Result.success(Unit) },
private val loadComposerDraftLambda: () -> Result<ComposerDraft?> = { Result.success<ComposerDraft?>(null) },
@ -215,8 +215,8 @@ class FakeMatrixRoom(
pinnedEventsTimelineResult()
}
override suspend fun mediaTimeline(): Result<Timeline> = simulateLongTask {
mediaTimelineResult()
override suspend fun mediaTimeline(eventId: EventId?): Result<Timeline> = simulateLongTask {
mediaTimelineResult(eventId)
}
override suspend fun subscribeToSync() {