@@ -46,6 +46,7 @@ final class ChatViewController: MessagesViewController {
4646 private var isScrollDownButtonHidden = true
4747 private var previousUnreadCount : Int = 0
4848 private var scrollToPositionType : UICollectionView . ScrollPosition = . top
49+ private var isAppActive = true
4950
5051 private lazy var inputBar = ChatInputBar ( )
5152 private lazy var loadingView = LoadingView ( )
@@ -325,10 +326,18 @@ extension ChatViewController {
325326 . notifications ( named: UIApplication . didBecomeActiveNotification)
326327 . sink { @MainActor [ weak self] _ in
327328 guard let self = self else { return }
329+ self . isAppActive = true
330+ self . updateUnreadMessages ( )
328331 let indexes = self . messagesCollectionView. indexPathsForVisibleItems
329332 self . viewModel. updatePreviewFor ( indexes: indexes)
330333 }
331334 . store ( in: & subscriptions)
335+
336+ NotificationCenter . default. publisher ( for: UIApplication . willResignActiveNotification)
337+ . sink { [ weak self] _ in
338+ self ? . isAppActive = false
339+ }
340+ . store ( in: & subscriptions)
332341
333342 viewModel. didTapAdmNodesList
334343 . sink { [ weak self] in
@@ -587,6 +596,9 @@ extension ChatViewController {
587596 }
588597
589598 fileprivate func updateUnreadMessages( ) {
599+ if isMacOS && !isAppActive {
600+ return
601+ }
590602 guard let unreadIndexes = viewModel. unreadMesaggesIndexes, !unreadIndexes. isEmpty else { return }
591603 let visibleIndexPaths = messagesCollectionView. indexPathsForVisibleItems
592604
0 commit comments