oficina / calendar Public

Clone
git clone https://amadan.net/oficina/calendar

Plain git — no account needed to clone.

Download

Download this file

1package calendar
2
3// The seam for Home's notification centre (spec §7 "In-app reminders").
4//
5// Paul, 2026-11-01: a suite-wide notification centre on oficina.works
6// comes later, as its own reviewed Home design, and Calendar builds
7// nothing in Home now. What Calendar owes that design is a read Home can
8// PULL that stores no content in Home: how many reminders are unread, and
9// a link to each. reminderNotices is that read, shaped like
10// dashboardEvents — the Read home/dashboard's provider calls today, with
11// (ctx, person, verified subject, now) in and an answer or an
12// unavailability out. It is not itself a dashboard Read (it returns a
13// NoticeSummary, not a dashboard.Response, and its now is unused): when
14// Home has a kind for it, Calendar wraps this in a provider for that kind,
15// behind the same bearer, replay and Resolve checks the dashboard pull
16// already has (dashboard.go), and nothing in Calendar's storage changes.
17//
18// It is not mounted: home/dashboard's provider accepts only the kinds
19// "documents" and "events" today, and the wire for a notification kind is
20// Home's to design.
21
22import (
23 "context"
24 "strconv"
25 "time"
26
27 "amadan.net/oficina/home/dashboard"
28 "amadan.net/oficina/home/teammode"
29)
30
31// NoticeLink is one unread in-app reminder as Home would see it: an
32// opaque ID that changes when the rule fires for a newer occurrence, an
33// absolute link on this origin, and when the occurrence starts. No
34// title: Home holds a link, never the content behind it.
35type NoticeLink struct {
36 ID string
37 URL string
38 Start time.Time
39}
40
41// NoticeSummary is the pull's answer: the unread count, and the links to
42// the newest of them. Unread may exceed len(Items); Truncated says so.
43type NoticeSummary struct {
44 Unread int
45 Items []NoticeLink
46 Truncated bool
47}
48
49// reminderNotices reads person's unread in-app reminders for a verified
50// Home subject. In team mode it reads on the subject's roster standing,
51// never anything stored: Unknown is dashboard.ErrUnavailable (never a
52// short count, to a reader on another origin who cannot see a partial
53// notice), asked after reading, as dashboardEvents asks, because a lease
54// can lapse during it (Unknown before reading reads nothing, so the one
55// check answers both); NotMember reaches nothing and so counts nothing.
56func (a *App) reminderNotices(ctx context.Context, id int64, subject string, _ time.Time) (NoticeSummary, error) {
57 var standing *teammode.Access
58 if a.team != nil {
59 standing = a.team.Access(ctx, subject)
60 ctx = teammode.WithAccess(ctx, standing)
61 }
62 n, err := a.store.UnreadNoticeCount(ctx, id)
63 if err != nil {
64 return NoticeSummary{}, err
65 }
66 list, err := a.store.UnreadNotices(ctx, id, dashboard.MaxItems)
67 if err != nil {
68 return NoticeSummary{}, err
69 }
70 if standing != nil && standing.Partial() {
71 return NoticeSummary{}, dashboard.ErrUnavailable
72 }
73 out := NoticeSummary{Unread: int(n), Items: make([]NoticeLink, 0, len(list)), Truncated: int(n) > len(list)}
74 for _, v := range list {
75 out.Items = append(out.Items, NoticeLink{
76 ID: strconv.FormatInt(v.ID, 10) + ":" + strconv.FormatInt(v.StartUTC, 10),
77 URL: a.cfg.Origin + v.Href,
78 Start: time.Unix(v.StartUTC, 0).UTC(),
79 })
80 }
81 return out, nil
82}
83