oficina / meet Public

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

Plain git — no account needed to clone.

Download

Download this file

1package calls
2
3// Team mode's answers: the retryable 503 for Unknown standing, in each of
4// the shapes Calls answers in, and the partial list's notice. None of it
5// is reached outside team mode.
6
7import (
8 "errors"
9 "net/http"
10 "strconv"
11 "time"
12
13 "amadan.net/oficina/home/roster"
14 "amadan.net/oficina/home/teammode"
15)
16
17// retryAfter is the roster's own retry interval, in whole seconds, as
18// every team-mode 503 says it.
19var retryAfter = strconv.Itoa(int(roster.RetryAfter / time.Second))
20
21// unavailableHeaders are every team-mode 503's: never cached, and when to
22// ask again.
23func unavailableHeaders(w http.ResponseWriter) {
24 w.Header().Set("Cache-Control", "no-store")
25 w.Header().Set("Retry-After", retryAfter)
26}
27
28// teamUnavailable is the retryable answer for Unknown standing to a page
29// or a form: the 503 page (with Try again for a GET) for a request that
30// asked for a page, plain text for anything else. A 404 would tell a
31// member their meeting is gone because Home was slow.
32func (a *app) teamUnavailable(w http.ResponseWriter, r *http.Request) {
33 unavailableHeaders(w)
34 a.errorPage(w, r, http.StatusServiceUnavailable, kindTeam, "")
35}
36
37// teamUnavailableJSON is the same answer to a script — the room's stream,
38// signal and ICE fetches, the native app — in their JSON shape. room.js
39// and callscore retry a 5xx with backoff; the body names nothing.
40func teamUnavailableJSON(w http.ResponseWriter) {
41 unavailableHeaders(w)
42 streamJSON(w, http.StatusServiceUnavailable, map[string]any{"error": "unavailable"})
43}
44
45// teamUnavailableAPI is the drive surface's.
46func teamUnavailableAPI(w http.ResponseWriter) {
47 unavailableHeaders(w)
48 apiJSON(w, http.StatusServiceUnavailable, map[string]any{"error": "unavailable"})
49}
50
51// isTeamUnavailable reports whether err is standing that cannot be
52// decided now (errTeamUnavailable, or the guard's ErrUnavailable).
53// Outside team mode no error is ever one.
54func isTeamUnavailable(err error) bool { return errors.Is(err, teammode.ErrUnavailable) }
55
56// requestPartial reports whether this request's own standing is Unknown
57// now, which is the partial-list rule (Paul, 2026-10-28, Home
58// implementation/teammode-package.md §4): the list asks it after it is
59// built, of the same Access it was built with — State latches, so a lease
60// that lapsed while listing marks the list partial. Without standing a
61// member reaches no meeting at all (Calls has no per-person shares of a
62// meeting: a guest's grant is for one call, and a guest has no list), so
63// a partial list is always empty, and the notice is what keeps it from
64// reading as "no meetings". NotMember is never partial: it never reaches
65// the list. Always false outside team mode.
66func (a *app) requestPartial(r *http.Request) bool {
67 t, ok := teamReqFrom(r.Context())
68 return a.team != nil && ok && t.access.Partial()
69}
70
71// The partial notice (Paul, 2026-10-28): what the meeting list says when
72// the roster could not be read within its lease.
73const (
74 partialTitle = "We couldn’t check your team access"
75 partialBody = "Your team’s meetings can’t be shown until it’s checked, so this list is not complete. Try again in a moment."
76)
77
78// guardRefused answers a write the guard refused, and reports whether it
79// did: standing lapsed between the route's gate and the commit, the same
80// retryable 503 as Unknown anywhere else, and the 404 for a definite "no"
81// (which one request's Access cannot reach once it has said Member, but
82// costs nothing to answer correctly). Outside team mode no error is ever
83// one of these.
84func (a *app) guardRefused(w http.ResponseWriter, r *http.Request, err error) bool {
85 switch {
86 case errors.Is(err, teammode.ErrUnavailable):
87 a.teamUnavailable(w, r)
88 case errors.Is(err, teammode.ErrNotMember):
89 a.notFound(w, r)
90 default:
91 return false
92 }
93 return true
94}
95