Calendar: in-app reminders (Paul 2026-11-01), WIP before mutation testing
A reminder channel "inapp" (and "both") beside email. The drain decides on the recipient's standing exactly as for email, then marks a reference-only reminder_notices row under the claim instead of sending. Home-only members get in-app by default and only; people with an address choose on Settings. /reminders lists and dismisses; the chrome links it with the unread count. Spec §7 "In-app reminders" and AGENTS.md row T2. Also: the drain's claimed-twice guard is keyed by rule and occurrence, not occurrence alone, so two rules on one occurrence no longer stop the pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 files changed,
+1,296
−101
AGENTS.md+10 −3docs/superpowers/specs/2026-09-02-calendar-design.md+127 −1internal/calendar/funcs.go+14 −0internal/calendar/handlers_events.go+5 −0internal/calendar/handlers_jobs.go+22 −2internal/calendar/handlers_misc.go+0 −25internal/calendar/handlers_reminders.go+186 −0internal/calendar/handlers_settings.go+3 −2internal/calendar/inapp_reminders_test.go+144 −0internal/calendar/migrations/0007_create_reminder_notices.sql+8 −0internal/calendar/migrations/schema.sql+7 −1internal/calendar/models.go+7 −0internal/calendar/models_event.go+27 −0internal/calendar/reminder_seam.go+83 −0internal/calendar/render.go+2 −10internal/calendar/routes.go+6 −0internal/calendar/serving.go+10 −0internal/calendar/store_drain.go+4 −0internal/calendar/store_feed.go+16 −10internal/calendar/store_reminder.go+26 −13internal/calendar/store_reminder_notice.go+192 −0internal/calendar/team_guard_test.go+5 −1internal/calendar/team_inapp_test.go+242 −0internal/calendar/team_jobs.go+27 −5internal/calendar/team_jobs_test.go+30 −19internal/calendar/team_world_test.go+16 −0internal/calendar/templates/event.html+10 −4internal/calendar/templates/reminders.html+47 −0internal/calendar/templates/settings.html+9 −1internal/calendartest/schedule_progress_test.go+11 −4
Intent
diff --git a/AGENTS.md b/AGENTS.md| index 484bd79..db91587 100644 |
| --- a/AGENTS.md |
| +++ b/AGENTS.md |
| @@ -65,6 +65,7 @@ pass by reading a file the data has not reached. |
| | 8 | A new event defaults to the person's PERSONAL calendar | Defaulting to the team calendar — the cost of forgetting to change a dropdown should fall on the side of privacy | This session, 2026-09-02 | |
| | H1 | **Optional Home sign-in connects to an existing person after fresh local proof and explicit confirmation; local sign-in remains available** | Treating the Home subject as an email or allocating a new person | User-approved suite connection, 2026-09-10 | |
| | T1 | **Team mode (`CALENDAR_TEAM_*`): Home's roster decides standing on every request**; a roster Member with no account here gets an addressless Home-only person through connect's `Unlinked` hook (H1 holds outside team mode) | The allowlist deciding a team instance; storing an address for a Home-only member (a new address column: its own privacy review, Fable on oficina/home #98) | Home team-members.md Part B (Fable #92), Paul's port order 2026-10-27; spec §7 "Roster team mode" | |
| +| T2 | **In-app reminders**: a reminder channel `inapp` (and `both`) whose delivery writes a reference-only notice (event, occurrence, person) in Calendar's own database; Home-only members get it by default and only it; people with an address choose on Settings | Option (b), an opt-in typed address stored sealed (a new address column, its own privacy review); option (c), reminders only through linked local accounts | Paul, 2026-11-01; Fable's recommendation on oficina/calendar #35; spec §7 "In-app reminders" | |
| | B1 | A booking is confirmed by a BUTTON on the page the mailed link opens — a same-origin POST — never on submit and never on GET | Instant confirmation; confirming on the GET, which every link-scanning mail gateway would press | Booking spec §1, 2026-09-07 | |
| | B2 | Everything the host can see is busy — every calendar they hold a grant on | Personal only | Booking spec §1, 2026-09-07 | |
| | B4 | The public identifier is a chosen plaintext `handle` plus a GENERATED page code | A chosen slug — prose joined to events | Booking spec §1, 2026-09-07 | |
| @@ -324,9 +325,15 @@ every rule above stands; the one difference is `GET /api/team` answering |
| - **Home-only people have no address** (`team_home_only.go`, |
| `teamstate/`): their `people.address` is a `home-only:` placeholder the |
| triggers keep that way. Never mail it, show it, or treat it as an |
| - address: `teamstate.Addressless`, `Person.shownAddress`. They get no |
| - reminders and publish no booking page until Paul rules on the reminders |
| - question in the spec. |
| + address: `teamstate.Addressless`, `Person.shownAddress`. They publish |
| + no booking page, and their reminders are in-app only (row T2). |
| +- **In-app reminders mark, never send** (`store_reminder_notice.go`, |
| + spec §7 "In-app reminders"): a rule's channel is `email`, `inapp` or |
| + `both`; the drain decides on the recipient's standing exactly as for |
| + email, then writes a reference-only `reminder_notices` row under the |
| + claim. No title, no address in it. `/reminders` is a view (partial under |
| + Unknown); dismissing is a guarded member write. A person who never chose |
| + in-app sees every page byte-identical except Settings. |
| --- |
diff --git a/docs/superpowers/specs/2026-09-02-calendar-design.md b/docs/superpowers/specs/2026-09-02-calendar-design.md| index 436c7f5..5e524cd 100644 |
| --- a/docs/superpowers/specs/2026-09-02-calendar-design.md |
| +++ b/docs/superpowers/specs/2026-09-02-calendar-design.md |
| @@ -448,7 +448,9 @@ So a Home-only member gets: |
| 1. **No email reminders.** No default reminder is made for their events, |
| adding one is refused (the event page says why), and the drain never |
| - mails one. Their colleagues' reminders are unaffected. |
| + mails one. Their colleagues' reminders are unaffected. *(Superseded |
| + 2026-11-01: Paul ruled for option (a). They get in-app reminders, and |
| + still no email; see "In-app reminders" below.)* |
| 2. **No published booking page.** A page may be drafted, not published: |
| the booker's invitation names the host by address (`ORGANIZER`), and the |
| host's booking mail has nowhere to go. |
| @@ -506,3 +508,127 @@ local sign-in). Keep `CALENDAR_DEK` and the `CALENDAR_HOME_*` and |
| probe is Calendar's `/api/team`; the fake console, `TestRosterRecipes` and |
| the homecompat runs need Calendar moved from "pending" to activated, as |
| `d59778f` did for Slides. |
| + |
| +### In-app reminders — 2026-11-01 |
| + |
| +🤖 Claude Opus 5.5, for Paul. **Paul's ruling, 2026-11-01:** Home-only |
| +team members have no stored email address, by design, so Calendar gets |
| +**in-app reminders now** (option (a) above, Fable's recommendation on |
| +oficina/calendar #35). A suite-wide notification centre on oficina.works |
| +comes later, as a separate reviewed Home design; nothing here is built in |
| +Home, but the shape below leaves Home a pull of "unread count + links" that |
| +stores no content there. Spec written before the code. |
| + |
| +**The channel.** `reminders.channel` has always been a column ("a value |
| +rather than a schema change"). It now takes three values: `email` (every |
| +row before this change), `inapp`, and `both`. A rule's channel is fixed |
| +when it is made; changing a preference does not rewrite existing rules, |
| +and the event page names each rule's channel. |
| + |
| +- **Home-only members** (team mode, `teamstate.Addressless`): every rule |
| + they make is `inapp`, their default reminder included (they now get one, |
| + from the same defaults as anybody), and `email` or `both` is refused |
| + (`ErrNoAddress`) and never offered. |
| +- **People with an address** choose on Settings ("How to remind me": |
| + Email, In Calendar, or Email and in Calendar), stored in a new nullable |
| + `people.reminder_channel`; NULL or `email` is today's behaviour. Once |
| + the choice is not Email the event page's Add form offers the channel per |
| + rule, defaulting to the choice. No address is stored by any of this. |
| +- **Byte-identical until somebody opts in.** For a person whose choice is |
| + Email and who has no in-app rule, every page renders as before except |
| + Settings, which is where the choice lives and so is the one page that |
| + must change. Calendar.oficina.works, team mode off, keeps its email |
| + reminders exactly as they were: the drain's email path is untouched for |
| + an `email` rule, and a diff of responses against `main` shows only the |
| + Settings field (recorded on the review discussion). |
| + |
| +**The drain — mark, don't send.** The same queue, the same claim, the |
| +same three entrances (§5). `ClaimDueReminder` now carries the rule's |
| +channel. `reminderDelivery` decides on the recipient's standing at fire |
| +time exactly as before (NotMember: settled unsent and the rule goes |
| +dormant, N2; Unknown: deferred by `standingRetry`, unsent and |
| +unattempted; out of reach: that occurrence settled unsent and the next |
| +queued) with one change: "no address" settles only a rule that has an |
| +email half. When the answer is deliver: |
| + |
| +1. the **in-app half** writes the person's notice for this occurrence, in |
| + a transaction conditional on the claim (a reschedule that overtook the |
| + claim marks nothing, as `CompleteReminder` advances nothing); |
| +2. the **email half**, if the rule has one and the person has an address, |
| + is sent exactly as before (busy defers, failure counts an attempt); |
| +3. a rule with no email half to send is completed at once, which queues |
| + its next occurrence. |
| + |
| +The page-view drain does the same, so a reminder that comes due while the |
| +app is closed is on the first page opened after it. |
| + |
| +**What is stored: `reminder_notices`.** One row per RULE (unique |
| +`reminder_id`), holding the newest fired occurrence for that rule: |
| +`reminder_id`, `person_id`, `event_id`, `occurrence_key`, `start_utc`, |
| +`fired_at`, `dismissed_at`. References and times only: no title, place, |
| +note or address, so the one rule holds unchanged (the title is opened |
| +from the sealed event when the list is drawn; times are plaintext as the |
| +queue's already are, §1.1). Not a flag on `reminder_queues`, as Fable's |
| +sketch had it: a queue row moves to the next occurrence at the moment it |
| +fires, and is deleted when a series ends or a one-off fires, so a mark |
| +there would be gone in the same transaction that made it. A sibling keyed |
| +by the same rule is exactly as bounded (a forever-daily standup is one |
| +notice row, never one per day). Firing the same occurrence again (at |
| +least once, §5) changes nothing, so a dismissed notice stays dismissed; a |
| +newer occurrence replaces the row and is unread again. Removing a rule |
| +removes its notice. A notice whose event is deleted, cancelled or out of |
| +reach is not shown or counted (the read joins the live event through the |
| +grant, as every read does). |
| + |
| +**Unread is undismissed.** Nothing is written on a GET, so there is no |
| +separate "seen" state: the list is where a reminder is read, Dismiss (one) |
| +and Dismiss all are POSTs. |
| + |
| +**The UI.** In the chrome, a **Reminders** link beside Today, Agenda and |
| +Calendars, reading "Reminders (2)" while two are unread: text, never |
| +colour alone, and the same in the narrow Menu sheet. It is drawn for a |
| +person who uses in-app reminders (a Home-only member, or a choice other |
| +than Email) or has an unread one; otherwise the bar is unchanged. |
| +`/reminders` lists the unread ones, newest occurrence first: the title, |
| +the occurrence's day and time in the person's zone (past tense once it |
| +has started), a link to the occurrence, and a Dismiss button; Dismiss all |
| +at the foot. Scriptless: plain links and forms, the suite's busy rule |
| +(estilo's `busy.js`) on every button by default, no webfont (the chrome's |
| +system face, so no FOUT). |
| + |
| +**Team mode.** Every read and write follows the team-mode rules. |
| +`/reminders` is a view (`needListing`): under Unknown it is the partial |
| +list with its notice, always empty, and its empty state is withheld so it |
| +never reads as "nothing due". The chrome's count reads through `grantJoin` |
| +on the request's standing, so under Unknown the link carries no number |
| +rather than a zero. Dismiss and Dismiss all are member routes (Unknown a |
| +retryable no-store 503, NotMember a 404) whose writes are guarded inside |
| +their transaction, and both are in |
| +`TestTeamEveryWriteRouteRefusesALapseBeforeCommit`. The native |
| +`GET /api/native/reminders` is a member route and, being JSON with no room |
| +for a notice, a 503 if standing lapses while it is built. |
| + |
| +**Feed alarms.** `?alarms=1` already carries a person's largest reminder |
| +offset per event as a `VALARM` with `ACTION:DISPLAY`, read from every rule |
| +whatever its channel; in-app rules therefore appear there too. This is the |
| +bridge for a Home-only member's own calendar app: today they can make the |
| +rules it reads. |
| + |
| +**The seam for Home's notification centre.** `App.reminderNotices(ctx, |
| +person, subject, now)` (`reminder_seam.go`) has the shape and standing |
| +contract of `dashboardEvents`, the `Read` that home/dashboard's provider |
| +calls: it puts the verified subject's roster standing on the context, |
| +reads, answers `dashboard.ErrUnavailable` under Unknown (never a short |
| +count) and nothing for NotMember, and returns **the unread count plus, per |
| +notice, an opaque ID, an absolute link on this origin and the occurrence's |
| +start** — no title, so Home holds no content even transiently beyond a |
| +link. It is not mounted: home/dashboard's provider takes only the kinds |
| +`documents` and `events` today, and the notification centre is Home's |
| +design to make. When it exists, a provider for its new kind passes this |
| +function as `Read` (behind the same bearer, replay and `Resolve` checks) |
| +and nothing in Calendar's storage changes. |
| + |
| +**Not built.** Push to the native apps or the browser; email for a |
| +Home-only member (option (b), its own privacy review); a "seen" state |
| +apart from dismissed; expiry of old undismissed notices (they are bounded |
| +by rules); a channel change rewriting existing rules. |
diff --git a/internal/calendar/funcs.go b/internal/calendar/funcs.go| index 1fb41fd..d96cc10 100644 |
| --- a/internal/calendar/funcs.go |
| +++ b/internal/calendar/funcs.go |
| @@ -20,12 +20,26 @@ var appFuncs = template.FuncMap{ |
| "zoneOptions": zoneOptions, |
| "weekStartOptions": weekStartOptions, |
| "minutesLabel": minutesLabel, |
| + "channelLabel": channelLabel, |
| "duration": humanDuration, |
| "feedURL": feedURL, |
| "deleteAllLabel": deleteAllLabel, |
| "canWrite": CanWrite, |
| } |
| +// channelLabel names how a reminder rule reaches its person, at the head |
| +// of its line on the event page: "Email 10 minutes before", as every rule |
| +// read before there was a choice, or "In Calendar 10 minutes before". |
| +func channelLabel(channel string) string { |
| + switch channel { |
| + case ChannelInApp: |
| + return "In Calendar" |
| + case ChannelBoth: |
| + return "Email and in Calendar" |
| + } |
| + return "Email" |
| +} |
| + |
| // deleteAllLabel names the expensive option with its own count, so the |
| // warning is in the label rather than in a sentence beside it. |
| // |
diff --git a/internal/calendar/handlers_events.go b/internal/calendar/handlers_events.go| index 530b271..31995fa 100644 |
| --- a/internal/calendar/handlers_events.go |
| +++ b/internal/calendar/handlers_events.go |
| @@ -153,6 +153,11 @@ func (h *handlers) showEvent(w http.ResponseWriter, r *http.Request) { |
| "RuleText": DescribeRule(e.RRule), |
| "When": spanWords(e.StartUTC, e.EndUTC, p.Zone), |
| "NoAddress": h.noAddress(p), |
| + // The channel choice on the Add form, offered only to a person |
| + // with an address who chose something other than email, so the |
| + // page is unchanged for everybody else. |
| + "Channel": h.store.channelFor(p), |
| + "ChannelChoice": !h.noAddress(p) && h.store.channelFor(p) != ChannelEmail, |
| } |
| render(w, "event", h.page(r, e.Title, data)) |
| } |
diff --git a/internal/calendar/handlers_jobs.go b/internal/calendar/handlers_jobs.go| index 79a7ac0..bf8674b 100644 |
| --- a/internal/calendar/handlers_jobs.go |
| +++ b/internal/calendar/handlers_jobs.go |
| @@ -115,11 +115,15 @@ func (h *handlers) drainReminderQueue(ctx context.Context, now, deadline time.Ti |
| // wrong again and this loop would spend its whole deadline |
| // re-sending one reminder. Stop, and name it — a bounded bug |
| // that says what it is beats an unbounded one that does not. |
| - if seen[due.Queue.OccurrenceKey] { |
| + // Keyed by RULE and occurrence: several rules share an event's |
| + // occurrence (two people's reminders on one team meeting), and |
| + // each of those is owed once in the same pass. |
| + once := fmt.Sprintf("%d %s", due.Queue.ReminderID, due.Queue.OccurrenceKey) |
| + if seen[once] { |
| h.logger.Error("calendar: the same occurrence was claimed twice in one drain; stopping the pass") |
| return sent, errors.New("calendar: the same occurrence was claimed twice in one drain; stopping the pass") |
| } |
| - seen[due.Queue.OccurrenceKey] = true |
| + seen[once] = true |
| // Team mode: only to somebody the roster says is on the team, |
| // and who still reaches the event (team_jobs.go). |
| @@ -128,6 +132,14 @@ func (h *handlers) drainReminderQueue(ctx context.Context, now, deadline time.Ti |
| } else if settled { |
| continue |
| } |
| + // In-app: a notice in this database, marked rather than sent; a |
| + // rule with an email half goes on to be mailed as always. |
| + if done, err := h.deliverInApp(ctx, due, now); err != nil { |
| + return sent, err |
| + } else if done { |
| + sent++ |
| + continue |
| + } |
| if err := h.sendReminder(ctx, due, now); err != nil { |
| if errors.Is(err, ErrMailBusy) { |
| // Nothing was tried: the sender is full. Back in the |
| @@ -242,6 +254,14 @@ func (h *handlers) DrainOnRequest(ctx context.Context) { |
| if settled, err := h.settleWithoutSending(ctx, due, now); err != nil || settled { |
| return |
| } |
| + // In-app: this is how a reminder that came due while the app was |
| + // closed is on the first page opened after it. |
| + if done, err := h.deliverInApp(ctx, due, now); err != nil || done { |
| + if err != nil { |
| + h.logger.Error("calendar: opportunistic in-app reminder", "stage", "reminders.mark", "err", scrubErr(err)) |
| + } |
| + return |
| + } |
| if err := h.sendReminder(sctx, due, now); err != nil { |
| if errors.Is(err, ErrMailBusy) { |
| _, _ = h.store.DeferReminder(keep(ctx), due.Queue.ID, due.ClaimID, now.Unix()) |
diff --git a/internal/calendar/handlers_misc.go b/internal/calendar/handlers_misc.go| index 656a04a..a78c93a 100644 |
| --- a/internal/calendar/handlers_misc.go |
| +++ b/internal/calendar/handlers_misc.go |
| @@ -1,7 +1,6 @@ |
| package calendar |
| import ( |
| - "errors" |
| "fmt" |
| "net/http" |
| "strconv" |
| @@ -253,30 +252,6 @@ func (h *handlers) importFailed(w http.ResponseWriter, r *http.Request, msg stri |
| })) |
| } |
| -func (h *handlers) addReminder(w http.ResponseWriter, r *http.Request) { |
| - p, _ := CurrentPerson(r) |
| - id, _ := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64) |
| - _ = r.ParseForm() |
| - offset, _ := strconv.ParseInt(r.FormValue("offset_min"), 10, 64) |
| - if err := h.store.AddReminder(r.Context(), p.ID, id, offset); err != nil && !NotFound(err) && !errors.Is(err, ErrNoAddress) { |
| - h.fail(w, r, "add reminder", err) |
| - return |
| - } |
| - http.Redirect(w, r, "/events/"+strconv.FormatInt(id, 10), http.StatusSeeOther) |
| -} |
| - |
| -func (h *handlers) removeReminder(w http.ResponseWriter, r *http.Request) { |
| - p, _ := CurrentPerson(r) |
| - id, _ := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64) |
| - _ = r.ParseForm() |
| - remID, _ := strconv.ParseInt(r.FormValue("reminder_id"), 10, 64) |
| - if err := h.store.RemoveReminder(r.Context(), p.ID, remID); err != nil && !NotFound(err) { |
| - h.fail(w, r, "remove reminder", err) |
| - return |
| - } |
| - http.Redirect(w, r, "/events/"+strconv.FormatInt(id, 10), http.StatusSeeOther) |
| -} |
| - |
| // calendarParam resolves {id}, answering 404 for anything the viewer |
| // may not see. |
| func (h *handlers) calendarParam(w http.ResponseWriter, r *http.Request) (Person, CalendarView, bool) { |
diff --git a/internal/calendar/handlers_reminders.go b/internal/calendar/handlers_reminders.go| new file mode 100644 |
| index 0000000..2dd1084 |
| --- /dev/null |
| +++ b/internal/calendar/handlers_reminders.go |
| @@ -0,0 +1,186 @@ |
| +package calendar |
| + |
| +// The in-app reminders list (spec §7 "In-app reminders"): GET /reminders, |
| +// a view, and the two dismissals, which are member writes. Unread means |
| +// undismissed: nothing is written on a GET. |
| + |
| +import ( |
| + "errors" |
| + "fmt" |
| + "net/http" |
| + "strconv" |
| + "time" |
| + |
| + "amadan.net/oficina/estilo.git/chrome" |
| + "github.com/go-chi/chi/v5" |
| +) |
| + |
| +// noticeListMax bounds one list. Notices are one per rule, so this is |
| +// only reached by somebody with a hundred unread rules. |
| +const noticeListMax = 100 |
| + |
| +// noticeRow is one notice as the list draws it. |
| +type noticeRow struct { |
| + ID int64 |
| + Title string |
| + Href string |
| + // When is the occurrence in the person's zone, in the past tense once |
| + // it has started: "Starts Monday 2 November at 09:00", "Started …". |
| + When string |
| +} |
| + |
| +// noticeWhen writes when a notice's occurrence is, in zone. An all-day |
| +// occurrence is a DATE, read from its own local key, never a UTC instant. |
| +func noticeWhen(n NoticeView, zone string, now int64) string { |
| + verb := "Starts" |
| + if n.StartUTC <= now { |
| + verb = "Started" |
| + } |
| + if n.AllDay { |
| + if d, err := time.Parse(LayoutDate, n.Local); err == nil { |
| + return verb + " " + d.Format("Monday 2 January") |
| + } |
| + } |
| + t, err := InZone(n.StartUTC, zone) |
| + if err != nil { |
| + return "" |
| + } |
| + return fmt.Sprintf("%s %s at %s", verb, t.Format("Monday 2 January"), hhmm(n.StartUTC, zone)) |
| +} |
| + |
| +// reminders is GET /reminders. |
| +func (h *handlers) reminders(w http.ResponseWriter, r *http.Request) { |
| + p, _ := CurrentPerson(r) |
| + list, err := h.store.UnreadNotices(r.Context(), p.ID, noticeListMax) |
| + if err != nil { |
| + h.fail(w, r, "list reminder notices", err) |
| + return |
| + } |
| + now := time.Now().Unix() |
| + rows := make([]noticeRow, 0, len(list)) |
| + for _, n := range list { |
| + rows = append(rows, noticeRow{ID: n.ID, Title: n.Title, Href: n.Href, When: noticeWhen(n, personZone(p), now)}) |
| + } |
| + render(w, "reminders", h.page(r, "Reminders", map[string]any{ |
| + "Notices": rows, |
| + "InApp": h.store.usesInApp(p), |
| + })) |
| +} |
| + |
| +// dismissReminder is POST /reminders/{id}/dismiss. |
| +func (h *handlers) dismissReminder(w http.ResponseWriter, r *http.Request) { |
| + p, _ := CurrentPerson(r) |
| + id, err := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64) |
| + if err != nil { |
| + h.errorPage(w, r, http.StatusNotFound, "") |
| + return |
| + } |
| + if err := h.store.DismissNotice(r.Context(), p.ID, id, time.Now().Unix()); err != nil { |
| + h.fail(w, r, "dismiss reminder", err) |
| + return |
| + } |
| + http.Redirect(w, r, "/reminders", http.StatusSeeOther) |
| +} |
| + |
| +// dismissAllReminders is POST /reminders/dismiss. |
| +func (h *handlers) dismissAllReminders(w http.ResponseWriter, r *http.Request) { |
| + p, _ := CurrentPerson(r) |
| + if err := h.store.DismissAllNotices(r.Context(), p.ID, time.Now().Unix()); err != nil { |
| + h.fail(w, r, "dismiss reminders", err) |
| + return |
| + } |
| + http.Redirect(w, r, "/reminders", http.StatusSeeOther) |
| +} |
| + |
| +// nativeReminders is GET /api/native/reminders: the unread count and the |
| +// list, for the native apps. JSON has no room for a partial notice, so |
| +// standing that lapsed while it was built is a 503, never a short list |
| +// (as nativeEvents). |
| +func (h *handlers) nativeReminders(w http.ResponseWriter, r *http.Request) { |
| + p, _ := CurrentPerson(r) |
| + n, err := h.store.UnreadNoticeCount(r.Context(), p.ID) |
| + if err != nil { |
| + http.Error(w, "Cannot load reminders", http.StatusInternalServerError) |
| + return |
| + } |
| + list, err := h.store.UnreadNotices(r.Context(), p.ID, noticeListMax) |
| + if err != nil { |
| + http.Error(w, "Cannot load reminders", http.StatusInternalServerError) |
| + return |
| + } |
| + if requestUnknown(r) { |
| + h.teamUnavailable(w, r) |
| + return |
| + } |
| + type item struct { |
| + ID int64 `json:"id"` |
| + EventID int64 `json:"event_id"` |
| + Title string `json:"title"` |
| + Start int64 `json:"start"` |
| + AllDay bool `json:"all_day"` |
| + Path string `json:"path"` |
| + } |
| + out := make([]item, 0, len(list)) |
| + for _, v := range list { |
| + out = append(out, item{v.ID, v.EventID, v.Title, v.StartUTC, v.AllDay, v.Href}) |
| + } |
| + nativeJSON(w, map[string]any{"unread": n, "reminders": out}) |
| +} |
| + |
| +// addReminderLink puts the Reminders link in a signed-in person's bar, |
| +// beside the sections (never on a door, which has no account menu). |
| +func (h *handlers) addReminderLink(r *http.Request, bar *chrome.Bar) { |
| + p, ok := CurrentPerson(r) |
| + if !ok || p.ID == 0 || bar.Account == nil || bar.Nav == nil { |
| + return |
| + } |
| + if link, ok := h.reminderLink(r, p); ok { |
| + bar.Nav = append(bar.Nav, link) |
| + } |
| +} |
| + |
| +// reminderLink is the chrome's Reminders link: drawn for a person who |
| +// uses in-app reminders or has one unread, and otherwise absent, so a |
| +// person who never chose in-app sees the bar they always did. The count |
| +// reads on this request's standing, so under Unknown it is absent rather |
| +// than a zero. |
| +func (h *handlers) reminderLink(r *http.Request, p Person) (chrome.Link, bool) { |
| + n, err := h.store.UnreadNoticeCount(r.Context(), p.ID) |
| + if err != nil { |
| + n = 0 |
| + } |
| + if n == 0 && !h.store.usesInApp(p) { |
| + return chrome.Link{}, false |
| + } |
| + label := "Reminders" |
| + if n > 0 { |
| + label = fmt.Sprintf("Reminders (%d)", n) |
| + } |
| + return chrome.Link{Href: "/reminders", Label: label, Current: r.URL.Path == "/reminders"}, true |
| +} |
| + |
| +func (h *handlers) addReminder(w http.ResponseWriter, r *http.Request) { |
| + p, _ := CurrentPerson(r) |
| + id, _ := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64) |
| + _ = r.ParseForm() |
| + offset, _ := strconv.ParseInt(r.FormValue("offset_min"), 10, 64) |
| + // channel is absent unless the form offered a choice: the person's |
| + // own channel, as before there was one (spec §7 "In-app reminders"). |
| + if err := h.store.AddReminderOn(r.Context(), p.ID, id, offset, r.FormValue("channel")); err != nil && !NotFound(err) && !errors.Is(err, ErrNoAddress) { |
| + h.fail(w, r, "add reminder", err) |
| + return |
| + } |
| + http.Redirect(w, r, "/events/"+strconv.FormatInt(id, 10), http.StatusSeeOther) |
| +} |
| + |
| +func (h *handlers) removeReminder(w http.ResponseWriter, r *http.Request) { |
| + p, _ := CurrentPerson(r) |
| + id, _ := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64) |
| + _ = r.ParseForm() |
| + remID, _ := strconv.ParseInt(r.FormValue("reminder_id"), 10, 64) |
| + if err := h.store.RemoveReminder(r.Context(), p.ID, remID); err != nil && !NotFound(err) { |
| + h.fail(w, r, "remove reminder", err) |
| + return |
| + } |
| + http.Redirect(w, r, "/events/"+strconv.FormatInt(id, 10), http.StatusSeeOther) |
| +} |
diff --git a/internal/calendar/handlers_settings.go b/internal/calendar/handlers_settings.go| index 2be3297..b532365 100644 |
| --- a/internal/calendar/handlers_settings.go |
| +++ b/internal/calendar/handlers_settings.go |
| @@ -23,6 +23,7 @@ func (h *handlers) settings(w http.ResponseWriter, r *http.Request) { |
| "Error": "", |
| "ErrorField": "", |
| "NoAddress": h.noAddress(p), |
| + "Channel": h.store.channelFor(p), |
| })) |
| } |
| @@ -33,7 +34,7 @@ func (h *handlers) saveSettings(w http.ResponseWriter, r *http.Request) { |
| reminderMin, _ := strconv.Atoi(r.FormValue("default_reminder_min")) |
| allDayMin, _ := strconv.Atoi(r.FormValue("default_all_day_min")) |
| - err := h.store.SaveSettings(r.Context(), p.ID, r.FormValue("zone"), weekStart, reminderMin, allDayMin) |
| + err := h.store.SaveSettings(r.Context(), p.ID, r.FormValue("zone"), weekStart, reminderMin, allDayMin, r.FormValue("reminder_channel")) |
| if err == nil { |
| // The handle is the first part of every booking link. Saved |
| // after the rest so a refused handle does not lose the zone. |
| @@ -49,7 +50,7 @@ func (h *handlers) saveSettings(w http.ResponseWriter, r *http.Request) { |
| render(w, "settings", h.page(r, "Settings", map[string]any{ |
| "Person": p, "Zones": CommonZones, |
| "Undeliverable": undeliverable, "Error": ve.Message, "ErrorField": ve.Field, |
| - "NoAddress": h.noAddress(p), |
| + "NoAddress": h.noAddress(p), "Channel": h.store.channelFor(p), |
| })) |
| return |
| } |
diff --git a/internal/calendar/inapp_reminders_test.go b/internal/calendar/inapp_reminders_test.go| new file mode 100644 |
| index 0000000..9dafced |
| --- /dev/null |
| +++ b/internal/calendar/inapp_reminders_test.go |
| @@ -0,0 +1,144 @@ |
| +package calendar |
| + |
| +import ( |
| + "context" |
| + "net/http" |
| + "net/http/httptest" |
| + "net/url" |
| + "strings" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// In-app reminders with team mode off (spec §7 "In-app reminders"): email |
| +// stays exactly what it was for anybody who never chose otherwise, and a |
| +// person with an address may choose in-app, or both. |
| + |
| +type plainWorld struct { |
| + t *testing.T |
| + app *App |
| + session *http.Cookie |
| + box *teamMailbox |
| + person Person |
| + calendar int64 // their default (personal) calendar |
| +} |
| + |
| +func newPlainWorld(t *testing.T) *plainWorld { |
| + t.Helper() |
| + app := NewForTest(t, t.TempDir()) |
| + w := &plainWorld{t: t, app: app, session: app.SignInForTest(t, "paul@example.test")} |
| + w.box = &teamMailbox{} |
| + app.h.mailer = newBoundedSender(w.box) |
| + w.do("GET", "/calendars", nil) // the first page makes their calendars |
| + w.person = app.PersonByAddressForTest(t, "paul@example.test") |
| + id, err := app.store.DefaultCalendarID(context.Background(), w.person.ID) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + w.calendar = id |
| + return w |
| +} |
| + |
| +func (w *plainWorld) do(method, path string, form url.Values) *httptest.ResponseRecorder { |
| + rec := httptest.NewRecorder() |
| + w.app.mux.ServeHTTP(rec, RequestForTest(w.session, method, path, form)) |
| + return rec |
| +} |
| + |
| +// event creates an event through the form a few minutes from now, so the |
| +// person's default reminder is made and due, and returns it. |
| +func (w *plainWorld) event(title string) Event { |
| + w.t.Helper() |
| + start, end := soon(5) |
| + if rec := w.do("POST", "/events", url.Values{"calendar_id": {itoa(w.calendar)}, "title": {title}, "start": {start}, "end": {end}, "tz": {"UTC"}, "kind": {"meeting"}, "status": {"confirmed"}, "repeat": {"none"}}); rec.Code != http.StatusSeeOther { |
| + w.t.Fatalf("create %q = %d %s", title, rec.Code, rec.Body.String()) |
| + } |
| + var e Event |
| + w.app.db.G.Last(&e) |
| + return e |
| +} |
| + |
| +func (w *plainWorld) notices() int64 { |
| + var n int64 |
| + w.app.db.G.Model(&ReminderNotice{}).Count(&n) |
| + return n |
| +} |
| + |
| +func TestEmailRemindersAreUnchangedUntilSomebodyOptsIn(t *testing.T) { |
| + w := newPlainWorld(t) |
| + e := w.event("Standup by email") |
| + var rule Reminder |
| + w.app.db.G.Where("event_id = ?", e.ID).First(&rule) |
| + if rule.Channel != ChannelEmail { |
| + t.Fatalf("the default reminder's channel = %q, want email", rule.Channel) |
| + } |
| + if sent, _, err := w.app.h.drain(context.Background(), time.Now()); err != nil || sent != 1 { |
| + t.Fatalf("drain = %d %v", sent, err) |
| + } |
| + page := w.do("GET", "/events/"+itoa(e.ID), nil).Body.String() |
| + if strings.Contains(page, `href="/reminders"`) || strings.Contains(page, `name="channel"`) || !strings.Contains(page, "Email 10 minutes before") { |
| + t.Fatal("a person who never chose in-app sees in-app reminders on the event page") |
| + } |
| + if len(w.box.to("paul@example.test")) != 1 || w.notices() != 0 { |
| + t.Fatalf("an email reminder = %v mailed, %d notices", w.box.sent, w.notices()) |
| + } |
| + if rec := w.do("GET", "/reminders", nil); rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), "Open Settings") { |
| + t.Fatalf("the list for somebody on email = %d", rec.Code) |
| + } |
| +} |
| + |
| +func TestAPersonWithAnAddressChoosesInAppOrBoth(t *testing.T) { |
| + w := newPlainWorld(t) |
| + settings := url.Values{"zone": {"UTC"}, "week_start": {"1"}, "default_reminder_min": {"10"}, "default_all_day_min": {"0"}, "handle": {""}} |
| + settings.Set("reminder_channel", "both") |
| + if rec := w.do("POST", "/settings", settings); rec.Code != http.StatusSeeOther { |
| + t.Fatalf("settings = %d %s", rec.Code, rec.Body.String()) |
| + } |
| + e := w.event("Both ways") |
| + var rule Reminder |
| + w.app.db.G.Where("event_id = ?", e.ID).First(&rule) |
| + if rule.Channel != ChannelBoth { |
| + t.Fatalf("the default reminder's channel = %q, want both", rule.Channel) |
| + } |
| + // Both: mailed AND marked, in one pass. |
| + if sent, _, err := w.app.h.drain(context.Background(), time.Now()); err != nil || sent != 1 { |
| + t.Fatalf("drain = %d %v", sent, err) |
| + } |
| + page := w.do("GET", "/events/"+itoa(e.ID), nil).Body.String() |
| + if !strings.Contains(page, `name="channel"`) || !strings.Contains(page, "Email and in Calendar 10 minutes before") || !strings.Contains(page, "Reminders (1)") { |
| + t.Fatal("the event page does not offer the channel, name it, or count it in the chrome") |
| + } |
| + if len(w.box.to("paul@example.test")) != 1 || w.notices() != 1 { |
| + t.Fatalf("both = %v mailed, %d notices", w.box.sent, w.notices()) |
| + } |
| + // One rule on its own channel, chosen on the event page. |
| + if rec := w.do("POST", "/events/"+itoa(e.ID)+"/reminders", url.Values{"offset_min": {"5"}, "channel": {"inapp"}}); rec.Code != http.StatusSeeOther { |
| + t.Fatalf("add = %d", rec.Code) |
| + } |
| + var channels []string |
| + w.app.db.G.Model(&Reminder{}).Where("event_id = ?", e.ID).Order("id").Pluck("channel", &channels) |
| + if len(channels) != 2 || channels[1] != ChannelInApp { |
| + t.Fatalf("channels = %v", channels) |
| + } |
| + // Settings without the field (an older form) keeps the choice. |
| + settings.Del("reminder_channel") |
| + w.do("POST", "/settings", settings) |
| + if w.app.db.G.First(&w.person, w.person.ID); w.person.ReminderChannel == nil || *w.person.ReminderChannel != ChannelBoth { |
| + t.Fatal("a settings save without the field changed the channel") |
| + } |
| +} |
| + |
| +// Several rules on ONE occurrence — two people's reminders on a shared |
| +// meeting, or one person's two — are each owed in the same pass. The |
| +// drain's claimed-twice guard used to key on the occurrence alone, so the |
| +// second stopped the pass with an error. |
| +func TestTwoRulesOnOneOccurrenceAreBothDeliveredInOnePass(t *testing.T) { |
| + w := newPlainWorld(t) |
| + e := w.event("Twice warned") |
| + if err := w.app.store.AddReminder(context.Background(), w.person.ID, e.ID, 30); err != nil { |
| + t.Fatal(err) |
| + } |
| + if sent, _, err := w.app.h.drain(context.Background(), time.Now()); err != nil || sent != 2 { |
| + t.Fatalf("drain = %d %v, want both rules delivered", sent, err) |
| + } |
| +} |
diff --git a/internal/calendar/migrations/0007_create_reminder_notices.sql b/internal/calendar/migrations/0007_create_reminder_notices.sql| new file mode 100644 |
| index 0000000..a381746 |
| --- /dev/null |
| +++ b/internal/calendar/migrations/0007_create_reminder_notices.sql |
| @@ -0,0 +1,8 @@ |
| +ALTER TABLE `people` ADD `reminder_channel` text; |
| + |
| +CREATE TABLE `reminder_notices` (`id` integer PRIMARY KEY AUTOINCREMENT,`reminder_id` integer NOT NULL,`person_id` integer NOT NULL,`event_id` integer NOT NULL,`occurrence_key` text NOT NULL,`start_utc` integer NOT NULL,`fired_at` integer NOT NULL,`dismissed_at` integer); |
| + |
| +CREATE INDEX `idx_reminder_notices_person_id` ON `reminder_notices`(`person_id`); |
| + |
| +CREATE UNIQUE INDEX `idx_reminder_notices_reminder_id` ON `reminder_notices`(`reminder_id`); |
| + |
diff --git a/internal/calendar/migrations/schema.sql b/internal/calendar/migrations/schema.sql| index c28eb7e..675319e 100644 |
| --- a/internal/calendar/migrations/schema.sql |
| +++ b/internal/calendar/migrations/schema.sql |
| @@ -21,7 +21,9 @@ CREATE TABLE `grants` (`id` integer PRIMARY KEY AUTOINCREMENT,`calendar_id` inte |
| CREATE TABLE `meta` (`key` text,`value` text NOT NULL,PRIMARY KEY (`key`)); |
| -CREATE TABLE `people` (`id` integer PRIMARY KEY AUTOINCREMENT,`address` text NOT NULL,`zone` text NOT NULL,`created_at` datetime NOT NULL,`updated_at` datetime NOT NULL, `name_sealed` blob, `week_start` integer NOT NULL, `default_reminder_min` integer NOT NULL, `default_all_day_min` integer NOT NULL, `handle` text); |
| +CREATE TABLE `people` (`id` integer PRIMARY KEY AUTOINCREMENT,`address` text NOT NULL,`zone` text NOT NULL,`created_at` datetime NOT NULL,`updated_at` datetime NOT NULL, `name_sealed` blob, `week_start` integer NOT NULL, `default_reminder_min` integer NOT NULL, `default_all_day_min` integer NOT NULL, `handle` text, `reminder_channel` text); |
| + |
| +CREATE TABLE `reminder_notices` (`id` integer PRIMARY KEY AUTOINCREMENT,`reminder_id` integer NOT NULL,`person_id` integer NOT NULL,`event_id` integer NOT NULL,`occurrence_key` text NOT NULL,`start_utc` integer NOT NULL,`fired_at` integer NOT NULL,`dismissed_at` integer); |
| CREATE TABLE `reminder_queues` (`id` integer PRIMARY KEY AUTOINCREMENT,`reminder_id` integer NOT NULL,`occurrence_key` text NOT NULL,`due_at` integer NOT NULL,`claimed_at` integer,`fired_at` integer,`attempts` integer NOT NULL,`late_by_sec` integer NOT NULL, `claim_id` text, `retry_at` integer); |
| @@ -85,6 +87,10 @@ CREATE UNIQUE INDEX `idx_people_address` ON `people`(`address`); |
| CREATE UNIQUE INDEX `idx_people_handle` ON `people`(`handle`); |
| +CREATE INDEX `idx_reminder_notices_person_id` ON `reminder_notices`(`person_id`); |
| + |
| +CREATE UNIQUE INDEX `idx_reminder_notices_reminder_id` ON `reminder_notices`(`reminder_id`); |
| + |
| CREATE INDEX `idx_reminder_queues_due_at` ON `reminder_queues`(`due_at`); |
| CREATE INDEX `idx_reminder_queues_occurrence_key` ON `reminder_queues`(`occurrence_key`); |
diff --git a/internal/calendar/models.go b/internal/calendar/models.go| index de71b73..b672a00 100644 |
| --- a/internal/calendar/models.go |
| +++ b/internal/calendar/models.go |
| @@ -15,6 +15,7 @@ var Models = []any{ |
| &Attendee{}, |
| &Reminder{}, |
| &ReminderQueue{}, |
| + &ReminderNotice{}, |
| &Feed{}, |
| &Meta{}, |
| &BookingPage{}, |
| @@ -79,6 +80,12 @@ type Person struct { |
| DefaultReminderMin int `gorm:"column:default_reminder_min;not null"` |
| DefaultAllDayMin int `gorm:"column:default_all_day_min;not null"` |
| + // ReminderChannel is the channel this person's NEW reminder rules |
| + // take: nil or "email" (everybody before in-app reminders), "inapp", |
| + // or "both" (spec §7 "In-app reminders"). A Home-only member's is |
| + // always in-app whatever this says (reminderChannelFor). |
| + ReminderChannel *string `gorm:"column:reminder_channel"` |
| + |
| CreatedAt time.Time `gorm:"column:created_at;not null"` |
| UpdatedAt time.Time `gorm:"column:updated_at;not null"` |
diff --git a/internal/calendar/models_event.go b/internal/calendar/models_event.go| index b0b49df..5f4671e 100644 |
| --- a/internal/calendar/models_event.go |
| +++ b/internal/calendar/models_event.go |
| @@ -234,6 +234,33 @@ type ReminderQueue struct { |
| LateBySec int64 `gorm:"column:late_by_sec;not null"` |
| } |
| +// ReminderNotice is an in-app reminder that has fired: the newest fired |
| +// occurrence of one rule, for the person whose rule it is, unread until |
| +// they dismiss it (spec §7 "In-app reminders"). |
| +// |
| +// References and times only. No title, place, note or address: the title |
| +// is opened from the sealed event when the list is drawn, so the one rule |
| +// holds, and the times are the shape of time the queue already holds. |
| +// |
| +// One row per RULE, like the queue, and for the same reason: a |
| +// forever-daily standup is one notice row, never one per day. It is a |
| +// sibling of the queue row rather than a flag on it because the queue row |
| +// moves to the next occurrence in the same transaction that fires it. |
| +type ReminderNotice struct { |
| + ID int64 `gorm:"primaryKey"` |
| + ReminderID int64 `gorm:"column:reminder_id;not null;uniqueIndex"` |
| + PersonID int64 `gorm:"column:person_id;not null;index"` |
| + EventID int64 `gorm:"column:event_id;not null"` |
| + |
| + // OccurrenceKey is the queue's "{event_id}/{local}", and what makes a |
| + // second fire of the same occurrence a no-op (delivery is at least |
| + // once): a dismissed notice stays dismissed. |
| + OccurrenceKey string `gorm:"column:occurrence_key;not null"` |
| + StartUTC int64 `gorm:"column:start_utc;not null"` |
| + FiredAt int64 `gorm:"column:fired_at;not null"` |
| + DismissedAt *int64 `gorm:"column:dismissed_at"` |
| +} |
| + |
| // Feed is a subscription capability: a URL somebody pastes into Google |
| // or Apple Calendar. |
| // |
diff --git a/internal/calendar/reminder_seam.go b/internal/calendar/reminder_seam.go| new file mode 100644 |
| index 0000000..fec3fb1 |
| --- /dev/null |
| +++ b/internal/calendar/reminder_seam.go |
| @@ -0,0 +1,83 @@ |
| +package calendar |
| + |
| +// The seam for Home's notification centre (spec §7 "In-app reminders"). |
| +// |
| +// Paul, 2026-11-01: a suite-wide notification centre on oficina.works |
| +// comes later, as its own reviewed Home design, and Calendar builds |
| +// nothing in Home now. What Calendar owes that design is a read Home can |
| +// PULL that stores no content in Home: how many reminders are unread, and |
| +// a link to each. reminderNotices is that read, shaped like |
| +// dashboardEvents — the Read home/dashboard's provider calls today, with |
| +// (ctx, person, verified subject, now) in and an answer or an |
| +// unavailability out — so that when Home has a kind for it, a provider |
| +// mounts this behind the same bearer, replay and Resolve checks the |
| +// dashboard pull already has (dashboard.go), and nothing in Calendar's |
| +// storage changes. |
| +// |
| +// It is not mounted: home/dashboard's provider accepts only the kinds |
| +// "documents" and "events" today, and the wire for a notification kind is |
| +// Home's to design. |
| + |
| +import ( |
| + "context" |
| + "strconv" |
| + "time" |
| + |
| + "amadan.net/oficina/home/dashboard" |
| + "amadan.net/oficina/home/teammode" |
| +) |
| + |
| +// NoticeLink is one unread in-app reminder as Home would see it: an |
| +// opaque ID that changes when the rule fires for a newer occurrence, an |
| +// absolute link on this origin, and when the occurrence starts. No |
| +// title: Home holds a link, never the content behind it. |
| +type NoticeLink struct { |
| + ID string |
| + URL string |
| + Start time.Time |
| +} |
| + |
| +// NoticeSummary is the pull's answer: the unread count, and the links to |
| +// the newest of them. Unread may exceed len(Items); Truncated says so. |
| +type NoticeSummary struct { |
| + Unread int |
| + Items []NoticeLink |
| + Truncated bool |
| +} |
| + |
| +// reminderNotices reads person's unread in-app reminders for a verified |
| +// Home subject. In team mode it reads on the subject's roster standing, |
| +// never anything stored: Unknown is dashboard.ErrUnavailable (never a |
| +// short count, to a reader on another origin who cannot see a partial |
| +// notice), asked after reading too because a lease can lapse during it; |
| +// NotMember reaches nothing and so counts nothing. |
| +func (a *App) reminderNotices(ctx context.Context, id int64, subject string, _ time.Time) (NoticeSummary, error) { |
| + var standing *teammode.Access |
| + if a.team != nil { |
| + standing = a.team.Access(ctx, subject) |
| + ctx = teammode.WithAccess(ctx, standing) |
| + } |
| + if standing != nil && standing.Partial() { |
| + return NoticeSummary{}, dashboard.ErrUnavailable |
| + } |
| + n, err := a.store.UnreadNoticeCount(ctx, id) |
| + if err != nil { |
| + return NoticeSummary{}, err |
| + } |
| + list, err := a.store.UnreadNotices(ctx, id, dashboard.MaxItems) |
| + if err != nil { |
| + return NoticeSummary{}, err |
| + } |
| + if standing != nil && standing.Partial() { |
| + return NoticeSummary{}, dashboard.ErrUnavailable |
| + } |
| + out := NoticeSummary{Unread: int(n), Items: make([]NoticeLink, 0, len(list)), Truncated: int(n) > len(list)} |
| + for _, v := range list { |
| + out.Items = append(out.Items, NoticeLink{ |
| + ID: strconv.FormatInt(v.ID, 10) + ":" + strconv.FormatInt(v.StartUTC, 10), |
| + URL: a.cfg.Origin + v.Href, |
| + Start: time.Unix(v.StartUTC, 0).UTC(), |
| + }) |
| + } |
| + return out, nil |
| +} |
diff --git a/internal/calendar/render.go b/internal/calendar/render.go| index 1b30946..97df41d 100644 |
| --- a/internal/calendar/render.go |
| +++ b/internal/calendar/render.go |
| @@ -38,7 +38,7 @@ var assets = rastrillo.NewAssets(appFS) |
| var pageNames = []string{ |
| "home", "signin", "errors", "credits", "day", "week", "month", "agenda", |
| "event", "event_form", "event_delete", "calendars", "share", |
| - "import", "import_done", "settings", |
| + "import", "import_done", "settings", "reminders", |
| "booking_pages", "booking_page_form", |
| "book_page", "book_sent", "book_hold", "book_manage", "book_gone", |
| } |
| @@ -170,6 +170,7 @@ func (h *handlers) page(r *http.Request, title string, data any) PageData { |
| if _, door := data.(signinData); door || r.URL.Path == "/signin" || r.URL.Path == "/signin/local" || r.URL.Path == "/signed-out" { |
| pd.Chrome.Account, pd.Chrome.SignIn = nil, nil |
| } |
| + h.addReminderLink(r, &pd.Chrome) // in-app reminders (handlers_reminders.go) |
| return pd |
| } |
| @@ -288,12 +289,3 @@ func (h *handlers) notFound(w http.ResponseWriter, r *http.Request) { |
| title, page := errorData(r, http.StatusNotFound, "") |
| render(w, "errors", h.page(r, title, page)) |
| } |
| - |
| -func containsHTML(accept string) bool { |
| - for i := 0; i+9 <= len(accept); i++ { |
| - if accept[i:i+9] == "text/html" { |
| - return true |
| - } |
| - } |
| - return false |
| -} |
diff --git a/internal/calendar/routes.go b/internal/calendar/routes.go| index fbdae4f..3f46b58 100644 |
| --- a/internal/calendar/routes.go |
| +++ b/internal/calendar/routes.go |
| @@ -133,6 +133,8 @@ func (a *App) routes(h *handlers, authPlugin *rauth.Auth, list allowlist, origin |
| r.With(a.standing(needListing)).Get("/month/{month}", h.month) |
| r.With(a.standing(needListing)).Get("/agenda", h.agenda) |
| r.With(a.standing(needListing)).Get("/calendars", h.calendars) |
| + // In-app reminders: a list, so a view (partial under Unknown). |
| + r.With(a.standing(needListing)).Get("/reminders", h.reminders) |
| r.Group(func(r chi.Router) { |
| r.Use(a.standing(needMember)) |
| @@ -188,6 +190,7 @@ func (a *App) memberRoutes(r chi.Router, h *handlers) { |
| r.Post("/api/native/quick", h.nativeQuickSave) |
| r.Get("/api/native/session", h.nativeSession) |
| r.Get("/api/native/events", h.nativeEvents) |
| + r.Get("/api/native/reminders", h.nativeReminders) |
| r.Post("/api/native/events", h.nativeSave) |
| r.Post("/api/native/events/{id}", h.nativeSave) |
| @@ -208,6 +211,9 @@ func (a *App) memberRoutes(r chi.Router, h *handlers) { |
| r.Post("/events/{id}/delete", h.deleteEvent) |
| r.Post("/events/{id}/reminders", h.addReminder) |
| r.Post("/events/{id}/reminders/remove", h.removeReminder) |
| + // In-app reminders: dismissing one, or all (handlers_reminders.go). |
| + r.Post("/reminders/dismiss", h.dismissAllReminders) |
| + r.Post("/reminders/{id}/dismiss", h.dismissReminder) |
| // One occurrence of a series. Last, so it cannot shadow the |
| // literal segments above. |
| r.Get("/events/{id}/{occ}", h.showEvent) |
diff --git a/internal/calendar/serving.go b/internal/calendar/serving.go| index f80a6b3..2995836 100644 |
| --- a/internal/calendar/serving.go |
| +++ b/internal/calendar/serving.go |
| @@ -46,3 +46,13 @@ func (a *App) ServeOptions(opts rastrillo.Options) rastrillo.Options { |
| opts.CSP = ContentSecurityPolicy |
| return opts |
| } |
| + |
| +// containsHTML reports whether an Accept header asks for HTML (notFound). |
| +func containsHTML(accept string) bool { |
| + for i := 0; i+9 <= len(accept); i++ { |
| + if accept[i:i+9] == "text/html" { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
diff --git a/internal/calendar/store_drain.go b/internal/calendar/store_drain.go| index e0e05d2..eefaa5b 100644 |
| --- a/internal/calendar/store_drain.go |
| +++ b/internal/calendar/store_drain.go |
| @@ -26,6 +26,9 @@ type DueReminder struct { |
| // PersonID is whose reminder it is: team mode asks the roster about |
| // them before anything is sent (team_jobs.go). |
| PersonID int64 |
| + // Channel is the rule's: email, inapp or both. The in-app half is |
| + // marked, never sent (store_reminder_notice.go). |
| + Channel string |
| Title string |
| Location string |
| Zone string |
| @@ -168,6 +171,7 @@ func (s *Store) ClaimDueReminder(ctx context.Context, now int64) (DueReminder, b |
| ClaimID: claimID, |
| EventID: e.ID, |
| PersonID: rem.PersonID, |
| + Channel: rem.Channel, |
| Title: title, |
| Location: loc, |
| Zone: zone, |
diff --git a/internal/calendar/store_feed.go b/internal/calendar/store_feed.go| index 5c3f5ee..7282bd2 100644 |
| --- a/internal/calendar/store_feed.go |
| +++ b/internal/calendar/store_feed.go |
| @@ -176,8 +176,11 @@ func (s *Store) reminderOffsets(ctx context.Context, personID int64) (map[int64] |
| return out, nil |
| } |
| -// SaveSettings updates a person's own display preferences. |
| -func (s *Store) SaveSettings(ctx context.Context, personID int64, zone string, weekStart, reminderMin, allDayMin int) error { |
| +// SaveSettings updates a person's own display preferences. channel is |
| +// the reminder channel their new rules take; "" or one that does not |
| +// exist leaves it as it was (a Home-only member's form has none: theirs |
| +// is in-app whatever is stored). |
| +func (s *Store) SaveSettings(ctx context.Context, personID int64, zone string, weekStart, reminderMin, allDayMin int, channel string) error { |
| if _, err := Zone(zone); err != nil { |
| return ValidationError{"zone", "That is not a time zone we know."} |
| } |
| @@ -186,15 +189,18 @@ func (s *Store) SaveSettings(ctx context.Context, personID int64, zone string, w |
| default: |
| weekStart = WeekStartMonday |
| } |
| + cols := map[string]any{ |
| + "zone": zone, |
| + "week_start": weekStart, |
| + "default_reminder_min": reminderMin, |
| + "default_all_day_min": allDayMin, |
| + "updated_at": time.Now().UTC(), |
| + } |
| + if validChannel(channel) { |
| + cols["reminder_channel"] = channel |
| + } |
| err := s.guarded(ctx, func(db *gorm.DB) error { |
| - return db.Model(&Person{}).Where("id = ?", personID). |
| - Updates(map[string]any{ |
| - "zone": zone, |
| - "week_start": weekStart, |
| - "default_reminder_min": reminderMin, |
| - "default_all_day_min": allDayMin, |
| - "updated_at": time.Now().UTC(), |
| - }).Error |
| + return db.Model(&Person{}).Where("id = ?", personID).Updates(cols).Error |
| }) |
| if err != nil { |
| return fmt.Errorf("calendar: save settings: %w", err) |
diff --git a/internal/calendar/store_reminder.go b/internal/calendar/store_reminder.go| index 06e15e9..9170588 100644 |
| --- a/internal/calendar/store_reminder.go |
| +++ b/internal/calendar/store_reminder.go |
| @@ -7,8 +7,6 @@ import ( |
| "time" |
| "gorm.io/gorm" |
| - |
| - "amadan.net/oficina/calendar/internal/calendar/teamstate" |
| ) |
| // EnsureDefaultReminder gives a newly created event the person's own |
| @@ -27,16 +25,14 @@ func (s *Store) EnsureDefaultReminder(ctx context.Context, p Person, e Event) er |
| if offset == 0 { |
| return nil |
| } |
| - if s.team && teamstate.Addressless(p.Address) { |
| - // Team mode: a Home-only person has no address to remind, so |
| - // gets no default reminder (team_home_only.go). |
| - return nil |
| - } |
| + // The person's own channel: email unless they chose otherwise, and |
| + // in-app for a Home-only member, who has no address to mail (spec §7 |
| + // "In-app reminders"). |
| r := Reminder{ |
| EventID: e.ID, |
| PersonID: p.ID, |
| OffsetMin: offset, |
| - Channel: "email", |
| + Channel: s.channelFor(p), |
| CreatedAt: time.Now().UTC(), |
| } |
| return s.guarded(ctx, func(db *gorm.DB) error { |
| @@ -62,20 +58,32 @@ func (s *Store) RemindersFor(ctx context.Context, personID, eventID int64) ([]Re |
| return out, nil |
| } |
| -// AddReminder attaches a warning to an event the person can see. |
| +// AddReminder attaches a warning to an event the person can see, on the |
| +// person's own channel. |
| func (s *Store) AddReminder(ctx context.Context, personID, eventID, offsetMin int64) error { |
| + return s.AddReminderOn(ctx, personID, eventID, offsetMin, "") |
| +} |
| + |
| +// AddReminderOn is AddReminder on a channel the person chose; "" (or a |
| +// channel that does not exist) is their own. An email half asked for by a |
| +// Home-only member is ErrNoAddress: they have no address to mail. |
| +func (s *Store) AddReminderOn(ctx context.Context, personID, eventID, offsetMin int64, channel string) error { |
| if _, err := s.Event(ctx, personID, eventID); err != nil { |
| return err |
| } |
| - // Team mode: a Home-only person has no address to remind. |
| - if err := s.refuseAddressless(ctx, personID); err != nil { |
| + var p Person |
| + if err := s.g.WithContext(ctx).First(&p, personID).Error; err != nil { |
| + return fmt.Errorf("calendar: read person for reminder: %w", err) |
| + } |
| + channel, err := s.ruleChannel(p, channel) |
| + if err != nil { |
| return err |
| } |
| r := Reminder{ |
| EventID: eventID, |
| PersonID: personID, |
| OffsetMin: int(offsetMin), |
| - Channel: "email", |
| + Channel: channel, |
| CreatedAt: time.Now().UTC(), |
| } |
| return s.guarded(ctx, func(db *gorm.DB) error { |
| @@ -105,7 +113,12 @@ func removeReminderOn(tx *gorm.DB, personID, reminderID int64) error { |
| // forbidden. |
| return ErrNotFound |
| } |
| - return tx.Where("reminder_id = ?", reminderID).Delete(&ReminderQueue{}).Error |
| + if err := tx.Where("reminder_id = ?", reminderID).Delete(&ReminderQueue{}).Error; err != nil { |
| + return err |
| + } |
| + // Its in-app notice goes with it: a reminder somebody removed is not |
| + // one they are still waiting to read. |
| + return tx.Where("reminder_id = ?", reminderID).Delete(&ReminderNotice{}).Error |
| } |
| // RescheduleReminder recomputes when a rule next fires and writes the |
diff --git a/internal/calendar/store_reminder_notice.go b/internal/calendar/store_reminder_notice.go| new file mode 100644 |
| index 0000000..6c64836 |
| --- /dev/null |
| +++ b/internal/calendar/store_reminder_notice.go |
| @@ -0,0 +1,192 @@ |
| +package calendar |
| + |
| +// In-app reminders (spec §7 "In-app reminders", Paul 2026-11-01): a |
| +// reminder rule's channel, and the notices the drain marks for the in-app |
| +// half instead of sending anything. |
| +// |
| +// A notice is references and times only (ReminderNotice). Its title is |
| +// opened from the sealed event when a list is drawn, through the same |
| +// grant join every read takes, so a notice on an event the person no |
| +// longer reaches, or one deleted or cancelled, is neither shown nor |
| +// counted. |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "strings" |
| + |
| + "gorm.io/gorm" |
| + |
| + "amadan.net/oficina/calendar/internal/calendar/seal" |
| + "amadan.net/oficina/calendar/internal/calendar/teamstate" |
| +) |
| + |
| +// The reminder channels. A rule's channel is fixed when it is made. |
| +const ( |
| + ChannelEmail = "email" |
| + ChannelInApp = "inapp" |
| + ChannelBoth = "both" |
| +) |
| + |
| +// validChannel reports whether c is one of the three channels. |
| +func validChannel(c string) bool { |
| + return c == ChannelEmail || c == ChannelInApp || c == ChannelBoth |
| +} |
| + |
| +// channelInApp reports whether a rule on channel c has an in-app half. |
| +func channelInApp(c string) bool { return c == ChannelInApp || c == ChannelBoth } |
| + |
| +// channelEmail reports whether a rule on channel c has an email half. |
| +// Anything that is not in-app only is mailed, as every rule was before |
| +// there was a choice: an unknown value resolves towards sending (ruling 6). |
| +func channelEmail(c string) bool { return c != ChannelInApp } |
| + |
| +// channelFor is the channel p's new rules take: in-app for a Home-only |
| +// member in team mode, who has no address to mail; otherwise their |
| +// choice, and email when they never made one. |
| +func (s *Store) channelFor(p Person) string { |
| + if s.team && teamstate.Addressless(p.Address) { |
| + return ChannelInApp |
| + } |
| + if p.ReminderChannel != nil && validChannel(*p.ReminderChannel) { |
| + return *p.ReminderChannel |
| + } |
| + return ChannelEmail |
| +} |
| + |
| +// usesInApp reports whether p's new rules have an in-app half, which is |
| +// when the chrome shows the Reminders link even with nothing unread. |
| +func (s *Store) usesInApp(p Person) bool { return channelInApp(s.channelFor(p)) } |
| + |
| +// ruleChannel is the channel a rule p asked for gets: their own channel |
| +// when they named none (or one that does not exist), and ErrNoAddress for |
| +// an email half asked for by somebody with no address. |
| +func (s *Store) ruleChannel(p Person, asked string) (string, error) { |
| + if !validChannel(asked) { |
| + asked = s.channelFor(p) |
| + } |
| + if channelEmail(asked) && s.team && teamstate.Addressless(p.Address) { |
| + return "", ErrNoAddress |
| + } |
| + return asked, nil |
| +} |
| + |
| +// MarkReminderNotice writes the in-app half of a claimed reminder: the |
| +// person's notice for this occurrence, unread. |
| +// |
| +// One statement, conditional on the claim this worker holds, as every |
| +// completion is: a reschedule that overtook the claim rewrote the queue |
| +// row to a time this worker never saw, and must not be announced. The |
| +// upsert replaces the rule's notice only for a DIFFERENT occurrence, so a |
| +// second fire of the same one (at least once, ruling 6) changes nothing |
| +// and a notice already dismissed stays dismissed. |
| +func (s *Store) MarkReminderNotice(ctx context.Context, due DueReminder, now int64) error { |
| + err := s.g.WithContext(ctx).Exec(`INSERT INTO reminder_notices |
| + (reminder_id, person_id, event_id, occurrence_key, start_utc, fired_at) |
| + SELECT ?, ?, ?, ?, ?, ? WHERE EXISTS |
| + (SELECT 1 FROM reminder_queues WHERE id = ? AND claim_id = ?) |
| + ON CONFLICT(reminder_id) DO UPDATE SET |
| + person_id = excluded.person_id, event_id = excluded.event_id, |
| + occurrence_key = excluded.occurrence_key, start_utc = excluded.start_utc, |
| + fired_at = excluded.fired_at, dismissed_at = NULL |
| + WHERE reminder_notices.occurrence_key <> excluded.occurrence_key`, |
| + due.Queue.ReminderID, due.PersonID, due.EventID, due.Queue.OccurrenceKey, due.StartUTC, now, |
| + due.Queue.ID, due.ClaimID).Error |
| + if err != nil { |
| + return fmt.Errorf("calendar: mark reminder notice: %w", err) |
| + } |
| + return nil |
| +} |
| + |
| +// NoticeView is one unread in-app reminder, opened for drawing. |
| +type NoticeView struct { |
| + ID int64 |
| + EventID int64 |
| + Title string |
| + StartUTC int64 |
| + AllDay bool |
| + // Local is the occurrence's own local start ("2026-11-02T09:00", or a |
| + // date for an all-day event), from the occurrence key. |
| + Local string |
| + // Href is the occurrence's page on this origin. |
| + Href string |
| +} |
| + |
| +// noticeRows is the one read behind the list, the count and the seam: a |
| +// person's unread notices on live events they reach on this request's |
| +// standing (grantJoin), newest occurrence first. |
| +func (s *Store) noticeRows(ctx context.Context, personID int64) *gorm.DB { |
| + return s.g.WithContext(ctx). |
| + Table("reminder_notices"). |
| + Joins("JOIN events ON events.id = reminder_notices.event_id AND events.deleted_at IS NULL AND events.status <> ?", StatusCancelled). |
| + Joins(grantJoin("events.calendar_id", s.reaches(ctx)), personID). |
| + Where("reminder_notices.person_id = ? AND reminder_notices.dismissed_at IS NULL", personID) |
| +} |
| + |
| +// UnreadNoticeCount is how many unread in-app reminders the person has. |
| +func (s *Store) UnreadNoticeCount(ctx context.Context, personID int64) (int64, error) { |
| + var n int64 |
| + if err := s.noticeRows(ctx, personID).Count(&n).Error; err != nil { |
| + return 0, fmt.Errorf("calendar: count reminder notices: %w", err) |
| + } |
| + return n, nil |
| +} |
| + |
| +// UnreadNotices lists up to limit unread in-app reminders, newest |
| +// occurrence first. |
| +func (s *Store) UnreadNotices(ctx context.Context, personID int64, limit int) ([]NoticeView, error) { |
| + type row struct { |
| + ID int64 |
| + EventID int64 |
| + OccurrenceKey string |
| + StartUTC int64 |
| + TitleSealed []byte |
| + RRule string |
| + AllDay bool |
| + } |
| + var rows []row |
| + err := s.noticeRows(ctx, personID). |
| + Select("reminder_notices.id, reminder_notices.event_id, reminder_notices.occurrence_key, reminder_notices.start_utc, events.title_sealed, events.rrule, events.all_day"). |
| + Order("reminder_notices.start_utc DESC, reminder_notices.id DESC"). |
| + Limit(limit). |
| + Scan(&rows).Error |
| + if err != nil { |
| + return nil, fmt.Errorf("calendar: list reminder notices: %w", err) |
| + } |
| + out := make([]NoticeView, 0, len(rows)) |
| + for _, r := range rows { |
| + title, err := s.seal.OpenString(seal.PurposeEventTitle, r.TitleSealed) |
| + if err != nil { |
| + return nil, fmt.Errorf("calendar: open title (notice %d): %w", r.ID, err) |
| + } |
| + _, local, _ := strings.Cut(r.OccurrenceKey, "/") |
| + href := fmt.Sprintf("/events/%d", r.EventID) |
| + if r.RRule != "" && local != "" { |
| + href += "/" + compactLocal(local) |
| + } |
| + out = append(out, NoticeView{ID: r.ID, EventID: r.EventID, Title: title, StartUTC: r.StartUTC, |
| + AllDay: r.AllDay, Local: local, Href: href}) |
| + } |
| + return out, nil |
| +} |
| + |
| +// DismissNotice marks one of the person's own notices read. Somebody |
| +// else's, or one already dismissed, changes nothing and is not an error: |
| +// the answer is the same redirect either way, so it cannot be used to |
| +// enumerate anybody's reminders. |
| +func (s *Store) DismissNotice(ctx context.Context, personID, noticeID, now int64) error { |
| + return s.guarded(ctx, func(db *gorm.DB) error { |
| + return db.Model(&ReminderNotice{}). |
| + Where("id = ? AND person_id = ? AND dismissed_at IS NULL", noticeID, personID). |
| + Update("dismissed_at", now).Error |
| + }) |
| +} |
| + |
| +// DismissAllNotices marks every one of the person's notices read. |
| +func (s *Store) DismissAllNotices(ctx context.Context, personID, now int64) error { |
| + return s.guarded(ctx, func(db *gorm.DB) error { |
| + return db.Model(&ReminderNotice{}). |
| + Where("person_id = ? AND dismissed_at IS NULL", personID). |
| + Update("dismissed_at", now).Error |
| + }) |
| +} |
diff --git a/internal/calendar/team_guard_test.go b/internal/calendar/team_guard_test.go| index 6b46b41..6dafd6d 100644 |
| --- a/internal/calendar/team_guard_test.go |
| +++ b/internal/calendar/team_guard_test.go |
| @@ -24,7 +24,7 @@ import ( |
| func teamSnapshot(t *testing.T, f *teamFixture) string { |
| t.Helper() |
| var b strings.Builder |
| - for _, table := range []string{"events", "reminders", "reminder_queues", "feeds", "people", "booking_pages", "booking_windows", "bookings", "booking_mails", "attendees", "calendars", "grants"} { |
| + for _, table := range []string{"events", "reminders", "reminder_queues", "reminder_notices", "feeds", "people", "booking_pages", "booking_windows", "bookings", "booking_mails", "attendees", "calendars", "grants"} { |
| rows, err := f.app.DBForTest().Query("SELECT * FROM " + table + " ORDER BY rowid") |
| if err != nil { |
| t.Fatal(err) |
| @@ -100,6 +100,10 @@ func (w *teamWriteWorld) routes() []writeRoute { |
| {"delete one occurrence", func() *httptest.ResponseRecorder { |
| return f.post("/events/"+id(w.series.ID)+"/delete", "scope=this&occurrence=2027-01-07T09:00") |
| }}, |
| + {"dismiss a reminder", func() *httptest.ResponseRecorder { |
| + return f.post("/reminders/"+id(w.notices[0])+"/dismiss", "") |
| + }}, |
| + {"dismiss all reminders", func() *httptest.ResponseRecorder { return f.post("/reminders/dismiss", "") }}, |
| {"add reminder", func() *httptest.ResponseRecorder { |
| return f.post("/events/"+id(w.single.ID)+"/reminders", "offset_min=60") |
| }}, |
diff --git a/internal/calendar/team_inapp_test.go b/internal/calendar/team_inapp_test.go| new file mode 100644 |
| index 0000000..2279084 |
| --- /dev/null |
| +++ b/internal/calendar/team_inapp_test.go |
| @@ -0,0 +1,242 @@ |
| +package calendar |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "net/http" |
| + "net/url" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/home/dashboard" |
| +) |
| + |
| +// In-app reminders in team mode (spec §7 "In-app reminders", Paul |
| +// 2026-11-01): a Home-only member's reminders are notices in this |
| +// database, decided on their standing at fire time exactly as email is. |
| + |
| +// homeOnlyEvent creates an event starting a few minutes from now on p's |
| +// team calendar through the form, so p's own default reminder (ten |
| +// minutes, in-app for a Home-only member) is made and already due. A POST |
| +// runs no page-view drain, so nothing has fired yet. |
| +func homeOnlyEvent(t *testing.T, f *teamFixture, team int64, title string) Event { |
| + t.Helper() |
| + start, end := soon(5) |
| + mustRedirect(t, "create "+title, f.post("/events", "calendar_id="+itoa(team)+"&title="+url.QueryEscape(title)+ |
| + "&start="+url.QueryEscape(start)+"&end="+url.QueryEscape(end)+"&tz=UTC&kind=meeting&status=confirmed")) |
| + var e Event |
| + if err := f.app.db.G.Where("calendar_id = ?", team).Last(&e).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + return e |
| +} |
| + |
| +// noticesOf is p's notices, as stored. |
| +func noticesOf(f *teamFixture, p Person) []ReminderNotice { |
| + var out []ReminderNotice |
| + f.app.db.G.Where("person_id = ?", p.ID).Order("id").Find(&out) |
| + return out |
| +} |
| + |
| +func TestTeamInAppReminderFiresUnreadForAHomeOnlyMember(t *testing.T) { |
| + f := newTeamFixture(t) |
| + box := f.mailbox() |
| + subject := teamSubject('i') |
| + p := f.member(subject, "member") |
| + team, _ := f.calendarsOf(p) |
| + const secret = "Quarterly board meeting about the acquisition" |
| + e := homeOnlyEvent(t, f, team, secret) |
| + |
| + // The first page opened after it came due shows it: the page-view |
| + // drain marks it before the page is drawn. |
| + page := f.get("/reminders").Body.String() |
| + if !strings.Contains(page, secret) || !strings.Contains(page, "Reminders (1)") || !strings.Contains(page, "/reminders/") { |
| + t.Fatal("a due in-app reminder is not on the next page, unread, with its count in the chrome") |
| + } |
| + if !strings.Contains(page, `href="/events/`+itoa(e.ID)+`"`) || !strings.Contains(page, "Starts ") { |
| + t.Fatal("the reminder does not link to its event or say when it is") |
| + } |
| + n := noticesOf(f, p) |
| + if len(n) != 1 || n[0].EventID != e.ID || n[0].DismissedAt != nil { |
| + t.Fatalf("notices = %+v", n) |
| + } |
| + if len(box.sent) != 0 { |
| + t.Fatalf("an in-app reminder sent mail: %v", box.sent) |
| + } |
| + // The tick's drain marks one too, and counts it delivered. |
| + homeOnlyEvent(t, f, team, "Second thing") |
| + if sent, _, err := f.app.h.drain(context.Background(), time.Now()); err != nil || sent != 1 || len(noticesOf(f, p)) != 2 { |
| + t.Fatalf("the tick's drain = %d %v, %d notices", sent, err, len(noticesOf(f, p))) |
| + } |
| + |
| + // The native list and the seam for Home agree. |
| + var native struct { |
| + Unread int64 `json:"unread"` |
| + Reminders []struct { |
| + Title string `json:"title"` |
| + Path string `json:"path"` |
| + } `json:"reminders"` |
| + } |
| + w := f.get("/api/native/reminders") |
| + if err := json.Unmarshal(w.Body.Bytes(), &native); err != nil || native.Unread != 2 || len(native.Reminders) != 2 { |
| + t.Fatalf("native reminders = %d %s", w.Code, w.Body.String()) |
| + } |
| + sum, err := f.app.reminderNotices(context.Background(), p.ID, subject, time.Now()) |
| + if err != nil || sum.Unread != 2 || len(sum.Items) != 2 || sum.Truncated { |
| + t.Fatalf("the seam = %+v %v", sum, err) |
| + } |
| + for _, it := range sum.Items { |
| + if !dashboard.SafeLink(it.URL, homeTestOrigin) || strings.Contains(it.URL, "acquisition") || it.Start.IsZero() { |
| + t.Fatalf("the seam's link %+v is not a bare link on this origin", it) |
| + } |
| + } |
| + |
| + // The one rule holds: the notice is references and times. |
| + if _, err := f.app.DBForTest().Exec("PRAGMA wal_checkpoint(TRUNCATE)"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if found, where := f.app.GrepDatabaseForTest(t, secret); found { |
| + t.Fatalf("the title is in plaintext in %s", where) |
| + } |
| +} |
| + |
| +func TestTeamInAppRemindersAreDismissed(t *testing.T) { |
| + f := newTeamFixture(t) |
| + subject := teamSubject('d') |
| + p := f.member(subject, "member") |
| + team, _ := f.calendarsOf(p) |
| + first := homeOnlyEvent(t, f, team, "First") |
| + homeOnlyEvent(t, f, team, "Second") |
| + if _, _, err := f.app.h.drain(context.Background(), time.Now()); err != nil || len(noticesOf(f, p)) != 2 { |
| + t.Fatalf("drain: %v, %d notices", err, len(noticesOf(f, p))) |
| + } |
| + var one ReminderNotice |
| + f.app.db.G.Where("event_id = ?", first.ID).First(&one) |
| + |
| + // Somebody else's dismissal answers the same and changes nothing. |
| + other := teamSubject('e') |
| + f.member(other, "member") |
| + mustRedirect(t, "a stranger's dismissal", f.post("/reminders/"+itoa(one.ID)+"/dismiss", "")) |
| + f.signInHome(subject) |
| + if body := f.get("/reminders").Body.String(); !strings.Contains(body, "Reminders (2)") { |
| + t.Fatal("another member dismissed this member's reminder") |
| + } |
| + |
| + mustRedirect(t, "dismiss", f.post("/reminders/"+itoa(one.ID)+"/dismiss", "")) |
| + body := f.get("/reminders").Body.String() |
| + if strings.Contains(body, ">First<") || !strings.Contains(body, ">Second<") || !strings.Contains(body, "Reminders (1)") { |
| + t.Fatal("dismissing one did not take it, and only it, off the list") |
| + } |
| + // Delivered again (at least once): a dismissed notice stays dismissed. |
| + var rule int64 |
| + f.app.db.G.Model(&Reminder{}).Where("event_id = ?", first.ID).Pluck("id", &rule) |
| + if err := f.app.store.RescheduleReminder(context.Background(), rule); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, _, err := f.app.h.drain(context.Background(), time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.app.db.G.First(&one, one.ID) |
| + if one.DismissedAt == nil { |
| + t.Fatal("the same occurrence delivered again un-dismissed its notice") |
| + } |
| + |
| + mustRedirect(t, "dismiss all", f.post("/reminders/dismiss", "")) |
| + body = f.get("/reminders").Body.String() |
| + if strings.Contains(body, ">Second<") || strings.Contains(body, "Reminders (") || !strings.Contains(body, "No reminders waiting") { |
| + t.Fatal("dismissing all left something unread") |
| + } |
| + // Removing the rule takes its notice with it. |
| + mustRedirect(t, "remove", f.post("/events/"+itoa(first.ID)+"/reminders/remove", "reminder_id="+itoa(rule))) |
| + var left int64 |
| + f.app.db.G.Model(&ReminderNotice{}).Where("reminder_id = ?", rule).Count(&left) |
| + if left != 0 { |
| + t.Fatal("a removed rule's notice was kept") |
| + } |
| +} |
| + |
| +func TestTeamInAppReminderToARemovedMemberIsNothing(t *testing.T) { |
| + f := newTeamFixture(t) |
| + subject := teamSubject('r') |
| + p := f.member(subject, "member") |
| + team, _ := f.calendarsOf(p) |
| + e := homeOnlyEvent(t, f, team, "After they left") |
| + f.dir.Set(subject, "") |
| + f.refreshed() |
| + if _, _, err := f.app.h.drain(context.Background(), time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if n := noticesOf(f, p); len(n) != 0 { |
| + t.Fatalf("a removed member got a notice: %+v", n) |
| + } |
| + var q ReminderQueue |
| + f.app.db.G.Joins("JOIN reminders ON reminders.id = reminder_queues.reminder_id").Where("reminders.event_id = ?", e.ID).First(&q) |
| + if q.FiredAt == nil || q.ClaimID == nil || *q.ClaimID != dormantClaim { |
| + t.Fatalf("a removed member's in-app rule = %+v, want dormant", q) |
| + } |
| + // What they had before is not readable either, by Home's pull. |
| + if err := f.app.db.G.Create(&ReminderNotice{ReminderID: q.ReminderID, PersonID: p.ID, EventID: e.ID, OccurrenceKey: q.OccurrenceKey, StartUTC: e.StartUTC, FiredAt: time.Now().Unix()}).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + if sum, err := f.app.reminderNotices(context.Background(), p.ID, subject, time.Now()); err != nil || sum.Unread != 0 || len(sum.Items) != 0 { |
| + t.Fatalf("the seam for a removed member = %+v %v", sum, err) |
| + } |
| +} |
| + |
| +func TestTeamInAppReminderUnderUnknownDefers(t *testing.T) { |
| + f := newTeamFixture(t) |
| + subject := teamSubject('u') |
| + p := f.member(subject, "member") |
| + team, _ := f.calendarsOf(p) |
| + e := homeOnlyEvent(t, f, team, "Held back") |
| + f.expired() |
| + if _, _, err := f.app.h.drain(context.Background(), time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if n := noticesOf(f, p); len(n) != 0 { |
| + t.Fatalf("a notice was marked while standing was unknown: %+v", n) |
| + } |
| + var q ReminderQueue |
| + f.app.db.G.Joins("JOIN reminders ON reminders.id = reminder_queues.reminder_id").Where("reminders.event_id = ?", e.ID).First(&q) |
| + if q.FiredAt != nil || q.RetryAt == nil || q.Attempts != 0 { |
| + t.Fatalf("under Unknown = fired %v retry %v attempts %d, want deferred", q.FiredAt, q.RetryAt, q.Attempts) |
| + } |
| + // Every surface: the list is partial and says so, never "nothing |
| + // waiting"; everything else is a retryable 503; Home's pull is |
| + // unavailable, never a short count. |
| + w := f.get("/reminders") |
| + if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), partialTitle) || strings.Contains(w.Body.String(), "No reminders waiting") { |
| + t.Fatalf("the list under Unknown = %d", w.Code) |
| + } |
| + retryable(t, "native reminders under Unknown", f.get("/api/native/reminders")) |
| + retryable(t, "dismiss under Unknown", f.post("/reminders/1/dismiss", "")) |
| + retryable(t, "dismiss all under Unknown", f.post("/reminders/dismiss", "")) |
| + if _, err := f.app.reminderNotices(context.Background(), p.ID, subject, time.Now()); !errors.Is(err, dashboard.ErrUnavailable) { |
| + t.Fatalf("the seam under Unknown = %v, want unavailable", err) |
| + } |
| + // Standing back: delivered, late. |
| + f.refreshed() |
| + if sent, _, err := f.app.h.drain(context.Background(), time.Now().Add(standingRetry+time.Second)); err != nil || sent != 1 || len(noticesOf(f, p)) != 1 { |
| + t.Fatalf("after standing returned = %d %v", sent, err) |
| + } |
| +} |
| + |
| +// A Home-only member's in-app rules reach their own calendar app through |
| +// a feed with alarms: VALARM DISPLAY at the rule's offset. |
| +func TestTeamInAppRulesAreFeedAlarms(t *testing.T) { |
| + f := newTeamFixture(t) |
| + p := f.member(teamSubject('a'), "member") |
| + team, _ := f.calendarsOf(p) |
| + mustRedirect(t, "create", f.post("/events", "calendar_id="+itoa(team)+"&title=Alarmed&start=2027-01-05T10:00&end=2027-01-05T11:00&tz=UTC&kind=meeting&status=confirmed")) |
| + u, _ := url.Parse(f.post("/calendars/"+itoa(team)+"/feeds", "").Header().Get("Location")) |
| + token := u.Query().Get("token") |
| + body := f.do("GET", "/feed/"+token+".ics?alarms=1", "").Body.String() |
| + if !strings.Contains(body, "BEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:Alarmed\r\nTRIGGER:-PT10M\r\nEND:VALARM") { |
| + t.Fatalf("no display alarm for an in-app rule:\n%s", body) |
| + } |
| + if strings.Contains(f.do("GET", "/feed/"+token+".ics", "").Body.String(), "VALARM") { |
| + t.Fatal("a feed without alarms=1 carried one") |
| + } |
| +} |
diff --git a/internal/calendar/team_jobs.go b/internal/calendar/team_jobs.go| index e621451..e7d464a 100644 |
| --- a/internal/calendar/team_jobs.go |
| +++ b/internal/calendar/team_jobs.go |
| @@ -9,10 +9,12 @@ package calendar |
| // asked when it is about to go, so a job acting on a removed member's |
| // events leaks nothing to them: |
| // |
| -// - a reminder is sent only to a recipient the roster says is a Member |
| -// now, who still reaches the event on that standing, and who has an |
| -// address. No reach, or a Home-only recipient, settles that occurrence |
| -// unsent and queues the next, decided the same way on its day. |
| +// - a reminder is delivered only to a recipient the roster says is a |
| +// Member now, who still reaches the event on that standing, and, for a |
| +// rule that is mailed, who has an address. No reach, or an email-only |
| +// rule of a Home-only recipient, settles that occurrence unsent and |
| +// queues the next, decided the same way on its day. An in-app rule |
| +// needs no address: its delivery is a notice in this database. |
| // NotMember settles it unsent and queues NOTHING: the rule goes |
| // dormant, so a removed member's daily standup does not wake the |
| // instance every day for nobody (Fable #35 N2). Re-added, their next |
| @@ -72,7 +74,7 @@ func (h *handlers) reminderDelivery(ctx context.Context, due DueReminder) delive |
| if h.team == nil { |
| return deliverNow |
| } |
| - if teamstate.Addressless(due.Address) { |
| + if !channelInApp(due.Channel) && teamstate.Addressless(due.Address) { |
| return deliverNever |
| } |
| acc := h.standingFor(ctx, due.PersonID) |
| @@ -113,6 +115,26 @@ func (h *handlers) settleWithoutSending(ctx context.Context, due DueReminder, no |
| return false, nil |
| } |
| +// deliverInApp delivers the in-app half of a reminder the drain may |
| +// deliver: it marks the person's notice, under the claim. done is true |
| +// when that was everything — an in-app-only rule, or a rule whose email |
| +// half has no address to go to in team mode — and the reminder has been |
| +// completed, which queues its next occurrence. An email-only rule is |
| +// untouched (done false, nothing written), so its path is what it always |
| +// was. |
| +func (h *handlers) deliverInApp(ctx context.Context, due DueReminder, now time.Time) (done bool, err error) { |
| + if !channelInApp(due.Channel) { |
| + return false, nil |
| + } |
| + if err := h.store.MarkReminderNotice(keep(ctx), due, now.Unix()); err != nil { |
| + return false, err |
| + } |
| + if channelEmail(due.Channel) && (h.team == nil || !teamstate.Addressless(due.Address)) { |
| + return false, nil |
| + } |
| + return true, h.store.CompleteReminder(keep(ctx), due, now.Unix()) |
| +} |
| + |
| // settleDormant settles a claimed reminder unsent and queues nothing, |
| // conditional on the claim as every completion is: the row is fired and |
| // held under dormantClaim until its person returns. |
diff --git a/internal/calendar/team_jobs_test.go b/internal/calendar/team_jobs_test.go| index 9faf21f..c293fa3 100644 |
| --- a/internal/calendar/team_jobs_test.go |
| +++ b/internal/calendar/team_jobs_test.go |
| @@ -143,7 +143,9 @@ func TestTeamRemindersGoOnlyToMembersWhoReachTheEvent(t *testing.T) { |
| } |
| } |
| -func TestTeamHomeOnlyMembersGetNoRemindersAndPublishNoPage(t *testing.T) { |
| +// A Home-only member has no address: their reminders are in-app, by |
| +// default and only (Paul, 2026-11-01), and no mail ever goes to them. |
| +func TestTeamHomeOnlyMembersGetInAppRemindersOnlyAndPublishNoPage(t *testing.T) { |
| f := newTeamFixture(t) |
| box := f.mailbox() |
| p := f.member(teamSubject('h'), "member") |
| @@ -153,37 +155,46 @@ func TestTeamHomeOnlyMembersGetNoRemindersAndPublishNoPage(t *testing.T) { |
| if w.Code != http.StatusSeeOther { |
| t.Fatalf("create = %d", w.Code) |
| } |
| - reminders := func() int64 { |
| - var n int64 |
| - f.app.db.G.Model(&Reminder{}).Where("person_id = ?", p.ID).Count(&n) |
| - return n |
| + channels := func() []string { |
| + var out []string |
| + f.app.db.G.Model(&Reminder{}).Where("person_id = ?", p.ID).Order("id").Pluck("channel", &out) |
| + return out |
| } |
| - if reminders() != 0 { |
| - t.Fatal("a Home-only member got a default reminder") |
| + if got := channels(); len(got) != 1 || got[0] != ChannelInApp { |
| + t.Fatalf("a Home-only member's default reminder = %v, want one in-app", got) |
| } |
| var e Event |
| f.app.db.G.Where("calendar_id = ?", team).Last(&e) |
| - if w := f.post("/events/"+itoa(e.ID)+"/reminders", "offset_min=10"); w.Code != http.StatusSeeOther || reminders() != 0 { |
| - t.Fatalf("adding a reminder = %d, %d reminders", w.Code, reminders()) |
| + // Email, asked for by name, is refused; nothing is made. |
| + for _, ch := range []string{"email", "both"} { |
| + if w := f.post("/events/"+itoa(e.ID)+"/reminders", "offset_min=60&channel="+ch); w.Code != http.StatusSeeOther || len(channels()) != 1 { |
| + t.Fatalf("adding a %s reminder = %d, %v", ch, w.Code, channels()) |
| + } |
| + } |
| + if w := f.post("/events/"+itoa(e.ID)+"/reminders", "offset_min=60"); w.Code != http.StatusSeeOther || len(channels()) != 2 || channels()[1] != ChannelInApp { |
| + t.Fatalf("adding a reminder = %d, %v", w.Code, channels()) |
| } |
| page := f.get("/events/" + itoa(e.ID)).Body.String() |
| - if !strings.Contains(page, "data-no-address") || strings.Contains(page, "cal-reminder-add") { |
| - t.Fatal("the event page offers a Home-only member a reminder") |
| + if !strings.Contains(page, "data-no-address") || !strings.Contains(page, "cal-reminder-add") || strings.Contains(page, `name="channel"`) || !strings.Contains(page, "In Calendar 10 minutes before") { |
| + t.Fatal("the event page does not offer a Home-only member in-app reminders, and only those") |
| } |
| - if !strings.Contains(f.get("/settings").Body.String(), "No email from this calendar") { |
| - t.Fatal("settings do not say what a Home-only member lacks") |
| + settings := f.get("/settings").Body.String() |
| + if !strings.Contains(settings, "No email from this calendar") || strings.Contains(settings, `name="reminder_channel"`) { |
| + t.Fatal("settings do not say what a Home-only member lacks, or offer them email") |
| } |
| // A reminder row made behind the app's back is still never mailed. |
| if err := f.app.db.G.Create(&Reminder{EventID: e.ID, PersonID: p.ID, OffsetMin: 10, Channel: "email", CreatedAt: time.Now()}).Error; err != nil { |
| t.Fatal(err) |
| } |
| - var rem Reminder |
| - f.app.db.G.Where("person_id = ?", p.ID).First(&rem) |
| - if err := f.app.store.RescheduleReminder(context.Background(), rem.ID); err != nil { |
| - t.Fatal(err) |
| + var ids []int64 |
| + f.app.db.G.Model(&Reminder{}).Where("person_id = ?", p.ID).Pluck("id", &ids) |
| + for _, id := range ids { |
| + if err := f.app.store.RescheduleReminder(context.Background(), id); err != nil { |
| + t.Fatal(err) |
| + } |
| } |
| - if sent, _, err := f.app.h.drain(context.Background(), time.Now()); err != nil || sent != 0 { |
| - t.Fatalf("drain for a Home-only member = %d %v", sent, err) |
| + if _, _, err := f.app.h.drain(context.Background(), time.Now()); err != nil { |
| + t.Fatalf("drain for a Home-only member: %v", err) |
| } |
| if len(box.sent) != 0 { |
| t.Fatalf("mail went out: %v", box.sent) |
diff --git a/internal/calendar/team_world_test.go b/internal/calendar/team_world_test.go| index c780c10..6a53c51 100644 |
| --- a/internal/calendar/team_world_test.go |
| +++ b/internal/calendar/team_world_test.go |
| @@ -21,6 +21,7 @@ type teamWriteWorld struct { |
| team int64 |
| single, series Event |
| reminder int64 |
| + notices []int64 // alice's two unread in-app notices |
| feed int64 |
| path string // the public booking page |
| day string // a future day with free slots |
| @@ -64,6 +65,21 @@ func newTeamWriteWorld(t *testing.T) *teamWriteWorld { |
| t.Fatal(err) |
| } |
| f.app.db.G.Model(&Reminder{}).Where("event_id = ?", w.single.ID).Pluck("id", &w.reminder) |
| + // Two unread in-app notices, one per rule, for the dismissals. |
| + if err := f.app.store.AddReminderOn(ctx, w.alice.ID, w.series.ID, 5, ChannelInApp); err != nil { |
| + t.Fatal(err) |
| + } |
| + var second int64 |
| + f.app.db.G.Model(&Reminder{}).Where("event_id = ?", w.series.ID).Pluck("id", &second) |
| + for _, n := range []ReminderNotice{ |
| + {ReminderID: w.reminder, PersonID: w.alice.ID, EventID: w.single.ID, OccurrenceKey: itoa(w.single.ID) + "/2027-01-05T10:00", StartUTC: w.single.StartUTC, FiredAt: time.Now().Unix()}, |
| + {ReminderID: second, PersonID: w.alice.ID, EventID: w.series.ID, OccurrenceKey: itoa(w.series.ID) + "/2027-01-04T09:00", StartUTC: w.series.StartUTC, FiredAt: time.Now().Unix()}, |
| + } { |
| + if err := f.app.db.G.Create(&n).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + w.notices = append(w.notices, n.ID) |
| + } |
| if _, err := f.app.store.MintFeed(ctx, w.alice.ID, w.team); err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/calendar/templates/event.html b/internal/calendar/templates/event.html| index dc7876e..2ae8dc9 100644 |
| --- a/internal/calendar/templates/event.html |
| +++ b/internal/calendar/templates/event.html |
| @@ -67,14 +67,14 @@ |
| <div cal-box-body> |
| {{/* Yours only. Whether a colleague wants a warning is a fact |
| about them, and not something this page should carry. */}} |
| - {{if .Data.NoAddress}}<p data-no-address>Email reminders need an email address, and you signed in with an Oficina account that doesn’t give this calendar one, so this calendar can’t remind you.</p>{{else}}{{if .Data.Reminders}} |
| + {{if .Data.NoAddress}}<p data-no-address>You signed in with an Oficina account, which doesn’t give this calendar an email address, so your reminders appear in Calendar, under Reminders, and not by email.</p>{{end}}{{if .Data.Reminders}} |
| {{range .Data.Reminders}} |
| <form cal-reminder method="post" action="/events/{{$.Data.Event.ID}}/reminders/remove"> |
| <input type="hidden" name="reminder_id" value="{{.ID}}"> |
| {{/* class, not an attribute: rst-grow is one of the seven |
| rastrillo utilities that keep the class spelling and have no |
| attribute twin. Written bare it silently does nothing. */}} |
| - <span class="rst-grow">Email {{minutesLabel .OffsetMin}}</span> |
| + <span class="rst-grow">{{channelLabel .Channel}} {{minutesLabel .OffsetMin}}</span> |
| <button rst-btn="ghost compact" type="submit">Remove</button> |
| </form> |
| {{end}} |
| @@ -91,9 +91,15 @@ |
| (dict "Value" "10" "Label" "10 minutes before" "Selected" true) |
| (dict "Value" "30" "Label" "30 minutes before") |
| (dict "Value" "60" "Label" "1 hour before") |
| - (dict "Value" "1440" "Label" "1 day before"))}} |
| + (dict "Value" "1440" "Label" "1 day before"))}}{{if .Data.ChannelChoice}} |
| + {{template "field-select" dict |
| + "ID" "channel" "Name" "channel" "Label" "How" "Short" true |
| + "Options" (list |
| + (dict "Value" "email" "Label" "By email" "Selected" (eq .Data.Channel "email")) |
| + (dict "Value" "inapp" "Label" "In Calendar" "Selected" (eq .Data.Channel "inapp")) |
| + (dict "Value" "both" "Label" "By email and in Calendar" "Selected" (eq .Data.Channel "both")))}}{{end}} |
| <button rst-btn type="submit">Add</button> |
| - </form>{{end}} |
| + </form> |
| </div> |
| </section> |
diff --git a/internal/calendar/templates/reminders.html b/internal/calendar/templates/reminders.html| new file mode 100644 |
| index 0000000..26fe1f3 |
| --- /dev/null |
| +++ b/internal/calendar/templates/reminders.html |
| @@ -0,0 +1,47 @@ |
| +{{define "title"}}{{.Title}}{{end}} |
| +{{define "content"}} |
| +<header rst-page-header> |
| + <div rst-page-header-titles> |
| + <h1>Reminders</h1> |
| + </div> |
| +</header>{{if .Partial}}{{template "team-partial" .}}{{end}} |
| + |
| +{{/* In-app reminders (spec §7): the ones that have come due, newest |
| + first, until they are dismissed. Unread means undismissed, because |
| + nothing is written on a GET. Every action is a plain link or form. */}} |
| +{{if .Data.Notices}} |
| +<p cal-sentence cal-sentence-muted>Reminders that have come due stay here until you dismiss them.</p> |
| +<div rst-list cal-notices> |
| + {{range .Data.Notices}} |
| + <div rst-row> |
| + <span rst-row-main> |
| + <a href="{{.Href}}">{{.Title}}</a> |
| + <small rst-row-sub>{{.When}}</small> |
| + </span> |
| + <form rst-row-action method="post" action="/reminders/{{.ID}}/dismiss"> |
| + <button rst-btn="ghost compact" type="submit">Dismiss<span class="rst-sr-only"> {{.Title}}</span></button> |
| + </form> |
| + </div> |
| + {{end}} |
| +</div> |
| +<div cal-bar> |
| + <form method="post" action="/reminders/dismiss"> |
| + <button rst-btn type="submit">Dismiss all</button> |
| + </form> |
| +</div> |
| +{{else if not .Partial}} |
| +{{/* Withheld under Unknown, so an empty partial list never reads as |
| + "nothing due". */}} |
| +{{if .Data.InApp}} |
| +{{template "empty-state" dict |
| + "Title" "No reminders waiting" |
| + "Body" "When a reminder you set comes due, it appears here and stays until you dismiss it."}} |
| +{{else}} |
| +{{template "empty-state" dict |
| + "Title" "No reminders waiting" |
| + "Body" "Your reminders come by email. To have them appear here instead, or as well, choose how to be reminded in Settings." |
| + "ActionHref" "/settings" |
| + "ActionLabel" "Open Settings"}} |
| +{{end}} |
| +{{end}} |
| +{{end}} |
diff --git a/internal/calendar/templates/settings.html b/internal/calendar/templates/settings.html| index 4dd48b9..3a4b4a7 100644 |
| --- a/internal/calendar/templates/settings.html |
| +++ b/internal/calendar/templates/settings.html |
| @@ -6,7 +6,7 @@ |
| </div> |
| </header> |
| -{{if .Data.NoAddress}}{{template "callout" dict "Tone" "info" "Title" "No email from this calendar" "Body" "You signed in with an Oficina account, which doesn’t give this calendar an email address. Reminders are not sent, and booking pages cannot be published."}}{{end}}{{if .Data.Saved}} |
| +{{if .Data.NoAddress}}{{template "callout" dict "Tone" "info" "Title" "No email from this calendar" "Body" "You signed in with an Oficina account, which doesn’t give this calendar an email address. Your reminders appear here in Calendar, under Reminders, instead of by email, and booking pages cannot be published."}}{{end}}{{if .Data.Saved}} |
| {{template "callout" dict "Tone" "positive" "Body" "Saved."}} |
| {{end}} |
| {{with .Data.Error}} |
| @@ -56,6 +56,14 @@ |
| (dict "Value" "360" "Label" "The evening before" "Selected" (eq .Data.Person.DefaultAllDayMin 360)) |
| (dict "Value" "1440" "Label" "A day before" "Selected" (eq .Data.Person.DefaultAllDayMin 1440)))}} |
| + {{if not .Data.NoAddress}}{{template "field-select" dict |
| + "ID" "reminder_channel" "Name" "reminder_channel" "Label" "How to remind me" |
| + "Hint" "In Calendar puts a reminder under Reminders at the top of every page until you dismiss it; nothing is sent. This applies to reminders you add from now on." |
| + "Options" (list |
| + (dict "Value" "email" "Label" "By email" "Selected" (eq .Data.Channel "email")) |
| + (dict "Value" "inapp" "Label" "In Calendar" "Selected" (eq .Data.Channel "inapp")) |
| + (dict "Value" "both" "Label" "By email and in Calendar" "Selected" (eq .Data.Channel "both")))}}{{end}} |
| + |
| {{template "form-foot" dict "Submit" "Save" "CancelHref" "/today" "CancelLabel" "Cancel"}} |
| </form> |
| {{end}} |
diff --git a/internal/calendartest/schedule_progress_test.go b/internal/calendartest/schedule_progress_test.go| index fe0811f..d451c03 100644 |
| --- a/internal/calendartest/schedule_progress_test.go |
| +++ b/internal/calendartest/schedule_progress_test.go |
| @@ -1,6 +1,7 @@ |
| package calendartest |
| import ( |
| + "fmt" |
| "net/http" |
| "net/url" |
| "testing" |
| @@ -32,11 +33,17 @@ func TestRepeatedOccurrenceGuardFailsEvenAfterASuccessfulSend(t *testing.T) { |
| control := controlForTest(t) |
| app, session := signedIn(t, "someone@example.com") |
| now := time.Now().UTC() |
| - for _, offset := range []time.Duration{time.Hour, 2 * time.Hour} { |
| - start := now.Add(offset) |
| - createEvent(t, app.Handler(), session, url.Values{"title": {"Guarded reminder"}, "start": {start.Format("2006-01-02T15:04")}, "end": {start.Add(15 * time.Minute).Format("2006-01-02T15:04")}, "kind": {"meeting"}, "status": {"confirmed"}, "repeat": {"none"}}) |
| + start := now.Add(time.Hour) |
| + createEvent(t, app.Handler(), session, url.Values{"title": {"Guarded reminder"}, "start": {start.Format("2006-01-02T15:04")}, "end": {start.Add(15 * time.Minute).Format("2006-01-02T15:04")}, "kind": {"meeting"}, "status": {"confirmed"}, "repeat": {"none"}}) |
| + past := now.Add(-time.Minute).Unix() |
| + if _, err := app.DBForTest().Exec(`UPDATE reminder_queues SET due_at=?`, past); err != nil { |
| + t.Fatal(err) |
| } |
| - if _, err := app.DBForTest().Exec(`UPDATE reminder_queues SET occurrence_key='same', due_at=?`, now.Add(-time.Minute).Unix()); err != nil { |
| + // A broken reschedule: whatever the send's completion writes back, the |
| + // SAME rule's SAME occurrence is claimable again in the same pass. (Two |
| + // different rules sharing an occurrence — two people's reminders on |
| + // one meeting — are each owed once, and are not this.) |
| + if _, err := app.DBForTest().Exec(fmt.Sprintf(`CREATE TRIGGER rearm AFTER UPDATE OF due_at ON reminder_queues WHEN NEW.due_at > %d BEGIN UPDATE reminder_queues SET due_at = %d WHERE id = NEW.id; END`, past, past)); err != nil { |
| t.Fatal(err) |
| } |
| before := time.Now() |