Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ See [`docs/versioning.md`](docs/versioning.md) for what the numbers mean and

## Unreleased

### Added

- `/about` says what maply is, how to play in Telegram and on the site, what
Google sign-in gives maply and where the panoramas come from, in all sixteen
languages, as plain HTML without a script. Google's brand review could not
read the home page, which is the Mini App, and refused the brand; `/about`
is the home page the sign-in screen names now.

### Changed

- The line that carries the DM keyboard ("Buttons below: play, today's result
and the menu") is deleted as soon as it is sent. The keyboard stays.

## v0.1.0-rc.1 - 2026-11-23

For the operator: no migrations. Pull the image from
Expand Down
1 change: 1 addition & 0 deletions cmd/maply-dev/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func mountAccounts(e *Env, mux *http.ServeMux) {
e.API.Accounts = svc
mux.Handle("/auth/", svc.Middleware(svc.Handler()))
mux.Handle("GET /privacy", svc.Privacy())
mux.Handle("GET /about", svc.About())
mux.HandleFunc("GET /dev/accounts/list", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
_, _ = w.Write([]byte(accountsList(r.Context(), e)))
Expand Down
1 change: 1 addition & 0 deletions cmd/maply/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func run(log *slog.Logger) error {
mux.Handle("/face/", game)
mux.Handle("/auth/", accounts.Middleware(accounts.Handler()))
mux.Handle("GET /privacy", accounts.Privacy())
mux.Handle("GET /about", accounts.About())
mux.Handle("/thumb/", game)
mux.Handle("/og/", game)
if cards != nil {
Expand Down
27 changes: 27 additions & 0 deletions internal/account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,30 @@ func TestARequestThatSignsForItselfIsNobodyOnTheSite(t *testing.T) {
}
}
}

// The about page is the home page Google's brand review reads: it names the
// app and the site, links the privacy page in its language and the owner's
// Telegram, and leaves no placeholder behind.
func TestAboutExplainsTheAppWithoutScript(t *testing.T) {
svc := New(Config{Key: []byte("k1"), AppURL: "https://maply.example.org/"})
for _, lang := range i18n.Codes() {
rec := httptest.NewRecorder()
svc.About().ServeHTTP(rec, httptest.NewRequest("GET", "/about?lang="+lang, nil))
body := rec.Body.String()
if rec.Code != http.StatusOK || !strings.Contains(body, "<h1>maply") {
t.Errorf("about in %s = %d without the app's name as its title", lang, rec.Code)
}
for _, want := range []string{
`<a href="https://t.me/amtiyo" dir="ltr">@amtiyo</a>`,
`<a href="/privacy?lang=` + lang + `">`,
"maply.example.org", "@maplyin_bot", "openid", `href="/about?lang=ar"`,
} {
if strings.Count(body, want) != 1 {
t.Errorf("about in %s has %q %d times, want once", lang, want, strings.Count(body, want))
}
}
if strings.Contains(body, "{site}") || strings.Contains(body, "{privacy}") || strings.Contains(body, "{contact}") || strings.Contains(body, "<script") || strings.Contains(body, "&lt;a") {
t.Errorf("about in %s leaves a placeholder, a script or an escaped link", lang)
}
}
}
59 changes: 39 additions & 20 deletions internal/account/privacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ nav a[aria-current] { color: var(--ink); }
</head>
<body>
<main>
<header><a class="mark" href="/">maply</a><a href="/">{{.Back}}</a></header>
<header><a class="mark" href="/">maply</a><a href="{{.BackHref}}">{{.Back}}</a></header>
<h1>{{.Title}}</h1>
<p>{{.Intro}}</p>
{{range .Sections}}<h2>{{.Head}}</h2>
<ul>{{range .Items}}<li>{{.}}</li>{{end}}</ul>
{{end}}
<nav aria-label="{{.Languages}}">{{range .Langs}}<a href="/privacy?lang={{.Code}}" hreflang="{{.Code}}" lang="{{.Code}}"{{if .Current}} aria-current="page"{{end}}>{{.Name}}</a>{{end}}</nav>
<nav aria-label="{{.Languages}}">{{range .Langs}}<a href="{{$.Path}}?lang={{.Code}}" hreflang="{{.Code}}" lang="{{.Code}}"{{if .Current}} aria-current="page"{{end}}>{{.Name}}</a>{{end}}</nav>
</main>
</body>
</html>
Expand Down Expand Up @@ -86,28 +86,47 @@ func (s *Service) siteHost(r *http.Request) string {
// Privacy serves /privacy in ?lang=, else the browser's first language maply
// speaks, else English.
func (s *Service) Privacy() http.Handler {
return s.textPage("/privacy", "acct.privacy.title", "acct.privacy.intro", "acct.privacy.back", "/",
"keep", "use", "google", "see", "not", "delete", "who")
}

// About serves /about the same way: what maply is and how to play, for
// whoever has no Telegram and no script, Google's brand review among them.
// It is the home page the sign-in screen names.
func (s *Service) About() http.Handler {
return s.textPage("/about", "acct.about.title", "acct.about.intro", "acct.about.back", "/",
"play", "account", "photos", "who")
}

// The links a line of a text page may carry: "{contact}" is the owner's
// Telegram, "{privacy}" the privacy page in the page's language.
func pageLine(lang, line string) template.HTML {
out := strings.ReplaceAll(template.HTMLEscapeString(line), "{contact}", privacyContact)
privacy := `<a href="/privacy?lang=` + lang + `">` + template.HTMLEscapeString(i18n.T(lang, "acct.privacy.title")) + `</a>`
return template.HTML(strings.ReplaceAll(out, "{privacy}", privacy))
}

// textPage serves one of the static pages: a title, an intro and sections
// whose keys are prefix+"."+name+"_h" for the head and prefix+"."+name for
// the lines, one item per line.
func (s *Service) textPage(path, titleKey, introKey, backKey, backHref string, sections ...string) http.Handler {
prefix := strings.TrimSuffix(titleKey, ".title")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
lang := privacyLangOf(r)
items := func(key string) []template.HTML {
var out []template.HTML
for _, line := range strings.Split(i18n.T(lang, key), "\n") {
out = append(out, template.HTML(strings.ReplaceAll(template.HTMLEscapeString(line), "{contact}", privacyContact)))
site := s.siteHost(r)
var secs []privacySection
for _, name := range sections {
var items []template.HTML
for _, line := range strings.Split(i18n.T(lang, prefix+"."+name, "site", site), "\n") {
items = append(items, pageLine(lang, line))
}
return out
secs = append(secs, privacySection{i18n.T(lang, prefix+"."+name+"_h"), items})
}
data := map[string]any{
"Lang": lang, "Dir": "ltr",
"Title": i18n.T(lang, "acct.privacy.title"), "Intro": i18n.T(lang, "acct.privacy.intro", "site", s.siteHost(r)),
"Back": i18n.T(lang, "acct.privacy.back"), "Languages": i18n.T(lang, "acct.privacy.languages"),
"Sections": []privacySection{
{i18n.T(lang, "acct.privacy.keep_h"), items("acct.privacy.keep")},
{i18n.T(lang, "acct.privacy.use_h"), items("acct.privacy.use")},
{i18n.T(lang, "acct.privacy.google_h"), items("acct.privacy.google")},
{i18n.T(lang, "acct.privacy.see_h"), items("acct.privacy.see")},
{i18n.T(lang, "acct.privacy.not_h"), items("acct.privacy.not")},
{i18n.T(lang, "acct.privacy.delete_h"), items("acct.privacy.delete")},
{i18n.T(lang, "acct.privacy.who_h"), items("acct.privacy.who")},
},
"Lang": lang, "Dir": "ltr", "Path": path, "BackHref": backHref,
"Title": i18n.T(lang, titleKey), "Intro": i18n.T(lang, introKey, "site", site),
"Back": i18n.T(lang, backKey), "Languages": i18n.T(lang, "acct.privacy.languages"),
"Sections": secs,
}
if lang == "ar" {
data["Dir"] = "rtl"
Expand All @@ -124,7 +143,7 @@ func (s *Service) Privacy() http.Handler {
data["Langs"] = langs
var buf bytes.Buffer
if err := privacyPage.Execute(&buf, data); err != nil {
s.log.Error("privacy page", "error", errClass(err))
s.log.Error("text page", "path", path, "error", errClass(err))
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
Expand Down
11 changes: 9 additions & 2 deletions internal/bot/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,21 @@ func (b *Bot) keyboard(lang string) telegram.Keyboard {
}

// sendKeyboard puts the keyboard under a DM's input field, in lang. Any
// other chat gets nothing.
// other chat gets nothing. Telegram sets a keyboard only with a message, and
// the keyboard outlives it: the message goes at once, so the chat keeps the
// buttons and no line that names them.
func (b *Bot) sendKeyboard(ctx context.Context, chat tg.Chat, lang string) error {
if chat.Type != "private" {
return nil
}
if _, err := b.tg.SendKeyboard(ctx, chat.ID, i18n.T(lang, "kb.ready"), b.keyboard(lang)); err != nil {
m, err := b.tg.SendKeyboard(ctx, chat.ID, i18n.T(lang, "kb.ready"), b.keyboard(lang))
if err != nil {
return fmt.Errorf("send keyboard to %d: %w", chat.ID, err)
}
if err := b.tg.DeleteMessage(ctx, chat.ID, m.MessageID); err != nil {
// The line stays in the chat; the keyboard works all the same.
b.log.Warn("keyboard message not deleted", "error", err)
}
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions internal/bot/keyboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func TestStartSendsTheKeyboardInDMsOnly(t *testing.T) {
if len(client.keyboards) != 1 || len(client.sends) != 1 {
t.Fatalf("keyboards = %d, sends = %d, want the keyboard and the panel", len(client.keyboards), len(client.sends))
}
// The line that carries the keyboard leaves the chat at once.
if len(client.deleted) != 1 || client.deleted[0] != 101 {
t.Fatalf("deleted = %v, want the keyboard's message", client.deleted)
}
k := client.keyboards[0]
if k.chatID != userID || k.text != i18n.T("ru", "kb.ready") || k.kb.Placeholder != i18n.T("ru", "kb.placeholder") {
t.Fatalf("keyboard = %+v", k)
Expand Down
Loading