From 86924af785da517a9b1fd9fdde84a844ff8071c2 Mon Sep 17 00:00:00 2001 From: cheykrym Date: Tue, 21 Oct 2025 20:32:36 +0300 Subject: [PATCH] disable notification while chat is opened --- yobble/Services/IncomingMessageCenter.swift | 10 ++++++++++ yobble/Views/Chat/PrivateChatView.swift | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/yobble/Services/IncomingMessageCenter.swift b/yobble/Services/IncomingMessageCenter.swift index 3451cc8..9b27e48 100644 --- a/yobble/Services/IncomingMessageCenter.swift +++ b/yobble/Services/IncomingMessageCenter.swift @@ -5,6 +5,7 @@ final class IncomingMessageCenter: ObservableObject { @Published private(set) var banner: IncomingMessageBanner? @Published var presentedChat: PrivateChatListItem? var currentUserId: String? + var activeChatId: String? private var dismissWorkItem: DispatchWorkItem? private var cancellables = Set() @@ -29,6 +30,7 @@ final class IncomingMessageCenter: ObservableObject { func openCurrentChat() { guard let banner else { return } + activeChatId = banner.message.chatId presentedChat = makeChatItem(from: banner.message) dismissBanner() } @@ -38,6 +40,14 @@ final class IncomingMessageCenter: ObservableObject { return } + if let activeChatId, activeChatId == message.chatId { + return + } + + if let presentedChat, presentedChat.chatId == message.chatId { + return + } + banner = buildBanner(from: message) scheduleDismiss() } diff --git a/yobble/Views/Chat/PrivateChatView.swift b/yobble/Views/Chat/PrivateChatView.swift index 965076d..f7d41fc 100644 --- a/yobble/Views/Chat/PrivateChatView.swift +++ b/yobble/Views/Chat/PrivateChatView.swift @@ -8,6 +8,7 @@ struct PrivateChatView: View { @State private var hasPositionedToBottom: Bool = false @State private var draftText: String = "" @FocusState private var isComposerFocused: Bool + @EnvironmentObject private var messageCenter: IncomingMessageCenter init(chat: PrivateChatListItem, currentUserId: String?) { self.chat = chat @@ -34,6 +35,9 @@ struct PrivateChatView: View { .task { viewModel.loadInitialHistory() } + .onAppear { + messageCenter.activeChatId = chat.chatId + } .onChange(of: viewModel.isInitialLoading) { isLoading in if isLoading { hasPositionedToBottom = false @@ -42,6 +46,11 @@ struct PrivateChatView: View { .safeAreaInset(edge: .bottom) { composer } + .onDisappear { + if messageCenter.activeChatId == chat.chatId { + messageCenter.activeChatId = nil + } + } } @ViewBuilder