@@ -58,6 +58,9 @@ import SwiftUI
5858 @Published public var scrolledId : String ?
5959 @Published public var highlightedMessageId : String ?
6060 @Published public var listId = UUID ( ) . uuidString
61+ // A boolean to skip highlighting of a message when scrolling to it.
62+ // This is used for scenarios when scrolling to message Id should not highlight it.
63+ var skipHighlightMessageId : String ?
6164
6265 @Published public var showScrollToLatestButton = false
6366 @Published var showAlertBanner = false
@@ -173,20 +176,11 @@ import SwiftUI
173176 self ? . messageCachingUtils. jumpToReplyId = scrollToMessage. messageId
174177 } else if messageController != nil , let jumpToReplyId = self ? . messageCachingUtils. jumpToReplyId {
175178 self ? . scrolledId = jumpToReplyId
176- // Trigger highlight when jumping to reply in thread
177- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.1 ) { [ weak self] in
178- self ? . highlightedMessageId = jumpToReplyId
179- }
180179 // Clear scroll ID after 2 seconds
181180 DispatchQueue . main. asyncAfter ( deadline: . now( ) + 2.0 ) { [ weak self] in
182181 self ? . scrolledId = nil
183182 }
184- // Clear highlight after animation completes
185- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.7 ) { [ weak self] in
186- withAnimation {
187- self ? . highlightedMessageId = nil
188- }
189- }
183+ self ? . highlightMessage ( withId: jumpToReplyId)
190184 self ? . messageCachingUtils. jumpToReplyId = nil
191185 } else if messageController == nil {
192186 self ? . scrolledId = scrollToMessage? . messageId
@@ -318,20 +312,11 @@ import SwiftUI
318312 if scrolledId == nil {
319313 scrolledId = messageId
320314 }
321- // Trigger highlight after a short delay to allow scroll animation to start
322- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.1 ) { [ weak self] in
323- self ? . highlightedMessageId = messageId
324- }
325315 // Clear scroll ID after 2 seconds
326316 DispatchQueue . main. asyncAfter ( deadline: . now( ) + 2.0 ) { [ weak self] in
327317 self ? . scrolledId = nil
328318 }
329- // Clear highlight after animation completes
330- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.7 ) { [ weak self] in
331- withAnimation {
332- self ? . highlightedMessageId = nil
333- }
334- }
319+ highlightMessage ( withId: messageId)
335320 return true
336321 } else {
337322 let message = channelController. dataStore. message ( id: baseId)
@@ -360,23 +345,33 @@ import SwiftUI
360345 DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.1 ) { [ weak self] in
361346 self ? . scrolledId = toJumpId
362347 self ? . loadingMessagesAround = false
363- // Trigger highlight after scroll starts
364- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.1 ) {
365- self ? . highlightedMessageId = toJumpId
366- }
367- // Clear highlight after animation completes
368- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.7 ) {
369- withAnimation {
370- self ? . highlightedMessageId = nil
371- }
372- }
348+ self ? . highlightMessage ( withId: toJumpId)
373349 }
374350 }
375351 return false
376352 }
377353 }
378354 }
379-
355+
356+ /// Highlights the message background.
357+ ///
358+ /// - Parameter messageId: The ID of the message to highlight.
359+ public func highlightMessage( withId messageId: MessageId ) {
360+ if skipHighlightMessageId == messageId {
361+ skipHighlightMessageId = nil
362+ return
363+ }
364+
365+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.1 ) { [ weak self] in
366+ self ? . highlightedMessageId = messageId
367+ }
368+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.7 ) { [ weak self] in
369+ withAnimation {
370+ self ? . highlightedMessageId = nil
371+ }
372+ }
373+ }
374+
380375 open func handleMessageAppear( index: Int , scrollDirection: ScrollDirection ) {
381376 if index >= channelDataSource. messages. count || loadingMessagesAround {
382377 return
@@ -561,7 +556,7 @@ import SwiftUI
561556 }
562557
563558 // MARK: - private
564-
559+
565560 private func checkForOlderMessages( index: Int ) {
566561 guard index >= channelDataSource. messages. count - 25 else { return }
567562 guard !loadingPreviousMessages else { return }
0 commit comments