@@ -109,63 +109,13 @@ public struct QuotedMessageView<Factory: ViewFactory>: View {
109109
110110 public var body : some View {
111111 HStack ( alignment: . top) {
112- if !quotedMessage. attachmentCounts. isEmpty {
113- ZStack {
114- if messageTypeResolver. hasCustomAttachment ( message: quotedMessage) {
115- factory. makeCustomAttachmentQuotedView ( for: quotedMessage)
116- } else if hasVoiceAttachments {
117- VoiceRecordingPreview ( voiceAttachment: quotedMessage. voiceRecordingAttachments [ 0 ] . payload)
118- } else if !quotedMessage. imageAttachments. isEmpty {
119- LazyLoadingImage (
120- source: MediaAttachment ( url: quotedMessage. imageAttachments [ 0 ] . imageURL, type: . image) ,
121- width: attachmentSize. width,
122- height: attachmentSize. height,
123- resize: false
124- )
125- } else if !quotedMessage. giphyAttachments. isEmpty {
126- LazyGiphyView (
127- source: quotedMessage. giphyAttachments [ 0 ] . previewURL,
128- width: attachmentSize. width
129- )
130- } else if !quotedMessage. fileAttachments. isEmpty {
131- Image ( uiImage: filePreviewImage ( for: quotedMessage. fileAttachments [ 0 ] . assetURL) )
132- } else if !quotedMessage. videoAttachments. isEmpty {
133- VideoAttachmentView (
134- attachment: quotedMessage. videoAttachments [ 0 ] ,
135- message: quotedMessage,
136- width: attachmentSize. width,
137- ratio: 1.0 ,
138- cornerRadius: 0
139- )
140- } else if !quotedMessage. linkAttachments. isEmpty {
141- LazyImage (
142- imageURL: quotedMessage. linkAttachments [ 0 ] . previewURL ?? quotedMessage. linkAttachments [ 0 ]
143- . originalURL
144- )
145- . onDisappear ( . cancel)
146- . processors ( [ ImageProcessors . Resize ( width: attachmentSize. width) ] )
147- . priority ( . high)
148- }
149- }
150- . frame ( width: hasVoiceAttachments ? nil : attachmentSize. width, height: attachmentSize. height)
151- . aspectRatio ( 1 , contentMode: . fill)
152- . clipShape ( RoundedRectangle ( cornerRadius: 8 ) )
153- . allowsHitTesting ( false )
154- } else if let poll = quotedMessage. poll, !quotedMessage. isDeleted {
155- Text ( " 📊 \( poll. name) " )
156- }
157-
158- if !hasVoiceAttachments {
159- Text ( textForMessage)
160- . foregroundColor ( textColor ( for: quotedMessage) )
161- . lineLimit ( 3 )
162- . font ( fonts. footnote)
163- . accessibility ( identifier: " quotedMessageText " )
164- }
165-
166- if fillAvailableSpace {
167- Spacer ( )
168- }
112+ QuotedMessageContentView (
113+ factory: factory,
114+ quotedMessage: quotedMessage,
115+ fillAvailableSpace: fillAvailableSpace,
116+ forceLeftToRight: forceLeftToRight,
117+ attachmentSize: attachmentSize
118+ )
169119 }
170120 . id ( quotedMessage. messageId)
171121 . padding (
@@ -195,6 +145,103 @@ public struct QuotedMessageView<Factory: ViewFactory>: View {
195145 colors. quotedMessageBackgroundCurrentUser : colors. quotedMessageBackgroundOtherUser
196146 return color
197147 }
148+
149+ private var hasVoiceAttachments : Bool {
150+ !quotedMessage. voiceRecordingAttachments. isEmpty
151+ }
152+ }
153+
154+ struct QuotedMessageContentView < Factory: ViewFactory > : View {
155+ @Environment ( \. channelTranslationLanguage) var translationLanguage
156+
157+ @Injected ( \. images) private var images
158+ @Injected ( \. fonts) private var fonts
159+ @Injected ( \. colors) private var colors
160+ @Injected ( \. utils) private var utils
161+
162+ public var factory : Factory
163+ public var quotedMessage : ChatMessage
164+ public var fillAvailableSpace : Bool
165+ public var forceLeftToRight : Bool
166+ public let attachmentSize : CGSize
167+
168+ private var messageTypeResolver : MessageTypeResolving {
169+ utils. messageTypeResolver
170+ }
171+
172+ public init (
173+ factory: Factory ,
174+ quotedMessage: ChatMessage ,
175+ fillAvailableSpace: Bool ,
176+ forceLeftToRight: Bool ,
177+ attachmentSize: CGSize = CGSize ( width: 36 , height: 36 )
178+ ) {
179+ self . factory = factory
180+ self . quotedMessage = quotedMessage
181+ self . fillAvailableSpace = fillAvailableSpace
182+ self . forceLeftToRight = forceLeftToRight
183+ self . attachmentSize = attachmentSize
184+ }
185+
186+ var body : some View {
187+ if !quotedMessage. attachmentCounts. isEmpty {
188+ ZStack {
189+ if messageTypeResolver. hasCustomAttachment ( message: quotedMessage) {
190+ factory. makeCustomAttachmentQuotedView ( for: quotedMessage)
191+ } else if hasVoiceAttachments {
192+ VoiceRecordingPreview ( voiceAttachment: quotedMessage. voiceRecordingAttachments [ 0 ] . payload)
193+ } else if !quotedMessage. imageAttachments. isEmpty {
194+ LazyLoadingImage (
195+ source: MediaAttachment ( url: quotedMessage. imageAttachments [ 0 ] . imageURL, type: . image) ,
196+ width: attachmentSize. width,
197+ height: attachmentSize. height,
198+ resize: false
199+ )
200+ } else if !quotedMessage. giphyAttachments. isEmpty {
201+ LazyGiphyView (
202+ source: quotedMessage. giphyAttachments [ 0 ] . previewURL,
203+ width: attachmentSize. width
204+ )
205+ } else if !quotedMessage. fileAttachments. isEmpty {
206+ Image ( uiImage: filePreviewImage ( for: quotedMessage. fileAttachments [ 0 ] . assetURL) )
207+ } else if !quotedMessage. videoAttachments. isEmpty {
208+ VideoAttachmentView (
209+ attachment: quotedMessage. videoAttachments [ 0 ] ,
210+ message: quotedMessage,
211+ width: attachmentSize. width,
212+ ratio: 1.0 ,
213+ cornerRadius: 0
214+ )
215+ } else if !quotedMessage. linkAttachments. isEmpty {
216+ LazyImage (
217+ imageURL: quotedMessage. linkAttachments [ 0 ] . previewURL ?? quotedMessage. linkAttachments [ 0 ]
218+ . originalURL
219+ )
220+ . onDisappear ( . cancel)
221+ . processors ( [ ImageProcessors . Resize ( width: attachmentSize. width) ] )
222+ . priority ( . high)
223+ }
224+ }
225+ . frame ( width: hasVoiceAttachments ? nil : attachmentSize. width, height: attachmentSize. height)
226+ . aspectRatio ( 1 , contentMode: . fill)
227+ . clipShape ( RoundedRectangle ( cornerRadius: 8 ) )
228+ . allowsHitTesting ( false )
229+ } else if let poll = quotedMessage. poll, !quotedMessage. isDeleted {
230+ Text ( " 📊 \( poll. name) " )
231+ }
232+
233+ if !hasVoiceAttachments {
234+ Text ( textForMessage)
235+ . foregroundColor ( textColor ( for: quotedMessage) )
236+ . lineLimit ( 3 )
237+ . font ( fonts. footnote)
238+ . accessibility ( identifier: " quotedMessageText " )
239+ }
240+
241+ if fillAvailableSpace {
242+ Spacer ( )
243+ }
244+ }
198245
199246 private func filePreviewImage( for url: URL ) -> UIImage {
200247 let iconName = url. pathExtension
0 commit comments