Skip to content

Commit fe62a2e

Browse files
committed
refactor(chat-ui): split session actions
1 parent e96789b commit fe62a2e

3 files changed

Lines changed: 46 additions & 43 deletions

File tree

apps/.i18n/native-source.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22555,31 +22555,31 @@
2255522555
},
2255622556
{
2255722557
"kind": "conditional-branch",
22558-
"line": 1516,
22558+
"line": 1481,
2255922559
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel.swift",
2256022560
"source": "delivery unconfirmed",
2256122561
"surface": "apple",
2256222562
"id": "native.apple.2b45abdc56b2caed"
2256322563
},
2256422564
{
2256522565
"kind": "conditional-branch",
22566-
"line": 1516,
22566+
"line": 1481,
2256722567
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel.swift",
2256822568
"source": "queued after route change",
2256922569
"surface": "apple",
2257022570
"id": "native.apple.722f1f90b97e8e45"
2257122571
},
2257222572
{
2257322573
"kind": "ui-localized-call",
22574-
"line": 1740,
22574+
"line": 1705,
2257522575
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel.swift",
2257622576
"source": "Remove attachments or wait for delivery to resolve before switching chats.",
2257722577
"surface": "apple",
2257822578
"id": "native.apple.710c7bd117a7cc12"
2257922579
},
2258022580
{
2258122581
"kind": "ui-localized-call",
22582-
"line": 1796,
22582+
"line": 1761,
2258322583
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel.swift",
2258422584
"source": "Remove attachments or wait for delivery to resolve before starting a new chat.",
2258522585
"surface": "apple",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Foundation
2+
3+
extension OpenClawChatViewModel {
4+
public func refreshSessions(limit: Int? = nil) {
5+
let context = self.currentSessionSnapshot()
6+
Task { await self.fetchSessions(limit: limit, sessionSnapshot: context) }
7+
}
8+
9+
public func startNewSession(worktree: Bool = false) async {
10+
await self.performStartNewSession(worktree: worktree)
11+
}
12+
13+
public func requestSessionReset() {
14+
Task { await self.performReset() }
15+
}
16+
17+
public func requestSessionCompact() {
18+
Task { await self.performCompact() }
19+
}
20+
21+
public func setSessionPinned(_ sessionKey: String, pinned: Bool) {
22+
Task {
23+
do {
24+
try await self.transport.patchSession(
25+
key: sessionKey,
26+
label: nil,
27+
category: nil,
28+
pinned: pinned,
29+
archived: nil,
30+
unread: nil)
31+
} catch {
32+
self.errorText = error.localizedDescription
33+
return
34+
}
35+
await self.fetchSessions(limit: nil, sessionSnapshot: self.currentSessionSnapshot())
36+
}
37+
}
38+
}

apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel.swift

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -369,41 +369,6 @@ public final class OpenClawChatViewModel {
369369
Task { await self.performAbort() }
370370
}
371371

372-
public func refreshSessions(limit: Int? = nil) {
373-
let context = self.currentSessionSnapshot()
374-
Task { await self.fetchSessions(limit: limit, sessionSnapshot: context) }
375-
}
376-
377-
public func startNewSession(worktree: Bool = false) async {
378-
await self.performStartNewSession(worktree: worktree)
379-
}
380-
381-
public func requestSessionReset() {
382-
Task { await self.performReset() }
383-
}
384-
385-
public func requestSessionCompact() {
386-
Task { await self.performCompact() }
387-
}
388-
389-
public func setSessionPinned(_ sessionKey: String, pinned: Bool) {
390-
Task {
391-
do {
392-
try await self.transport.patchSession(
393-
key: sessionKey,
394-
label: nil,
395-
category: nil,
396-
pinned: pinned,
397-
archived: nil,
398-
unread: nil)
399-
} catch {
400-
self.errorText = error.localizedDescription
401-
return
402-
}
403-
await self.fetchSessions(limit: nil, sessionSnapshot: self.currentSessionSnapshot())
404-
}
405-
}
406-
407372
public func deleteSession(_ sessionKey: String) {
408373
Task {
409374
do {
@@ -1565,7 +1530,7 @@ public final class OpenClawChatViewModel {
15651530
}
15661531
}
15671532

1568-
private func fetchSessions(limit: Int?, sessionSnapshot: SessionSnapshot? = nil) async {
1533+
func fetchSessions(limit: Int?, sessionSnapshot: SessionSnapshot? = nil) async {
15691534
do {
15701535
let res = try await transport.listSessions(limit: limit, search: nil, archived: false)
15711536
if let sessionSnapshot, !self.isCurrentSession(sessionSnapshot) { return }
@@ -1765,7 +1730,7 @@ public final class OpenClawChatViewModel {
17651730
self.applySessionSwitch(to: sessionKey, intent: .externalSync)
17661731
}
17671732

1768-
private func performStartNewSession(worktree: Bool) async {
1733+
func performStartNewSession(worktree: Bool) async {
17691734
guard !self.blocksAttachmentOwnerChange else {
17701735
self.errorText = String(
17711736
localized: "Remove attachments or wait for delivery to resolve before starting a new chat.")
@@ -1828,7 +1793,7 @@ public final class OpenClawChatViewModel {
18281793
&& nsError.localizedDescription == "sessions.create not supported by this transport"
18291794
}
18301795

1831-
private func performReset() async {
1796+
func performReset() async {
18321797
self.isLoading = true
18331798
self.errorText = nil
18341799

@@ -1846,7 +1811,7 @@ public final class OpenClawChatViewModel {
18461811
self.startBootstrap()
18471812
}
18481813

1849-
private func performCompact() async {
1814+
func performCompact() async {
18501815
guard !self.isCompacting else { return }
18511816
guard !self.isSending, self.pendingRuns.isEmpty, !self.isAborting else {
18521817
self.errorText = "Wait for the current response before compacting the session."

0 commit comments

Comments
 (0)