diff --git a/submodules/InstantPageUI/Sources/InstantPageV2Layout.swift b/submodules/InstantPageUI/Sources/InstantPageV2Layout.swift index a3eca4e24b..698029dd77 100644 --- a/submodules/InstantPageUI/Sources/InstantPageV2Layout.swift +++ b/submodules/InstantPageUI/Sources/InstantPageV2Layout.swift @@ -889,6 +889,8 @@ private func layoutBlock( context: &context) // Block kinds filled in by later tasks: + case .thinking: + return [] case .unsupported: return [] } diff --git a/submodules/TelegramCore/FlatSerialization/Models/InstantPageBlock.fbs b/submodules/TelegramCore/FlatSerialization/Models/InstantPageBlock.fbs index eb51bad065..07f74e3963 100644 --- a/submodules/TelegramCore/FlatSerialization/Models/InstantPageBlock.fbs +++ b/submodules/TelegramCore/FlatSerialization/Models/InstantPageBlock.fbs @@ -36,7 +36,8 @@ union InstantPageBlock_Value { InstantPageBlock_RelatedArticles, InstantPageBlock_Map, InstantPageBlock_Heading, - InstantPageBlock_Formula + InstantPageBlock_Formula, + InstantPageBlock_Thinking } table InstantPageBlock { @@ -197,6 +198,10 @@ table InstantPageBlock_Formula { latex:string (id: 0, required); } +table InstantPageBlock_Thinking { + text:RichText (id: 0, required); +} + table InstantPageCaption { text:RichText (id: 0, required); credit:RichText (id: 1, required); diff --git a/submodules/TelegramCore/Sources/ApiUtils/InstantPage.swift b/submodules/TelegramCore/Sources/ApiUtils/InstantPage.swift index 4241837632..a5d4d4ad1f 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/InstantPage.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/InstantPage.swift @@ -328,14 +328,16 @@ extension InstantPageBlock { self = .heading(text: RichText(apiText: pageBlockHeading6.text), level: 6) case let .pageBlockMath(pageBlockMath): self = .formula(latex: pageBlockMath.source) - case .inputPageBlockMap, .pageBlockThinking: + case let .pageBlockThinking(pageBlockThinking): + self = .thinking(RichText(apiText: pageBlockThinking.text)) + case .inputPageBlockMap: self = .unsupported } } func apiInputBlock() -> Api.PageBlock? { switch self { - case .unsupported, .title, .subtitle, .kicker, .header, .subheader, .cover, .channelBanner, .authorDate, .relatedArticles, .webEmbed, .postEmbed: + case .unsupported, .title, .subtitle, .kicker, .header, .subheader, .cover, .channelBanner, .authorDate, .relatedArticles, .webEmbed, .postEmbed, .thinking: return nil case let .heading(text, level): let block: Api.PageBlock diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_InstantPage.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_InstantPage.swift index 87e276953f..2cd8dbe974 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_InstantPage.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_InstantPage.swift @@ -34,6 +34,7 @@ private enum InstantPageBlockType: Int32 { case map = 27 case heading = 28 case formula = 29 + case thinking = 30 } private func decodeListItems(_ decoder: PostboxDecoder) -> [InstantPageListItem] { @@ -82,6 +83,7 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable { case slideshow(items: [InstantPageBlock], caption: InstantPageCaption) case channelBanner(TelegramChannel?) case kicker(RichText) + case thinking(RichText) case table(title: RichText, rows: [InstantPageTableRow], bordered: Bool, striped: Bool) case details(title: RichText, blocks: [InstantPageBlock], expanded: Bool) case relatedArticles(title: RichText, articles: [InstantPageRelatedArticle]) @@ -168,6 +170,8 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable { self = .audio(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decodeCaption(decoder)) case InstantPageBlockType.kicker.rawValue: self = .kicker(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case InstantPageBlockType.thinking.rawValue: + self = .thinking(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) case InstantPageBlockType.table.rawValue: self = .table(title: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, rows: decoder.decodeObjectArrayWithDecoderForKey("r"), bordered: decoder.decodeInt32ForKey("b", orElse: 0) != 0, striped: decoder.decodeInt32ForKey("s", orElse: 0) != 0) case InstantPageBlockType.details.rawValue: @@ -339,6 +343,9 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable { case let .kicker(text): encoder.encodeInt32(InstantPageBlockType.kicker.rawValue, forKey: "r") encoder.encodeObject(text, forKey: "t") + case let .thinking(text): + encoder.encodeInt32(InstantPageBlockType.thinking.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") case let .table(title, rows, bordered, striped): encoder.encodeInt32(InstantPageBlockType.table.rawValue, forKey: "r") encoder.encodeObject(title, forKey: "t") @@ -530,6 +537,12 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable { } else { return false } + case let .thinking(text): + if case .thinking(text) = rhs { + return true + } else { + return false + } case let .table(lhsTitle, lhsRows, lhsBordered, lhsStriped): if case let .table(rhsTitle, rhsRows, rhsBordered, rhsStriped) = rhs, lhsTitle == rhsTitle, lhsRows == rhsRows, lhsBordered == rhsBordered, lhsStriped == rhsStriped { return true @@ -692,6 +705,11 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable { throw FlatBuffersError.missingRequiredField() } self = .kicker(try RichText(flatBuffersObject: value.text)) + case .instantpageblockThinking: + guard let value = flatBuffersObject.value(type: TelegramCore_InstantPageBlock_Thinking.self) else { + throw FlatBuffersError.missingRequiredField() + } + self = .thinking(try RichText(flatBuffersObject: value.text)) case .instantpageblockTable: guard let value = flatBuffersObject.value(type: TelegramCore_InstantPageBlock_Table.self) else { throw FlatBuffersError.missingRequiredField() @@ -937,6 +955,12 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable { let start = TelegramCore_InstantPageBlock_Kicker.startInstantPageBlock_Kicker(&builder) TelegramCore_InstantPageBlock_Kicker.add(text: textOffset, &builder) offset = TelegramCore_InstantPageBlock_Kicker.endInstantPageBlock_Kicker(&builder, start: start) + case let .thinking(text): + valueType = .instantpageblockThinking + let textOffset = text.encodeToFlatBuffers(builder: &builder) + let start = TelegramCore_InstantPageBlock_Thinking.startInstantPageBlock_Thinking(&builder) + TelegramCore_InstantPageBlock_Thinking.add(text: textOffset, &builder) + offset = TelegramCore_InstantPageBlock_Thinking.endInstantPageBlock_Thinking(&builder, start: start) case let .table(title, rows, bordered, striped): valueType = .instantpageblockTable let titleOffset = title.encodeToFlatBuffers(builder: &builder) diff --git a/submodules/TelegramStringFormatting/Sources/InstantPagePreviewText.swift b/submodules/TelegramStringFormatting/Sources/InstantPagePreviewText.swift index ed6e7fb3d1..6b8d179aef 100644 --- a/submodules/TelegramStringFormatting/Sources/InstantPagePreviewText.swift +++ b/submodules/TelegramStringFormatting/Sources/InstantPagePreviewText.swift @@ -151,6 +151,8 @@ extension InstantPageBlock { return "" case .kicker: return "" + case .thinking: + return "" case .table: //TODO:localize return "Table"