11import Foundation
2+ import Postbox
23import TelegramCore
4+ import TelegramPresentationData
35
46extension RichText {
5- public func previewText( ) -> String {
7+ public func previewText( strings : PresentationStrings ) -> String {
68 switch self {
79 case . empty:
810 return " "
911 case let . plain( value) :
1012 return value
1113 case let . bold( value) :
12- return value. previewText ( )
14+ return value. previewText ( strings : strings )
1315 case let . italic( value) :
14- return value. previewText ( )
16+ return value. previewText ( strings : strings )
1517 case let . underline( value) :
16- return value. previewText ( )
18+ return value. previewText ( strings : strings )
1719 case let . strikethrough( value) :
18- return value. previewText ( )
20+ return value. previewText ( strings : strings )
1921 case let . fixed( value) :
20- return value. previewText ( )
22+ return value. previewText ( strings : strings )
2123 case let . url( value, _, _) :
22- return value. previewText ( )
24+ return value. previewText ( strings : strings )
2325 case let . email( value, _) :
24- return value. previewText ( )
26+ return value. previewText ( strings : strings )
2527 case let . concat( values) :
2628 var result = " "
2729 for value in values {
28- result. append ( value. previewText ( ) )
30+ result. append ( value. previewText ( strings : strings ) )
2931 }
3032 return result
3133 case let . `subscript`( value) :
32- return value. previewText ( )
34+ return value. previewText ( strings : strings )
3335 case let . superscript( value) :
34- return value. previewText ( )
36+ return value. previewText ( strings : strings )
3537 case let . marked( value) :
36- return value. previewText ( )
38+ return value. previewText ( strings : strings )
3739 case let . phone( value, _) :
38- return value. previewText ( )
40+ return value. previewText ( strings : strings )
3941 case . image:
40- //TODO:localize
41- return " Photo "
42+ return strings. Message_Photo
4243 case let . anchor( value, _) :
43- return value. previewText ( )
44+ return value. previewText ( strings : strings )
4445 case . formula:
45- //TODO:localize
46- return " Fx "
46+ return strings. RichTextPreview_Formula
4747 case let . textCustomEmoji( _, alt) :
4848 return alt
4949 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, _, _) :
50- return value. previewText ( )
50+ return value. previewText ( strings : strings )
5151 }
5252 }
5353}
5454
5555extension InstantPageListItem {
56- public func previewText( ) -> String {
56+ public func previewText( strings : PresentationStrings , media : [ MediaId : Media ] ) -> String {
5757 switch self {
5858 case . unknown:
5959 return " "
6060 case let . text( text, num, checked) :
61- let body = text. previewText ( )
61+ let body = text. previewText ( strings : strings )
6262 if let checked {
6363 return " \( checked ? " ☑︎ " : " ☐ " ) \( body) "
6464 } else if let num, !num. isEmpty {
@@ -72,7 +72,7 @@ extension InstantPageListItem {
7272 if !blocksText. isEmpty {
7373 blocksText. append ( " \n " )
7474 }
75- blocksText. append ( block. previewText ( ) )
75+ blocksText. append ( block. previewText ( strings : strings , media : media ) )
7676 }
7777 if let checked {
7878 return " \( checked ? " ☑︎ " : " ☐ " ) \( blocksText) "
@@ -86,30 +86,30 @@ extension InstantPageListItem {
8686}
8787
8888extension InstantPageBlock {
89- public func previewText( ) -> String {
89+ public func previewText( strings : PresentationStrings , media : [ MediaId : Media ] ) -> String {
9090 switch self {
9191 case . unsupported:
9292 return " "
9393 case let . title( text) :
94- return text. previewText ( )
94+ return text. previewText ( strings : strings )
9595 case let . subtitle( text) :
96- return text. previewText ( )
96+ return text. previewText ( strings : strings )
9797 case let . authorDate( author, _) :
98- return author. previewText ( )
98+ return author. previewText ( strings : strings )
9999 case let . header( text) :
100- return text. previewText ( )
100+ return text. previewText ( strings : strings )
101101 case let . subheader( text) :
102- return text. previewText ( )
102+ return text. previewText ( strings : strings )
103103 case let . heading( text, _) :
104- return text. previewText ( )
104+ return text. previewText ( strings : strings )
105105 case . formula:
106- return " Fx "
106+ return strings . RichTextPreview_Formula
107107 case let . paragraph( text) :
108- return text. previewText ( )
108+ return text. previewText ( strings : strings )
109109 case let . preformatted( text, _) :
110- return text. previewText ( )
110+ return text. previewText ( strings : strings )
111111 case let . footer( text) :
112- return text. previewText ( )
112+ return text. previewText ( strings : strings )
113113 case . divider:
114114 return " \n "
115115 case . anchor:
@@ -120,23 +120,24 @@ extension InstantPageBlock {
120120 if !result. isEmpty {
121121 result. append ( " \n " )
122122 }
123- result. append ( item. previewText ( ) )
123+ result. append ( item. previewText ( strings : strings , media : media ) )
124124 }
125125 return result
126126 case let . blockQuote( blocks, caption) :
127- let body = blocks. map { $0. previewText ( ) } . joined ( separator: " " )
128- return body + caption. previewText ( )
127+ let body = blocks. map { $0. previewText ( strings : strings , media : media ) } . joined ( separator: " " )
128+ return body + caption. previewText ( strings : strings )
129129 case let . pullQuote( text, caption) :
130- return text. previewText ( ) + caption. previewText ( )
130+ return text. previewText ( strings : strings ) + caption. previewText ( strings : strings )
131131 case . image( _, _, _, _) :
132- //TODO:localize
133- return " Photo "
132+ return strings. Message_Photo
134133 case . video( _, _, _, _) :
135- //TODO:localize
136- return " Video "
137- case . audio:
138- //TODO:localize
139- return " Audio "
134+ return strings. Message_Video
135+ case let . audio( id, _) :
136+ if let file = media [ id] as? TelegramMediaFile , file. isVoice {
137+ return strings. Message_Audio
138+ } else {
139+ return strings. RichTextPreview_Music
140+ }
140141 case . cover:
141142 return " "
142143 case . webEmbed:
@@ -154,28 +155,26 @@ extension InstantPageBlock {
154155 case . thinking:
155156 return " "
156157 case . table:
157- //TODO:localize
158- return " Table "
158+ return strings. RichTextPreview_Table
159159 case . details:
160160 return " "
161161 case . relatedArticles:
162162 return " "
163163 case . map:
164- //TODO:localize
165- return " Map "
164+ return strings. Message_Location
166165 }
167166 }
168167}
169168
170169extension InstantPage {
171- public func previewText( ) -> String {
170+ public func previewText( strings : PresentationStrings ) -> String {
172171 let maxLength : Int = 200
173172 var result = " "
174173 for block in self . blocks {
175174 if !result. isEmpty {
176175 result. append ( " \n " )
177176 }
178- result. append ( block. previewText ( ) )
177+ result. append ( block. previewText ( strings : strings , media : self . media ) )
179178 if result. count > maxLength {
180179 break
181180 }
0 commit comments