d
This commit is contained in:
@@ -3,12 +3,15 @@ version: 2
|
|||||||
model:
|
model:
|
||||||
activeIds: [[String], []]
|
activeIds: [[String], []]
|
||||||
activityDates: [[String:Date], [:]]
|
activityDates: [[String:Date], [:]]
|
||||||
|
requestActivityDate: [String?, nil]
|
||||||
|
|
||||||
service:
|
service:
|
||||||
actions:
|
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:
|
pipes:
|
||||||
activeIds: [recent, K.activeIds]
|
activeIds: [recent, K.activeIds]
|
||||||
activityDates: [recent, K.activityDates]
|
activityDates: [recent, K.activityDates]
|
||||||
|
requestActivityDate: [toggleNil, K.requestActivityDate]
|
||||||
|
|
||||||
world:
|
world:
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import UIKit
|
|||||||
public protocol MicContext {
|
public protocol MicContext {
|
||||||
var activeIds: MPAK.Recent<[String]> { get }
|
var activeIds: MPAK.Recent<[String]> { get }
|
||||||
var activityDates: MPAK.Recent<[String:Date]> { get }
|
var activityDates: MPAK.Recent<[String:Date]> { get }
|
||||||
|
var requestActivityDate: String? { get }
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Controller
|
// MARK: - Controller
|
||||||
@@ -35,6 +36,7 @@ extension Mic {
|
|||||||
public struct Model: MicContext {
|
public struct Model: MicContext {
|
||||||
public var activeIds: MPAK.Recent<[String]> = .init([])
|
public var activeIds: MPAK.Recent<[String]> = .init([])
|
||||||
public var activityDates: MPAK.Recent<[String:Date]> = .init([:])
|
public var activityDates: MPAK.Recent<[String:Date]> = .init([:])
|
||||||
|
public var requestActivityDate: String? = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Service
|
// MARK: - Service
|
||||||
@@ -78,10 +80,15 @@ extension Mic {
|
|||||||
) {
|
) {
|
||||||
// MARK: - SectionGenerated Service Actions
|
// 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
|
ctrl.m
|
||||||
.compactMap { shouldResetActivityDates($0) }
|
.compactMap { shouldResetActivityDates($0) }
|
||||||
.receive(on: DispatchQueue.main)
|
.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)
|
.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 }
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ public extension Mic {
|
|||||||
public static let activityDates = "Mic.activityDates"
|
public static let activityDates = "Mic.activityDates"
|
||||||
public static let isActive = "Mic.isActive"
|
public static let isActive = "Mic.isActive"
|
||||||
public static let MI = "Mic.Model.Item"
|
public static let MI = "Mic.Model.Item"
|
||||||
|
public static let requestActivityDate = "Mic.requestActivityDate"
|
||||||
public static let timeout = "Mic.timeout"
|
public static let timeout = "Mic.timeout"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,31 @@
|
|||||||
public extension Mic {
|
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: Словарь активных состояний
|
/// - Returns: Словарь активных состояний
|
||||||
static func shouldResetActivityDates(_ c: MicContext) -> [String: Date]? {
|
static func shouldResetActivityDates(_ c: MicContext) -> [String: Date]? {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ extension MicItem {
|
|||||||
.animation(.easeInOut(duration: 0.3))
|
.animation(.easeInOut(duration: 0.3))
|
||||||
.onAppear {
|
.onAppear {
|
||||||
isActive.id = id
|
isActive.id = id
|
||||||
|
Bus.send(K.requestActivityDate, id)
|
||||||
}
|
}
|
||||||
.onChange(of: id) { newValue in
|
.onChange(of: id) { newValue in
|
||||||
isActive.id = newValue
|
isActive.id = newValue
|
||||||
|
|||||||
Reference in New Issue
Block a user