Show event label and first paragraph in notifications

This commit is contained in:
Ian Gulliver
2026-10-20 21:49:01 -07:00
parent da824b9728
commit c67c215118
3 changed files with 33 additions and 13 deletions
+31 -11
View File
@@ -54,11 +54,31 @@ private func enqueue(_ op: @escaping @MainActor () async -> Void) {
}
@MainActor
private func show(_ store: Store, _ taskId: String, _ tag: String, _ text: String) {
let line = trimmed(text).split(separator: "\n", omittingEmptySubsequences: false).first.map(String.init) ?? ""
private func preview(_ text: String) -> String {
var lines: [String] = []
for raw in text.split(separator: "\n", omittingEmptySubsequences: false) {
var line = trimmed(String(raw))
if line.isEmpty || line.hasPrefix("#") || line.hasPrefix("<") || line.hasPrefix("```") {
if lines.isEmpty {
continue
}
break
}
for marker in ["- ", "* ", "> "] where line.hasPrefix(marker) {
line = trimmed(String(line.dropFirst(marker.count)))
}
lines.append((try? AttributedString(markdown: line)).map { String($0.characters) } ?? line)
}
let body = lines.joined(separator: " ")
return body.count > 200 ? "\(body.prefix(199))…" : body
}
@MainActor
private func show(_ store: Store, _ taskId: String, _ tag: String, _ kind: String, _ text: String) {
let content = UNMutableNotificationContent()
content.title = store.findTask(taskId).map { "byre · \($0.name)" } ?? "byre"
content.body = line.count > 200 ? "\(line.prefix(199))…" : line
content.subtitle = kind
content.body = preview(text)
content.sound = .default
content.userInfo = ["task_id": taskId, "origin": store.api.origin.absoluteString]
let request = UNNotificationRequest(identifier: tag, content: content, trigger: nil)
@@ -80,7 +100,7 @@ func notifyInbox(_ store: Store, _ item: InboxItem) {
guard let me = store.me, me.notificationPrefs.questions, item.state == .open else {
return
}
show(store, item.taskId, item.id, str(item.payload.value, "question") ?? "")
show(store, item.taskId, item.id, "Question", str(item.payload.value, "question") ?? "")
}
@MainActor
@@ -92,7 +112,7 @@ func notifyError(_ store: Store, _ ev: ByreEvent) {
if !(limited ? me.notificationPrefs.rateLimits : me.notificationPrefs.errors) {
return
}
show(store, taskId, "error-\(ev.seq)@\(store.api.origin.absoluteString)", limited ? "Rate limited" : "Error: \(str(ev.payload.value, "error") ?? "")")
show(store, taskId, "error-\(ev.seq)@\(store.api.origin.absoluteString)", limited ? "Rate limited" : "Error", limited ? "" : str(ev.payload.value, "error") ?? "")
}
@MainActor
@@ -128,15 +148,15 @@ func notifyTask(_ store: Store, _ ev: ByreEvent) {
let background = store.findTask(taskId)?.background == true
switch ev.kind {
case "task.ready" where prefs.ready:
show(store, taskId, "task-\(taskId)@\(origin)", "Ready to merge: \(str(ev.payload.value, "overview") ?? "")")
show(store, taskId, "task-\(taskId)@\(origin)", "Ready to merge", str(ev.payload.value, "overview") ?? "")
case "task.discard_suggested" where prefs.discard && !background:
show(store, taskId, "task-\(taskId)@\(origin)", "Suggests discard: \(str(ev.payload.value, "reason") ?? "")")
show(store, taskId, "task-\(taskId)@\(origin)", "Suggests discard", str(ev.payload.value, "reason") ?? "")
case "task.merge_stopped" where prefs.mergeProblems:
show(store, taskId, "task-\(taskId)@\(origin)", "Merge stopped: \(str(ev.payload.value, "reason") ?? "")")
show(store, taskId, "task-\(taskId)@\(origin)", "Merge stopped", str(ev.payload.value, "reason") ?? "")
case "task.merge_after_review_dropped" where prefs.mergeProblems:
show(store, taskId, "task-\(taskId)@\(origin)", "Didn't merge after the review: \(str(ev.payload.value, "reason") ?? "")")
show(store, taskId, "task-\(taskId)@\(origin)", "Didn't merge after the review", str(ev.payload.value, "reason") ?? "")
case "task.workflow_finished" where prefs.workflows && !background:
show(store, taskId, "workflow-\(ev.seq)@\(origin)", "Finished \(str(ev.payload.value, "workflow") ?? ""): \(str(ev.payload.value, "output") ?? "")")
show(store, taskId, "workflow-\(ev.seq)@\(origin)", "Finished \(str(ev.payload.value, "workflow") ?? "")", str(ev.payload.value, "output") ?? "")
default:
break
}
@@ -155,5 +175,5 @@ func notifyTurn(_ store: Store, _ ev: ByreEvent) {
guard let me = store.me, me.notificationPrefs.reports, ev.payload.value["summary"] as? Bool == true, let taskId = ev.taskId, !taskId.isEmpty, store.findTask(taskId)?.background != true else {
return
}
show(store, taskId, "turn-\(ev.seq)@\(store.api.origin.absoluteString)", str(ev.payload.value, "result") ?? "")
show(store, taskId, "turn-\(ev.seq)@\(store.api.origin.absoluteString)", "Turn finished", str(ev.payload.value, "result") ?? "")
}