disable notification while chat is opened
This commit is contained in:
parent
ed91efacf5
commit
86924af785
@ -5,6 +5,7 @@ final class IncomingMessageCenter: ObservableObject {
|
|||||||
@Published private(set) var banner: IncomingMessageBanner?
|
@Published private(set) var banner: IncomingMessageBanner?
|
||||||
@Published var presentedChat: PrivateChatListItem?
|
@Published var presentedChat: PrivateChatListItem?
|
||||||
var currentUserId: String?
|
var currentUserId: String?
|
||||||
|
var activeChatId: String?
|
||||||
|
|
||||||
private var dismissWorkItem: DispatchWorkItem?
|
private var dismissWorkItem: DispatchWorkItem?
|
||||||
private var cancellables = Set<AnyCancellable>()
|
private var cancellables = Set<AnyCancellable>()
|
||||||
@ -29,6 +30,7 @@ final class IncomingMessageCenter: ObservableObject {
|
|||||||
|
|
||||||
func openCurrentChat() {
|
func openCurrentChat() {
|
||||||
guard let banner else { return }
|
guard let banner else { return }
|
||||||
|
activeChatId = banner.message.chatId
|
||||||
presentedChat = makeChatItem(from: banner.message)
|
presentedChat = makeChatItem(from: banner.message)
|
||||||
dismissBanner()
|
dismissBanner()
|
||||||
}
|
}
|
||||||
@ -38,6 +40,14 @@ final class IncomingMessageCenter: ObservableObject {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let activeChatId, activeChatId == message.chatId {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if let presentedChat, presentedChat.chatId == message.chatId {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
banner = buildBanner(from: message)
|
banner = buildBanner(from: message)
|
||||||
scheduleDismiss()
|
scheduleDismiss()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ struct PrivateChatView: View {
|
|||||||
@State private var hasPositionedToBottom: Bool = false
|
@State private var hasPositionedToBottom: Bool = false
|
||||||
@State private var draftText: String = ""
|
@State private var draftText: String = ""
|
||||||
@FocusState private var isComposerFocused: Bool
|
@FocusState private var isComposerFocused: Bool
|
||||||
|
@EnvironmentObject private var messageCenter: IncomingMessageCenter
|
||||||
|
|
||||||
init(chat: PrivateChatListItem, currentUserId: String?) {
|
init(chat: PrivateChatListItem, currentUserId: String?) {
|
||||||
self.chat = chat
|
self.chat = chat
|
||||||
@ -34,6 +35,9 @@ struct PrivateChatView: View {
|
|||||||
.task {
|
.task {
|
||||||
viewModel.loadInitialHistory()
|
viewModel.loadInitialHistory()
|
||||||
}
|
}
|
||||||
|
.onAppear {
|
||||||
|
messageCenter.activeChatId = chat.chatId
|
||||||
|
}
|
||||||
.onChange(of: viewModel.isInitialLoading) { isLoading in
|
.onChange(of: viewModel.isInitialLoading) { isLoading in
|
||||||
if isLoading {
|
if isLoading {
|
||||||
hasPositionedToBottom = false
|
hasPositionedToBottom = false
|
||||||
@ -42,6 +46,11 @@ struct PrivateChatView: View {
|
|||||||
.safeAreaInset(edge: .bottom) {
|
.safeAreaInset(edge: .bottom) {
|
||||||
composer
|
composer
|
||||||
}
|
}
|
||||||
|
.onDisappear {
|
||||||
|
if messageCenter.activeChatId == chat.chatId {
|
||||||
|
messageCenter.activeChatId = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user