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 var presentedChat: PrivateChatListItem?
 | 
			
		||||
    var currentUserId: String?
 | 
			
		||||
    var activeChatId: String?
 | 
			
		||||
 | 
			
		||||
    private var dismissWorkItem: DispatchWorkItem?
 | 
			
		||||
    private var cancellables = Set<AnyCancellable>()
 | 
			
		||||
@ -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()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user