Files
ichmagmaus111andClaude Opus 5.5 0622057a4f Ghostgram: open-source release
Ghostgram for iOS, rebuilt from scratch on Telegram iOS 13.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 17:57:09 +01:00

37 lines
1.5 KiB
Swift

import Foundation
import Postbox
public extension ChatInputContent {
/// Every medium this content references, anywhere — including inside blockquotes and details.
/// Order is document order; duplicates are NOT removed (callers that need a set deduplicate by
/// `EngineMedia.Id`).
var allMedia: [EngineMedia] {
var result: [EngineMedia] = []
ChatInputContent.collectMedia(in: self.blocks, into: &result)
return result
}
private static func collectMedia(in blocks: [ChatInputBlock], into result: inout [EngineMedia]) {
for block in blocks {
switch block {
case let .media(media):
for item in media.items {
result.append(EngineMedia(item.media))
}
case let .blockQuote(quote):
collectMedia(in: quote.content.blocks, into: &result)
case let .details(details):
collectMedia(in: details.content.blocks, into: &result)
case .table:
// A ChatInputTableCell holds `runs: [ChatInputRun]`, not nested blocks, so a table
// cannot contain media on this side. (The EDITOR's TableBlock.Cell does have
// `blocks` — hence the different walk in RichTextAttachmentScreen. Do not copy one
// into the other.)
break
case .paragraph, .code, .pullQuote, .buttonRow:
break
}
}
}
}