mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Localize rich-text message preview labels; split audio into voice/music
Thread PresentationStrings through RichText/InstantPageBlock/InstantPage
previewText(), replacing the hardcoded //TODO:localize placeholders
("Photo", "Fx", "Table", "Map", ...) with localized keys and reusing the
existing Message.Photo/Video/Location strings. Add RichTextPreview.Formula
("[formula]"), RichTextPreview.Table ("[table]"), and RichTextPreview.Music
("Music").
The .audio block previously rendered the wrong label (Message.Audio is
"Voice Message"). Thread InstantPage.media down so the block can resolve
media[id] as TelegramMediaFile and split: isVoice -> "Voice Message",
otherwise -> "Music", mirroring MessageContentKind's voice/music handling.
Update both previewText() call sites (MessageContentKind, ChatListItemStrings)
to pass strings, and complete the InstantPageListItem migration that was
left on the old signature.
Also remove the dead streaming-status ("Thinking...") rendering block from
ChatMessageTextBubbleContentNode (guarded by an always-false `!"".isEmpty`)
along with the now-orphaned streamingTextFrame layout machinery it fed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
0050cc7a08
commit
35711ec6ad
5 changed files with 57 additions and 160 deletions
|
|
@ -1,64 +1,64 @@
|
|||
import Foundation
|
||||
import Postbox
|
||||
import TelegramCore
|
||||
import TelegramPresentationData
|
||||
|
||||
extension RichText {
|
||||
public func previewText() -> String {
|
||||
public func previewText(strings: PresentationStrings) -> String {
|
||||
switch self {
|
||||
case .empty:
|
||||
return ""
|
||||
case let .plain(value):
|
||||
return value
|
||||
case let .bold(value):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
case let .italic(value):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
case let .underline(value):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
case let .strikethrough(value):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
case let .fixed(value):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
case let .url(value, _, _):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
case let .email(value, _):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
case let .concat(values):
|
||||
var result = ""
|
||||
for value in values {
|
||||
result.append(value.previewText())
|
||||
result.append(value.previewText(strings: strings))
|
||||
}
|
||||
return result
|
||||
case let .`subscript`(value):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
case let .superscript(value):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
case let .marked(value):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
case let .phone(value, _):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
case .image:
|
||||
//TODO:localize
|
||||
return "Photo"
|
||||
return strings.Message_Photo
|
||||
case let .anchor(value, _):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
case .formula:
|
||||
//TODO:localize
|
||||
return "Fx"
|
||||
return strings.RichTextPreview_Formula
|
||||
case let .textCustomEmoji(_, alt):
|
||||
return alt
|
||||
case let .textAutoEmail(value), let .textAutoPhone(value), let .textAutoUrl(value), let .textBankCard(value), let .textBotCommand(value), let .textCashtag(value), let .textHashtag(value), let .textMention(value), let .textMentionName(value, _), let .textSpoiler(value), let .textDate(value, _, _):
|
||||
return value.previewText()
|
||||
return value.previewText(strings: strings)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension InstantPageListItem {
|
||||
public func previewText() -> String {
|
||||
public func previewText(strings: PresentationStrings, media: [MediaId: Media]) -> String {
|
||||
switch self {
|
||||
case .unknown:
|
||||
return ""
|
||||
case let .text(text, num, checked):
|
||||
let body = text.previewText()
|
||||
let body = text.previewText(strings: strings)
|
||||
if let checked {
|
||||
return "\(checked ? "☑︎" : "☐") \(body)"
|
||||
} else if let num, !num.isEmpty {
|
||||
|
|
@ -72,7 +72,7 @@ extension InstantPageListItem {
|
|||
if !blocksText.isEmpty {
|
||||
blocksText.append("\n")
|
||||
}
|
||||
blocksText.append(block.previewText())
|
||||
blocksText.append(block.previewText(strings: strings, media: media))
|
||||
}
|
||||
if let checked {
|
||||
return "\(checked ? "☑︎" : "☐") \(blocksText)"
|
||||
|
|
@ -86,30 +86,30 @@ extension InstantPageListItem {
|
|||
}
|
||||
|
||||
extension InstantPageBlock {
|
||||
public func previewText() -> String {
|
||||
public func previewText(strings: PresentationStrings, media: [MediaId: Media]) -> String {
|
||||
switch self {
|
||||
case .unsupported:
|
||||
return ""
|
||||
case let .title(text):
|
||||
return text.previewText()
|
||||
return text.previewText(strings: strings)
|
||||
case let .subtitle(text):
|
||||
return text.previewText()
|
||||
return text.previewText(strings: strings)
|
||||
case let .authorDate(author, _):
|
||||
return author.previewText()
|
||||
return author.previewText(strings: strings)
|
||||
case let .header(text):
|
||||
return text.previewText()
|
||||
return text.previewText(strings: strings)
|
||||
case let .subheader(text):
|
||||
return text.previewText()
|
||||
return text.previewText(strings: strings)
|
||||
case let .heading(text, _):
|
||||
return text.previewText()
|
||||
return text.previewText(strings: strings)
|
||||
case .formula:
|
||||
return "Fx"
|
||||
return strings.RichTextPreview_Formula
|
||||
case let .paragraph(text):
|
||||
return text.previewText()
|
||||
return text.previewText(strings: strings)
|
||||
case let .preformatted(text, _):
|
||||
return text.previewText()
|
||||
return text.previewText(strings: strings)
|
||||
case let .footer(text):
|
||||
return text.previewText()
|
||||
return text.previewText(strings: strings)
|
||||
case .divider:
|
||||
return "\n"
|
||||
case .anchor:
|
||||
|
|
@ -120,23 +120,24 @@ extension InstantPageBlock {
|
|||
if !result.isEmpty {
|
||||
result.append("\n")
|
||||
}
|
||||
result.append(item.previewText())
|
||||
result.append(item.previewText(strings: strings, media: media))
|
||||
}
|
||||
return result
|
||||
case let .blockQuote(blocks, caption):
|
||||
let body = blocks.map { $0.previewText() }.joined(separator: " ")
|
||||
return body + caption.previewText()
|
||||
let body = blocks.map { $0.previewText(strings: strings, media: media) }.joined(separator: " ")
|
||||
return body + caption.previewText(strings: strings)
|
||||
case let .pullQuote(text, caption):
|
||||
return text.previewText() + caption.previewText()
|
||||
return text.previewText(strings: strings) + caption.previewText(strings: strings)
|
||||
case .image(_, _, _, _):
|
||||
//TODO:localize
|
||||
return "Photo"
|
||||
return strings.Message_Photo
|
||||
case .video(_, _, _, _):
|
||||
//TODO:localize
|
||||
return "Video"
|
||||
case .audio:
|
||||
//TODO:localize
|
||||
return "Audio"
|
||||
return strings.Message_Video
|
||||
case let .audio(id, _):
|
||||
if let file = media[id] as? TelegramMediaFile, file.isVoice {
|
||||
return strings.Message_Audio
|
||||
} else {
|
||||
return strings.RichTextPreview_Music
|
||||
}
|
||||
case .cover:
|
||||
return ""
|
||||
case .webEmbed:
|
||||
|
|
@ -154,28 +155,26 @@ extension InstantPageBlock {
|
|||
case .thinking:
|
||||
return ""
|
||||
case .table:
|
||||
//TODO:localize
|
||||
return "Table"
|
||||
return strings.RichTextPreview_Table
|
||||
case .details:
|
||||
return ""
|
||||
case .relatedArticles:
|
||||
return ""
|
||||
case .map:
|
||||
//TODO:localize
|
||||
return "Map"
|
||||
return strings.Message_Location
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension InstantPage {
|
||||
public func previewText() -> String {
|
||||
public func previewText(strings: PresentationStrings) -> String {
|
||||
let maxLength: Int = 200
|
||||
var result = ""
|
||||
for block in self.blocks {
|
||||
if !result.isEmpty {
|
||||
result.append("\n")
|
||||
}
|
||||
result.append(block.previewText())
|
||||
result.append(block.previewText(strings: strings, media: self.media))
|
||||
if result.count > maxLength {
|
||||
break
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue