Skip to content

Commit 65fa39f

Browse files
committed
[trello.com/c/sG80IZan] remove chat reeding when app is not active macOs
1 parent bcaa967 commit 65fa39f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Adamant/Modules/Chat/View/ChatViewController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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()
@@ -309,10 +310,18 @@ extension ChatViewController {
309310
.notifications(named: UIApplication.didBecomeActiveNotification)
310311
.sink { @MainActor [weak self] _ in
311312
guard let self = self else { return }
313+
self.isAppActive = true
314+
self.updateUnreadMessages()
312315
let indexes = self.messagesCollectionView.indexPathsForVisibleItems
313316
self.viewModel.updatePreviewFor(indexes: indexes)
314317
}
315318
.store(in: &subscriptions)
319+
320+
NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification)
321+
.sink { [weak self] _ in
322+
self?.isAppActive = false
323+
}
324+
.store(in: &subscriptions)
316325

317326
viewModel.didTapAdmNodesList
318327
.sink { [weak self] in
@@ -571,6 +580,9 @@ extension ChatViewController {
571580
}
572581

573582
fileprivate func updateUnreadMessages() {
583+
if isMacOS && !isAppActive {
584+
return
585+
}
574586
guard let unreadIndexes = viewModel.unreadMesaggesIndexes, !unreadIndexes.isEmpty else { return }
575587
let visibleIndexPaths = messagesCollectionView.indexPathsForVisibleItems
576588

0 commit comments

Comments
 (0)