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// The shared chrome (estilo chrome, round 2): every page's bar, account
4// menu and <title> are built here, once, so no page can drift from
5// another. Before this the shell was rastrillo's topbar at 81px: a raw
6// address, a blue underlined "Settings" and a Sign out button that
7// wrapped under it, a separate one-item Help dropdown, no nav and no
8// current-page marker, and a <title> that named the app on one page out
9// of fifteen.
10//
11// Spec: estilo spec/shared-chrome, docs/superpowers/specs/
12// 2026-09-23-shared-chrome.md, §5 (bar), §6 (switcher), §8 (account),
13// §10 (titles). Calls adopts after Docs, Sheets and Slides.
14//
15// The call room keeps no bar: since 2026-09-28 a call is one window in
16// the viewport (room.html). Its title menu carries the same items, in
17// the same order and words, as the account menu built here (roomMenu).
18
19import (
20 "net/http"
21 "net/url"
22
23 "amadan.net/oficina/estilo.git/chrome"
24 estilomenu "amadan.net/oficina/estilo.git/menu"
25 "amadan.net/rastrillo/rastrillo/sessions"
26)
27
28// appName is the brand and the last part of every <title>.
29const appName = "Calls"
30
31// Frame is what layout.html reads from every page: the bar, the parts of
32// the <title> before the app's name, and the Appearance preference for
33// <html data-theme>.
34type Frame struct {
35 Chrome chrome.Bar
36 TitleParts []string
37 // WholeTitle, when set, is the whole <title>, in place of TitleParts
38 // and the app's name: the sign-in door's is rastrillo's for its state
39 // ("Sign in to Calls"), which names the app itself (signin.go).
40 WholeTitle string
41 Theme string
42}
43
44// frame describes one page's chrome. The zero value is a page whose
45// <title> is just "Calls" (the meeting list, the app root).
46type frame struct {
47 // parts precede "Calls" in <title>, most specific first. The first
48 // is the page's h1 (spec §10).
49 parts []string
50 // title, when set, is the whole <title> (Frame.WholeTitle).
51 title string
52 // context is the open meeting's title, shown in the bar.
53 context string
54 // signinPage is one of the sign-in, sent and signed-out pages, or a
55 // native app hand-off page: the corner is empty and the brand is
56 // plain text, since everything it could link to is behind the session
57 // gate (and a hand-off page keeps no-referrer, which a chained
58 // sign-out could not pass through).
59 signinPage bool
60 // public is a page reached through a capability (the invitation
61 // link /j/{token}): "Sign in" carries no return path, because the
62 // path is the capability and must not be copied into another URL.
63 public bool
64}
65
66// titled is the frame for a page whose <title> is these parts.
67func titled(parts ...string) frame { return frame{parts: parts} }
68
69// onMeeting is the frame for one of a meeting's pages: the meeting's
70// title is the bar's context, and it follows page in the <title>. With
71// page empty the meeting is the page (the holding screen, the room).
72func onMeeting(page, meeting string) frame {
73 if page == "" {
74 return frame{parts: []string{meeting}, context: meeting}
75 }
76 return frame{parts: []string{page, meeting}, context: meeting}
77}
78
79// viewer is who the chrome is for: nobody, a guest, or a signed-in
80// person, and how they signed in.
81type viewer struct {
82 person Person
83 method string
84 ok bool
85}
86
87// signedIn is a person who signed in, as opposed to a per-meeting guest.
88func (v viewer) signedIn() bool { return v.ok && !v.person.Anonymous }
89
90// viewerOf resolves whoever the request is for without requiring
91// anybody. Behind requireParticipant that is the person already in the
92// context. Anywhere else (an error page, Open source, the invitation
93// page) the session is read optionally and without side effects: an
94// error page must never create a persons row or end a session, so a
95// session that no longer resolves is simply signed out here, and the
96// next guarded page is where it is dealt with.
97func (a *app) viewerOf(r *http.Request) viewer {
98 if p, ok := currentPerson(r); ok {
99 s, _ := sessions.Current(r)
100 return viewer{person: p, method: s.Method, ok: true}
101 }
102 id, ok := a.auth.SessionFrom(r)
103 if !ok {
104 return viewer{}
105 }
106 p, err := a.lookupPerson(r, sessions.Session{Subject: id.Address, Method: string(id.Method)})
107 if err != nil {
108 return viewer{}
109 }
110 return viewer{person: p, method: string(id.Method), ok: true}
111}
112
113// lookupPerson is personForSession without its one write: a first
114// sign-in's persons row is created by the guarded pages, never by chrome.
115func (a *app) lookupPerson(r *http.Request, s sessions.Session) (Person, error) {
116 switch s.Method {
117 case "magiclink", "keymail":
118 return a.store.existingHomePerson(r.Context(), s.Subject)
119 }
120 return a.personForSession(r.Context(), s)
121}
122
123// page builds render's data for a page: data plus "Frame", the chrome,
124// and "Viewer", which the room's own menu reads.
125func (a *app) page(r *http.Request, f frame, data map[string]any) map[string]any {
126 if data == nil {
127 data = map[string]any{}
128 }
129 var v viewer
130 if !f.signinPage {
131 v = a.viewerOf(r)
132 }
133 if v.signedIn() {
134 data["Viewer"] = Viewer{Email: v.person.shown(), Member: a.memberNow(r.Context(), v.person)}
135 }
136 data["Frame"] = a.frameFor(r, v, f)
137 return data
138}
139
140// Viewer is the signed-in person, for the room's title menu: who they
141// are, and whether the team's pages (Meetings, Settings) are theirs.
142type Viewer struct {
143 Email string
144 Member bool
145}
146
147// frameFor builds a page's Frame for viewer v.
148func (a *app) frameFor(r *http.Request, v viewer, f frame) Frame {
149 bar := chrome.Bar{
150 App: chrome.App{
151 Name: appName,
152 Slug: "calls",
153 Home: "/",
154 Icon: assets.Path("static/brand/icon.svg"),
155 },
156 Context: f.context,
157 Labels: chrome.BarLabels{Skip: "Skip to content", Menu: "Menu"},
158 }
159 switch {
160 case f.signinPage:
161 bar.App.Home = ""
162 case v.signedIn():
163 bar.Account = a.account(r, v)
164 bar.Switcher = a.switcher()
165 if a.memberNow(r.Context(), v.person) {
166 bar.Nav = a.nav(r)
167 bar.NavLabel = "Calls"
168 }
169 case f.public:
170 // A guest, or nobody, on the invitation page.
171 bar.App.Home = ""
172 bar.SignIn = &chrome.Link{Href: signinPath, Label: "Sign in"}
173 default:
174 // Nobody, or a guest (spec §8.4: guests get the same corner).
175 bar.SignIn = &chrome.Link{Href: signinPath + "?return_to=" + url.QueryEscape(returnTarget(r)), Label: "Sign in"}
176 }
177 return Frame{
178 Chrome: bar,
179 TitleParts: f.parts,
180 WholeTitle: f.title,
181 Theme: chrome.ThemeAttr(chrome.Appearance(r)),
182 }
183}
184
185// nav is the team's two pages, with the one being shown marked.
186func (a *app) nav(r *http.Request) []chrome.Link {
187 return []chrome.Link{
188 {Href: "/", Label: "Meetings", Current: r.URL.Path == "/"},
189 {Href: "/settings", Label: "Settings", Current: r.URL.Path == "/settings"},
190 }
191}
192
193// returnTarget is where a person should come back to: this page, if it
194// is a page (a GET), otherwise the meeting list.
195func returnTarget(r *http.Request) string {
196 if r.Method != http.MethodGet && r.Method != http.MethodHead {
197 return "/"
198 }
199 return r.URL.RequestURI()
200}
201
202// account is the account menu (spec §8.2): who is signed in, "Connect
203// your Oficina account" when that means something, Appearance, Help
204// (Open source, last), and the one Sign out in the app. Settings is in
205// the bar's nav rather than here: it is the team's meeting defaults and
206// agents, not this person's account, and a second copy of the link would
207// be a second label to keep in step.
208func (a *app) account(r *http.Request, v viewer) *chrome.Account {
209 acc := &chrome.Account{
210 TriggerLabel: "Account: " + v.person.shown(),
211 Initials: chrome.Initials("", v.person.shown()),
212 Address: v.person.shown(),
213 Labels: chrome.AccountLabels{SignedInAs: "Signed in as", Appearance: "Appearance", Help: "Help"},
214 Appearance: &chrome.AppearanceMenu{
215 Action: "/appearance",
216 Return: returnTarget(r),
217 Options: chrome.AppearanceOptions(chrome.Appearance(r), "Light", "Dark", "System"),
218 },
219 Help: []estilomenu.Item{{Href: "/help/open-source", Label: "Open source"}},
220 SignOut: chrome.SignOut{Action: "/signout", Label: "Sign out"},
221 }
222 if a.offersHomeLink(r, v) {
223 acc.Items = []estilomenu.Item{{Href: "/account/home", Label: "Connect your Oficina account"}}
224 }
225 return acc
226}
227
228// offersHomeLink is whether the account menu offers to connect the
229// person's Oficina account: only with Home configured, only to a member
230// (the page is behind requireMember), never to somebody who signed in
231// through Home, whose account already is the connection, and never once
232// the account has a stored link, however this session signed in (an
233// emailed link still signs in a linked account). The link lookup is one
234// query on the UNIQUE (issuer, person_id) index; an error offers nothing.
235func (a *app) offersHomeLink(r *http.Request, v viewer) bool {
236 if a.team != nil {
237 // Team mode: the link page is the local door's admitted, unlinked
238 // accounts' (team_access.go's linkable).
239 t, ok := teamReqFrom(r.Context())
240 return ok && t.person.ID == v.person.ID && a.linkable(t)
241 }
242 if a.home == nil || !v.signedIn() || !a.isMember(v.person) || (v.method != "magiclink" && v.method != "keymail") {
243 return false
244 }
245 linked, err := a.home.bridge.Linked(r.Context(), v.person.ID)
246 return err == nil && !linked
247}
248
249// switcher is the app switcher, or nil when no hub directory is
250// configured: the suite's six apps as tiles, each at its own host under
251// the directory's (estilo's chrome.SuiteApps), with Calls marked current,
252// then "All apps".
253func (a *app) switcher() *chrome.Switcher {
254 if a.cfg.home == nil || a.cfg.home.Directory == "" {
255 return nil
256 }
257 return &chrome.Switcher{
258 Label: "Oficina apps",
259 CurrentLabel: "(this app)",
260 Apps: chrome.SuiteApps(a.cfg.home.Directory, "calls"),
261 AllApps: estilomenu.Item{Href: a.cfg.home.Directory + "/", Label: "All apps"},
262 }
263}
264
265// roomMenu is the call window's title menu: the account menu's items in
266// its order and its words, for a page that has no bar. Standing is the
267// one line only the room has.
268type roomMenu struct {
269 Identity string
270 Nav []chrome.Link
271 Help []estilomenu.Item
272 SignOut *chrome.SignOut
273}
274
275func (a *app) roomMenuFor(fr Frame) roomMenu {
276 m := roomMenu{Nav: fr.Chrome.Nav}
277 if acc := fr.Chrome.Account; acc != nil {
278 m.Identity = acc.Address
279 m.Help = acc.Help
280 m.SignOut = &acc.SignOut
281 } else {
282 m.Help = []estilomenu.Item{{Href: "/help/open-source", Label: "Open source"}}
283 }
284 return m
285}
286