commit d070ed3e091b8ca44591ce96c6cae39837bf3f02
parent d4cc69a6714c40a3ed85a60add38588090cbe57f
Author: Michael Camilleri <[email protected]>
Date: Tue, 20 Oct 2026 23:27:03 +0900
Fix timing of reports prompted by notifications
Diffstat
| M | Notes/Design.md | | | 8 | ++++---- |
| M | Reportage/Services/Prompts/PromptNotification.swift | | | 6 | +++--- |
| M | Tests/Unit/PromptSchedulerTests.swift | | | 4 | ++-- |
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/Notes/Design.md b/Notes/Design.md
@@ -233,7 +233,7 @@ stored blank, so it isn't filled again. | Field | Notes | |---------------|--------------------------------------------------------------| | `id` | UUID. Imported reports keep Reporter's `uniqueIdentifier`, which makes re-import idempotent. | -| `date` | The moment being described: when the prompt fired or the passive log was tapped, not when the survey was finished. | +| `date` | The moment being described: when the prompt notification or the passive log was tapped, not when the survey was finished. | | `timeZone` | IANA identifier, stored explicitly. Reporter didn't do this and its export lost every report's local time. | | `kind` | `random`, `wake`, `bedtime`, `manual`. | | `trigger` | `notification`, `app`, `watch`, `intent` (Shortcuts, Control Center, Action button), `imported`. | @@ -560,9 +560,9 @@ Category `prompt`: - **Snooze** runs in the background and schedules a one-off repeat of the prompt in 15 minutes (configurable). The snoozed prompt keeps the original `promptedAt`. -- **Tapping the notification** opens the survey with `date` set to the fire - time (for a snoozed prompt, when the repeat came) and `promptedAt` set to - when the prompt first fired. If a survey or Settings is already open, it +- **Tapping the notification** opens the survey with `date` set to when the + notification was tapped and `promptedAt` set to when the prompt first + fired. If a survey or Settings is already open, it waits until that closes. Location for background actions requires 'Always' authorisation, and
diff --git a/Reportage/Services/Prompts/PromptNotification.swift b/Reportage/Services/Prompts/PromptNotification.swift
@@ -146,10 +146,10 @@ struct PromptResponder: Sendable {
promptedAt: response.firedAt, delay: TimeInterval(settings.snooze * 60)))
return nil
case UNNotificationDefaultActionIdentifier:
- // The report describes when the notification came, which for a
- // snoozed prompt is after it was first sent.
+ // The report describes when the notification was tapped, not
+ // when it came.
return SurveyRequest(
- kind: .random, date: response.deliveredAt, trigger: .notification,
+ kind: .random, date: now, trigger: .notification,
promptedAt: response.firedAt)
default:
return nil
diff --git a/Tests/Unit/PromptSchedulerTests.swift b/Tests/Unit/PromptSchedulerTests.swift
@@ -190,14 +190,14 @@ struct PromptResponderTests {
#expect(delivered.firedAt == Self.firedAt)
}
- @Test("Tapping a prompt opens a random survey for when it came")
+ @Test("Tapping a prompt opens a random survey for when it was tapped")
func tap() async throws {
let survey = try #require(
try await responder.respond(
to: Self.response(UNNotificationDefaultActionIdentifier, snoozed: true),
settings: PromptSettings(), now: Self.now))
#expect(survey.kind == .random)
- #expect(survey.date == Self.deliveredAt)
+ #expect(survey.date == Self.now)
#expect(survey.trigger == .notification)
#expect(survey.promptedAt == Self.firedAt)
#expect(survey.reportID == nil)