Minor quicklook fixes. (#6112)

* Only show a spinner when opening the media viewer is slow

* Keep a sent local echo's page in the media viewer

* Fix the caption visibility.

---------

Co-authored-by: Stefan Ceriu <stefan.ceriu@gmail.com>
Co-authored-by: Matthew Hodgson <matthew@matrix.org>
This commit is contained in:
Doug
2026-09-08 09:40:43 +01:00
committed by GitHub
parent 1af16e92db
commit 15627e4512
4 changed files with 112 additions and 10 deletions
@@ -343,6 +343,41 @@ struct TimelineMediaPreviewDataSourceTests {
.filter { !($0 is GalleryRoomTimelineItem) } // Galleries are previewed through their own data source.
}
@Test
func sentLocalEchoKeepsItsPage() async throws {
// Given a viewer opened on an upload in flight: a local echo with a transaction ID.
let uniqueID = TimelineItemIdentifier.UniqueID(UUID().uuidString)
func makeUpload(id: TimelineItemIdentifier.EventOrTransactionID) -> ImageRoomTimelineItem {
ImageRoomTimelineItem(id: .event(uniqueID: uniqueID, eventOrTransactionID: id),
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: false,
sender: .init(id: "Alice"),
content: .init(filename: "upload.jpg", imageInfo: .mockImage, thumbnailInfo: nil, blurhash: nil))
}
let localEcho = makeUpload(id: .transactionID("t1"))
var items = newChunk()
items.append(localEcho)
let dataSource = TimelineMediaPreviewDataSource(itemViewStates: items.map { RoomTimelineItemViewState(item: $0, groupStyle: .single) },
initialItem: localEcho,
paginationState: .initial)
let page = try #require(dataSource.currentItem.mediaItem)
#expect(page.id == .timelineItem(.transactionID("t1")))
// When the upload completes and the timeline swaps the echo's transaction ID for its event ID.
items[items.count - 1] = makeUpload(id: .eventID("$e1"))
let deferred = deferFailure(dataSource.previewItemsPaginationPublisher, timeout: .seconds(1)) { _ in true }
dataSource.updatePreviewItems(itemViewStates: items.map { RoomTimelineItemViewState(item: $0, groupStyle: .single) })
try await deferred.fulfill()
// Then the same page carries on under the new ID (its file came from the local media cache), nothing rebuilt.
#expect(dataSource.currentItem.mediaItem === page)
#expect(page.id == .timelineItem(.eventID("$e1")))
#expect(dataSource.previewItems.map(\.id).last == .timelineItem(.eventID("$e1")))
#expect(dataSource.previewItems.count == items.count)
}
@discardableResult
private func assertInitialDataSource() throws -> TimelineMediaPreviewDataSource {
// Given a data source built with the initial items.