diff --git a/Modules/MicX/Mic/Mic.yml b/Modules/MicX/Mic/Mic.yml index e86185a..482f0aa 100644 --- a/Modules/MicX/Mic/Mic.yml +++ b/Modules/MicX/Mic/Mic.yml @@ -3,12 +3,15 @@ version: 2 model: activeIds: [[String], []] activityDates: [[String:Date], [:]] + requestActivityDate: [String?, nil] service: actions: - shouldResetActivityDates: Bus.send(K.activityDates, v);Bus.deliver(K.activityDate, v) + shouldDeliverActivityDates: Bus.deliver(K.activityDate, v) + shouldResetActivityDates: Bus.send(K.activityDates, v) pipes: activeIds: [recent, K.activeIds] activityDates: [recent, K.activityDates] + requestActivityDate: [toggleNil, K.requestActivityDate] world: diff --git a/Modules/MicX/Mic/src/Mic.Generated.swift b/Modules/MicX/Mic/src/Mic.Generated.swift index a8065f4..fd4bdfe 100644 --- a/Modules/MicX/Mic/src/Mic.Generated.swift +++ b/Modules/MicX/Mic/src/Mic.Generated.swift @@ -13,6 +13,7 @@ import UIKit public protocol MicContext { var activeIds: MPAK.Recent<[String]> { get } var activityDates: MPAK.Recent<[String:Date]> { get } + var requestActivityDate: String? { get } } // MARK: - Controller @@ -35,6 +36,7 @@ extension Mic { public struct Model: MicContext { public var activeIds: MPAK.Recent<[String]> = .init([]) public var activityDates: MPAK.Recent<[String:Date]> = .init([:]) + public var requestActivityDate: String? = nil } // MARK: - Service @@ -78,10 +80,15 @@ extension Mic { ) { // MARK: - SectionGenerated Service Actions + ctrl.m + .compactMap { shouldDeliverActivityDates($0) } + .receive(on: DispatchQueue.main) + .sink { v in Bus.deliver(K.activityDate, v) } + .store(in: &service.subscriptions) ctrl.m .compactMap { shouldResetActivityDates($0) } .receive(on: DispatchQueue.main) - .sink { v in Bus.send(K.activityDates, v);Bus.deliver(K.activityDate, v) } + .sink { v in Bus.send(K.activityDates, v) } .store(in: &service.subscriptions) @@ -113,6 +120,19 @@ extension Mic { + ctrl.pipeValue( + dbg: "requestAD", + sub: nil, + Bus.events.compactMap { Bus.convertKeyValue(K.requestActivityDate, $0) }.map { (k: String, v: String?) in v }.eraseToAnyPublisher(), + { $0.requestActivityDate = $1 }, + { m, _ in m.requestActivityDate = nil } + ) + + + + + + } diff --git a/Modules/MicX/Mic/src/Mic.K.swift b/Modules/MicX/Mic/src/Mic.K.swift index 16c90a9..68b48cf 100644 --- a/Modules/MicX/Mic/src/Mic.K.swift +++ b/Modules/MicX/Mic/src/Mic.K.swift @@ -5,6 +5,7 @@ public extension Mic { public static let activityDates = "Mic.activityDates" public static let isActive = "Mic.isActive" public static let MI = "Mic.Model.Item" + public static let requestActivityDate = "Mic.requestActivityDate" public static let timeout = "Mic.timeout" } } diff --git a/Modules/MicX/Mic/src/Mic.Shoulds.swift b/Modules/MicX/Mic/src/Mic.Shoulds.swift index 15cd7bf..1791c67 100644 --- a/Modules/MicX/Mic/src/Mic.Shoulds.swift +++ b/Modules/MicX/Mic/src/Mic.Shoulds.swift @@ -1,8 +1,31 @@ public extension Mic { + /// Следует доставить состояния звуковой активности элементам + /// + /// Условия: + /// 1. Изменились даты активности + /// 2. Элемент запросил свою дату активности + /// + /// - Returns: Словарь состояний + static func shouldDeliverActivityDates(_ c: MicContext) -> [String: Date]? { + if let ad = shouldResetActivityDates(c) { + return ad + } + + if + let id = c.requestActivityDate, + let timeout = c.activityDates.value[id], + timeout > Date() + { + return [id: timeout] + } + + return nil + } + /// Следует обновить словарь состояний звуковой активности /// /// Условия: - /// 1. ??? + /// 1. Пришли id активных участников /// /// - Returns: Словарь активных состояний static func shouldResetActivityDates(_ c: MicContext) -> [String: Date]? { diff --git a/Modules/MicX/MicItem/src/MicItem.V.swift b/Modules/MicX/MicItem/src/MicItem.V.swift index 6828850..edb180a 100644 --- a/Modules/MicX/MicItem/src/MicItem.V.swift +++ b/Modules/MicX/MicItem/src/MicItem.V.swift @@ -27,6 +27,7 @@ extension MicItem { .animation(.easeInOut(duration: 0.3)) .onAppear { isActive.id = id + Bus.send(K.requestActivityDate, id) } .onChange(of: id) { newValue in isActive.id = newValue