unified the filtering of the gallery items

This commit is contained in:
Mauro Romito
2026-07-30 15:18:59 +02:00
committed by Mauro
parent 68a277143a
commit b044764310
6 changed files with 47 additions and 27 deletions
@@ -15,6 +15,21 @@ nonisolated struct GalleryRoomTimelineItemContent: Hashable {
/// The original textual representation of the formatted caption directly from the event (usually HTML code)
var formattedCaptionHTMLString: String?
let items: [GalleryItem]
/// The attachments of the given types, paired with their position in the gallery so that they remain
/// identifiable once separated from it. Attachments of an unknown type are never included as there's
/// nothing to show for them.
/// - Parameter allowedTypes: The types to include, or `nil` to include them all.
func attachments(allowedTypes: [TimelineAllowedGalleryItemType]?) -> [(mediaIndex: Int, item: GalleryItem)] {
items.enumerated().compactMap { mediaIndex, item in
guard let allowedItemType = item.allowedItemType,
allowedTypes?.contains(allowedItemType) ?? true else {
return nil
}
return (mediaIndex, item)
}
}
}
/// Identifies a single attachment within a gallery message.