Vendor OpenClaw source as Adolf fork baseline
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
This commit is contained in:
35
apps/ios/Sources/Model/NodeAppModel+Canvas.swift
Normal file
35
apps/ios/Sources/Model/NodeAppModel+Canvas.swift
Normal file
@@ -0,0 +1,35 @@
|
||||
import Foundation
|
||||
import OpenClawKit
|
||||
|
||||
enum A2UIReadyState {
|
||||
case ready
|
||||
case hostUnavailable
|
||||
}
|
||||
|
||||
extension NodeAppModel {
|
||||
func showA2UIOnConnectIfNeeded() async {
|
||||
await MainActor.run {
|
||||
// Keep the bundled home canvas as the default connected view.
|
||||
// Agents can still explicitly present a remote or local canvas later.
|
||||
self.screen.showDefaultCanvas()
|
||||
}
|
||||
}
|
||||
|
||||
func ensureA2UIReadyWithCapabilityRefresh(timeoutMs: Int = 5000) async -> A2UIReadyState {
|
||||
if self.screen.isShowingLocalA2UI(),
|
||||
await self.screen.waitForA2UIReady(timeoutMs: timeoutMs)
|
||||
{
|
||||
return .ready
|
||||
}
|
||||
|
||||
self.screen.showLocalA2UI()
|
||||
if await self.screen.waitForA2UIReady(timeoutMs: timeoutMs) {
|
||||
return .ready
|
||||
}
|
||||
return .hostUnavailable
|
||||
}
|
||||
|
||||
func showLocalCanvasOnDisconnect() {
|
||||
self.screen.showDefaultCanvas()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import Foundation
|
||||
import OpenClawKit
|
||||
|
||||
extension NodeAppModel {
|
||||
static func normalizeWatchNotifyParams(_ params: OpenClawWatchNotifyParams) -> OpenClawWatchNotifyParams {
|
||||
var normalized = params
|
||||
normalized.title = params.title.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
normalized.body = params.body.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
normalized.promptId = self.trimmedOrNil(params.promptId)
|
||||
normalized.sessionKey = self.trimmedOrNil(params.sessionKey)
|
||||
normalized.kind = self.trimmedOrNil(params.kind)
|
||||
normalized.details = self.trimmedOrNil(params.details)
|
||||
normalized.priority = self.normalizedWatchPriority(params.priority, risk: params.risk)
|
||||
normalized.risk = self.normalizedWatchRisk(params.risk, priority: normalized.priority)
|
||||
|
||||
let normalizedActions = self.normalizeWatchActions(
|
||||
params.actions,
|
||||
kind: normalized.kind,
|
||||
promptId: normalized.promptId)
|
||||
normalized.actions = normalizedActions.isEmpty ? nil : normalizedActions
|
||||
return normalized
|
||||
}
|
||||
|
||||
static func normalizeWatchActions(
|
||||
_ actions: [OpenClawWatchAction]?,
|
||||
kind: String?,
|
||||
promptId: String?) -> [OpenClawWatchAction]
|
||||
{
|
||||
let provided = (actions ?? []).compactMap { action -> OpenClawWatchAction? in
|
||||
let id = action.id.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let label = action.label.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !id.isEmpty, !label.isEmpty else { return nil }
|
||||
return OpenClawWatchAction(
|
||||
id: id,
|
||||
label: label,
|
||||
style: self.trimmedOrNil(action.style))
|
||||
}
|
||||
if !provided.isEmpty {
|
||||
return Array(provided.prefix(4))
|
||||
}
|
||||
|
||||
// Only auto-insert quick actions when this is a prompt/decision flow.
|
||||
guard promptId?.isEmpty == false else {
|
||||
return []
|
||||
}
|
||||
|
||||
let normalizedKind = kind?.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() ?? ""
|
||||
if normalizedKind.contains("approval") || normalizedKind.contains("approve") {
|
||||
return [
|
||||
OpenClawWatchAction(id: "approve", label: "Approve"),
|
||||
OpenClawWatchAction(id: "decline", label: "Decline", style: "destructive"),
|
||||
OpenClawWatchAction(id: "open_phone", label: "Open iPhone"),
|
||||
OpenClawWatchAction(id: "escalate", label: "Escalate"),
|
||||
]
|
||||
}
|
||||
|
||||
return [
|
||||
OpenClawWatchAction(id: "done", label: "Done"),
|
||||
OpenClawWatchAction(id: "snooze_10m", label: "Snooze 10m"),
|
||||
OpenClawWatchAction(id: "open_phone", label: "Open iPhone"),
|
||||
OpenClawWatchAction(id: "escalate", label: "Escalate"),
|
||||
]
|
||||
}
|
||||
|
||||
static func normalizedWatchRisk(
|
||||
_ risk: OpenClawWatchRisk?,
|
||||
priority: OpenClawNotificationPriority?) -> OpenClawWatchRisk?
|
||||
{
|
||||
if let risk { return risk }
|
||||
switch priority {
|
||||
case .passive:
|
||||
return .low
|
||||
case .active:
|
||||
return .medium
|
||||
case .timeSensitive:
|
||||
return .high
|
||||
case nil:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
static func normalizedWatchPriority(
|
||||
_ priority: OpenClawNotificationPriority?,
|
||||
risk: OpenClawWatchRisk?) -> OpenClawNotificationPriority?
|
||||
{
|
||||
if let priority { return priority }
|
||||
switch risk {
|
||||
case .low:
|
||||
return .passive
|
||||
case .medium:
|
||||
return .active
|
||||
case .high:
|
||||
return .timeSensitive
|
||||
case nil:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
static func trimmedOrNil(_ value: String?) -> String? {
|
||||
let trimmed = value?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
return trimmed.isEmpty ? nil : trimmed
|
||||
}
|
||||
}
|
||||
5413
apps/ios/Sources/Model/NodeAppModel.swift
Normal file
5413
apps/ios/Sources/Model/NodeAppModel.swift
Normal file
File diff suppressed because it is too large
Load Diff
203
apps/ios/Sources/Model/WatchReplyCoordinator.swift
Normal file
203
apps/ios/Sources/Model/WatchReplyCoordinator.swift
Normal file
@@ -0,0 +1,203 @@
|
||||
import Foundation
|
||||
|
||||
@MainActor
|
||||
final class WatchReplyCoordinator {
|
||||
enum Decision {
|
||||
case dropMissingFields
|
||||
case deduped(replyId: String)
|
||||
case queue(replyId: String, actionId: String)
|
||||
case forward
|
||||
}
|
||||
|
||||
private var queuedReplies: [WatchQuickReplyEvent] = []
|
||||
private var seenReplyIds = Set<String>()
|
||||
|
||||
func ingest(_ event: WatchQuickReplyEvent, isGatewayConnected: Bool) -> Decision {
|
||||
let replyId = event.replyId.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let actionId = event.actionId.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
if replyId.isEmpty || actionId.isEmpty {
|
||||
return .dropMissingFields
|
||||
}
|
||||
if self.seenReplyIds.contains(replyId) {
|
||||
return .deduped(replyId: replyId)
|
||||
}
|
||||
self.seenReplyIds.insert(replyId)
|
||||
if !isGatewayConnected {
|
||||
self.queuedReplies.append(event)
|
||||
return .queue(replyId: replyId, actionId: actionId)
|
||||
}
|
||||
return .forward
|
||||
}
|
||||
|
||||
func drainIfConnected(_ isGatewayConnected: Bool) -> [WatchQuickReplyEvent] {
|
||||
guard isGatewayConnected, !self.queuedReplies.isEmpty else { return [] }
|
||||
let pending = self.queuedReplies
|
||||
self.queuedReplies.removeAll()
|
||||
return pending
|
||||
}
|
||||
|
||||
func requeueFront(_ event: WatchQuickReplyEvent) {
|
||||
self.queuedReplies.insert(event, at: 0)
|
||||
}
|
||||
|
||||
var queuedCount: Int {
|
||||
self.queuedReplies.count
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
final class WatchChatCoordinator {
|
||||
enum Decision {
|
||||
case dropMissingFields
|
||||
case dropMissingTarget
|
||||
case deduped(commandId: String)
|
||||
case queue(commandId: String)
|
||||
case forward
|
||||
}
|
||||
|
||||
private static let persistedQueueKey = "watch.chat.command.queue.v1"
|
||||
private static let maxRecentCommandIds = 128
|
||||
|
||||
private struct QueuedCommand: Codable, Equatable {
|
||||
var gatewayStableID: String
|
||||
var event: WatchAppCommandEvent
|
||||
}
|
||||
|
||||
private let defaults: UserDefaults
|
||||
private var queuedCommands: [QueuedCommand] = []
|
||||
private var recentCommandIds: [String] = []
|
||||
private var seenCommandIds = Set<String>()
|
||||
|
||||
init(defaults: UserDefaults = .standard) {
|
||||
self.defaults = defaults
|
||||
self.restoreQueue()
|
||||
}
|
||||
|
||||
func ingest(
|
||||
_ event: WatchAppCommandEvent,
|
||||
isChatAvailable: Bool,
|
||||
gatewayStableID: String?) -> Decision
|
||||
{
|
||||
let commandId = event.commandId.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let text = event.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
if commandId.isEmpty || text.isEmpty {
|
||||
return .dropMissingFields
|
||||
}
|
||||
if self.seenCommandIds.contains(commandId) {
|
||||
return .deduped(commandId: commandId)
|
||||
}
|
||||
self.rememberRecentCommandId(commandId)
|
||||
if !isChatAvailable {
|
||||
let owner = gatewayStableID?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
guard !owner.isEmpty else { return .dropMissingTarget }
|
||||
self.queuedCommands.append(
|
||||
QueuedCommand(gatewayStableID: owner, event: self.command(event, taggedFor: owner)))
|
||||
self.rebuildSeenCommandIds()
|
||||
self.persistQueue()
|
||||
return .queue(commandId: commandId)
|
||||
}
|
||||
return .forward
|
||||
}
|
||||
|
||||
func nextQueuedCommand(isChatAvailable: Bool, gatewayStableID: String?) -> WatchAppCommandEvent? {
|
||||
let owner = gatewayStableID?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
guard isChatAvailable, !owner.isEmpty else { return nil }
|
||||
return self.queuedCommands.first { $0.gatewayStableID == owner }?.event
|
||||
}
|
||||
|
||||
func removeQueuedCommand(commandId: String, gatewayStableID: String?) {
|
||||
let commandId = commandId.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let owner = gatewayStableID?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
guard !commandId.isEmpty, !owner.isEmpty else { return }
|
||||
guard let index = self.queuedCommands.firstIndex(where: {
|
||||
$0.gatewayStableID == owner && $0.event.commandId == commandId
|
||||
}) else { return }
|
||||
self.queuedCommands.remove(at: index)
|
||||
self.rememberRecentCommandId(commandId)
|
||||
self.persistQueue()
|
||||
}
|
||||
|
||||
func requeueFront(_ event: WatchAppCommandEvent, gatewayStableID: String?) {
|
||||
let commandId = event.commandId.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let owner = gatewayStableID?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
guard !owner.isEmpty else { return }
|
||||
if !commandId.isEmpty {
|
||||
self.rememberRecentCommandId(commandId)
|
||||
self.queuedCommands.removeAll { $0.event.commandId == commandId }
|
||||
}
|
||||
self.queuedCommands.insert(
|
||||
QueuedCommand(gatewayStableID: owner, event: self.command(event, taggedFor: owner)),
|
||||
at: 0)
|
||||
self.rebuildSeenCommandIds()
|
||||
self.persistQueue()
|
||||
}
|
||||
|
||||
var queuedCount: Int {
|
||||
self.queuedCommands.count
|
||||
}
|
||||
|
||||
var queuedCommandIds: [String] {
|
||||
self.queuedCommands.map(\.event.commandId)
|
||||
}
|
||||
|
||||
private func restoreQueue() {
|
||||
guard let data = defaults.data(forKey: Self.persistedQueueKey),
|
||||
let persisted = try? JSONDecoder().decode([QueuedCommand].self, from: data)
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
var seen: [String] = []
|
||||
var seenSet = Set<String>()
|
||||
self.queuedCommands = persisted.compactMap { queued in
|
||||
let owner = queued.gatewayStableID.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let commandId = queued.event.commandId.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let text = queued.event.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
guard !owner.isEmpty, !commandId.isEmpty, !text.isEmpty, seenSet.insert(commandId).inserted else {
|
||||
return nil
|
||||
}
|
||||
seen.append(commandId)
|
||||
return QueuedCommand(gatewayStableID: owner, event: self.command(queued.event, taggedFor: owner))
|
||||
}
|
||||
self.recentCommandIds = Array(seen.suffix(Self.maxRecentCommandIds))
|
||||
self.rebuildSeenCommandIds()
|
||||
if self.queuedCommands.count != persisted.count {
|
||||
self.persistQueue()
|
||||
}
|
||||
}
|
||||
|
||||
private func rememberRecentCommandId(_ commandId: String) {
|
||||
guard !commandId.isEmpty else { return }
|
||||
self.recentCommandIds.removeAll { $0 == commandId }
|
||||
self.recentCommandIds.append(commandId)
|
||||
if self.recentCommandIds.count > Self.maxRecentCommandIds {
|
||||
self.recentCommandIds.removeFirst(self.recentCommandIds.count - Self.maxRecentCommandIds)
|
||||
}
|
||||
self.rebuildSeenCommandIds()
|
||||
}
|
||||
|
||||
private func rebuildSeenCommandIds() {
|
||||
var ids = Set(self.recentCommandIds)
|
||||
ids.formUnion(self.queuedCommands.map(\.event.commandId))
|
||||
self.seenCommandIds = ids
|
||||
}
|
||||
|
||||
private func persistQueue() {
|
||||
if self.queuedCommands.isEmpty {
|
||||
self.defaults.removeObject(forKey: Self.persistedQueueKey)
|
||||
return
|
||||
}
|
||||
guard let data = try? JSONEncoder().encode(queuedCommands) else { return }
|
||||
self.defaults.set(data, forKey: Self.persistedQueueKey)
|
||||
}
|
||||
|
||||
private func command(_ event: WatchAppCommandEvent, taggedFor gatewayStableID: String) -> WatchAppCommandEvent {
|
||||
var tagged = event
|
||||
tagged.gatewayStableID = gatewayStableID
|
||||
return tagged
|
||||
}
|
||||
|
||||
static func resetPersistedQueue(defaults: UserDefaults = .standard) {
|
||||
defaults.removeObject(forKey: self.persistedQueueKey)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user