// // NotificationsBellModulePresenter.swift // PrivadoVPN // // Created by Zhandos Bolatbekov on 12.01.2021. // Copyright © 2021 Privado LLC. All rights reserved. // import Foundation class NotificationsBellModulePresenter: NotificationsBellModuleOutput { var serversModuleOutput: ServersModuleOutput? weak var viewInput: NotificationsBellViewInput? init(session: Session, output: ServersModuleOutput?) { self.serversModuleOutput = output SerenityService.shared.localNotificationsEmitter.addReaction { [weak self] notifications -> ShouldContinueReceiveNotifications in let notifications = NotificationsFilter.shared.handleEmpty(of: notifications) DispatchQueue.main.async { [weak self] in self?.viewInput?.showBadge(!notifications.isEmpty) } return self.isExist } session.vpnConnectionStateEmitter.addReaction { [weak self] state, _ -> ShouldContinueReceiveNotifications in DispatchQueue.main.async { [weak self] in self?.viewInput?.set(highlighted: state == .connected) } return self.isExist } } func openNotificationsList() { self.viewInput?.showBadge(false) self.serversModuleOutput?.navigate(to: .notifications) LocalNotificationsManager.shared().resetAppBadgeCount() } func viewIsReady() { if VPNConnectionState(rawValue: UserSettings.shared.lastConnectionState) == .connected { self.viewInput?.set(highlighted: true) } } }