refactor: normalize group session keys
This commit is contained in:
@@ -79,7 +79,7 @@ struct ContextMenuCardView: View {
|
||||
height: self.barHeight)
|
||||
|
||||
HStack(alignment: .firstTextBaseline, spacing: 8) {
|
||||
Text(row.key)
|
||||
Text(row.label)
|
||||
.font(.caption.weight(row.key == "main" ? .semibold : .regular))
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
|
||||
@@ -8,6 +8,11 @@ struct GatewaySessionDefaultsRecord: Codable {
|
||||
|
||||
struct GatewaySessionEntryRecord: Codable {
|
||||
let key: String
|
||||
let displayName: String?
|
||||
let surface: String?
|
||||
let subject: String?
|
||||
let room: String?
|
||||
let space: String?
|
||||
let updatedAt: Double?
|
||||
let sessionId: String?
|
||||
let systemSent: Bool?
|
||||
@@ -65,6 +70,11 @@ struct SessionRow: Identifiable {
|
||||
let id: String
|
||||
let key: String
|
||||
let kind: SessionKind
|
||||
let displayName: String?
|
||||
let surface: String?
|
||||
let subject: String?
|
||||
let room: String?
|
||||
let space: String?
|
||||
let updatedAt: Date?
|
||||
let sessionId: String?
|
||||
let thinkingLevel: String?
|
||||
@@ -75,6 +85,7 @@ struct SessionRow: Identifiable {
|
||||
let model: String?
|
||||
|
||||
var ageText: String { relativeAge(from: self.updatedAt) }
|
||||
var label: String { self.displayName ?? self.key }
|
||||
|
||||
var flagLabels: [String] {
|
||||
var flags: [String] = []
|
||||
@@ -92,6 +103,8 @@ enum SessionKind {
|
||||
static func from(key: String) -> SessionKind {
|
||||
if key == "global" { return .global }
|
||||
if key.hasPrefix("group:") { return .group }
|
||||
if key.contains(":group:") { return .group }
|
||||
if key.contains(":channel:") { return .group }
|
||||
if key == "unknown" { return .unknown }
|
||||
return .direct
|
||||
}
|
||||
@@ -127,6 +140,11 @@ extension SessionRow {
|
||||
id: "direct-1",
|
||||
key: "user@example.com",
|
||||
kind: .direct,
|
||||
displayName: nil,
|
||||
surface: nil,
|
||||
subject: nil,
|
||||
room: nil,
|
||||
space: nil,
|
||||
updatedAt: Date().addingTimeInterval(-90),
|
||||
sessionId: "sess-direct-1234",
|
||||
thinkingLevel: "low",
|
||||
@@ -137,8 +155,13 @@ extension SessionRow {
|
||||
model: "claude-3.5-sonnet"),
|
||||
SessionRow(
|
||||
id: "group-1",
|
||||
key: "group:engineering",
|
||||
key: "discord:channel:release-squad",
|
||||
kind: .group,
|
||||
displayName: "discord:#release-squad",
|
||||
surface: "discord",
|
||||
subject: nil,
|
||||
room: "#release-squad",
|
||||
space: nil,
|
||||
updatedAt: Date().addingTimeInterval(-3600),
|
||||
sessionId: "sess-group-4321",
|
||||
thinkingLevel: "medium",
|
||||
@@ -151,6 +174,11 @@ extension SessionRow {
|
||||
id: "global",
|
||||
key: "global",
|
||||
kind: .global,
|
||||
displayName: nil,
|
||||
surface: nil,
|
||||
subject: nil,
|
||||
room: nil,
|
||||
space: nil,
|
||||
updatedAt: Date().addingTimeInterval(-86400),
|
||||
sessionId: nil,
|
||||
thinkingLevel: nil,
|
||||
@@ -269,6 +297,11 @@ enum SessionLoader {
|
||||
id: entry.key,
|
||||
key: entry.key,
|
||||
kind: SessionKind.from(key: entry.key),
|
||||
displayName: entry.displayName,
|
||||
surface: entry.surface,
|
||||
subject: entry.subject,
|
||||
room: entry.room,
|
||||
space: entry.space,
|
||||
updatedAt: updated,
|
||||
sessionId: entry.sessionId,
|
||||
thinkingLevel: entry.thinkingLevel,
|
||||
|
||||
@@ -36,7 +36,7 @@ struct SessionMenuLabelView: View {
|
||||
height: self.barHeight)
|
||||
|
||||
HStack(alignment: .firstTextBaseline, spacing: 8) {
|
||||
Text(self.row.key)
|
||||
Text(self.row.label)
|
||||
.font(.caption.weight(self.row.key == "main" ? .semibold : .regular))
|
||||
.foregroundStyle(self.primaryTextColor)
|
||||
.lineLimit(1)
|
||||
|
||||
@@ -89,7 +89,7 @@ struct SessionsSettings: View {
|
||||
private func sessionRow(_ row: SessionRow) -> some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 8) {
|
||||
Text(row.key)
|
||||
Text(row.label)
|
||||
.font(.subheadline.bold())
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
|
||||
@@ -29,6 +29,11 @@ struct MenuSessionsInjectorTests {
|
||||
id: "main",
|
||||
key: "main",
|
||||
kind: .direct,
|
||||
displayName: nil,
|
||||
surface: nil,
|
||||
subject: nil,
|
||||
room: nil,
|
||||
space: nil,
|
||||
updatedAt: Date(),
|
||||
sessionId: "s1",
|
||||
thinkingLevel: "low",
|
||||
@@ -38,9 +43,14 @@ struct MenuSessionsInjectorTests {
|
||||
tokens: SessionTokenStats(input: 10, output: 20, total: 30, contextTokens: 200_000),
|
||||
model: "claude-opus-4-5"),
|
||||
SessionRow(
|
||||
id: "group:alpha",
|
||||
key: "group:alpha",
|
||||
id: "discord:group:alpha",
|
||||
key: "discord:group:alpha",
|
||||
kind: .group,
|
||||
displayName: nil,
|
||||
surface: nil,
|
||||
subject: nil,
|
||||
room: nil,
|
||||
space: nil,
|
||||
updatedAt: Date(timeIntervalSinceNow: -60),
|
||||
sessionId: "s2",
|
||||
thinkingLevel: "high",
|
||||
|
||||
@@ -6,7 +6,7 @@ import Testing
|
||||
struct SessionDataTests {
|
||||
@Test func sessionKindFromKeyDetectsCommonKinds() {
|
||||
#expect(SessionKind.from(key: "global") == .global)
|
||||
#expect(SessionKind.from(key: "group:engineering") == .group)
|
||||
#expect(SessionKind.from(key: "discord:group:engineering") == .group)
|
||||
#expect(SessionKind.from(key: "unknown") == .unknown)
|
||||
#expect(SessionKind.from(key: "user@example.com") == .direct)
|
||||
}
|
||||
@@ -27,6 +27,11 @@ struct SessionDataTests {
|
||||
id: "x",
|
||||
key: "user@example.com",
|
||||
kind: .direct,
|
||||
displayName: nil,
|
||||
surface: nil,
|
||||
subject: nil,
|
||||
room: nil,
|
||||
space: nil,
|
||||
updatedAt: Date(),
|
||||
sessionId: nil,
|
||||
thinkingLevel: "high",
|
||||
@@ -41,4 +46,3 @@ struct SessionDataTests {
|
||||
#expect(row.flagLabels.contains("aborted"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ struct WorkActivityStoreTests {
|
||||
@Test func mainSessionJobPreemptsOther() {
|
||||
let store = WorkActivityStore()
|
||||
|
||||
store.handleJob(sessionKey: "group:1", state: "started")
|
||||
store.handleJob(sessionKey: "discord:group:1", state: "started")
|
||||
#expect(store.iconState == .workingOther(.job))
|
||||
#expect(store.current?.sessionKey == "group:1")
|
||||
#expect(store.current?.sessionKey == "discord:group:1")
|
||||
|
||||
store.handleJob(sessionKey: "main", state: "started")
|
||||
#expect(store.iconState == .workingMain(.job))
|
||||
@@ -18,9 +18,9 @@ struct WorkActivityStoreTests {
|
||||
|
||||
store.handleJob(sessionKey: "main", state: "finished")
|
||||
#expect(store.iconState == .workingOther(.job))
|
||||
#expect(store.current?.sessionKey == "group:1")
|
||||
#expect(store.current?.sessionKey == "discord:group:1")
|
||||
|
||||
store.handleJob(sessionKey: "group:1", state: "finished")
|
||||
store.handleJob(sessionKey: "discord:group:1", state: "finished")
|
||||
#expect(store.iconState == .idle)
|
||||
#expect(store.current == nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user