Choose the new scan's areas, list messages to you, find messages

In the message areas, for every front end (internal/app):

- Scan setup (S, PF11): which areas the new scan goes through, kept per
  user (scan_off: the areas left out; all are in until taken out).
- To you (T, PF4): the newest 100 messages addressed to the caller, in
  any case, in the areas they read, unread ones marked.
- Find (F, PF10): messages whose subject, text or author has the words,
  in any case, newest first; LIKE's wildcards are taken as text.

Reading what these found leaves the areas' last-read points as they
were.  A 3270's key line closes up when a screen has many actions.

Tested through internal/app and in the store on SQLite, PostgreSQL,
MySQL and MariaDB.  Message-Areas is the callers' wiki page for the
areas.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
This commit is contained in:
Claude committed 2026-10-12 14:26:54 +00:00
1 parent 094ad0561f
commit 05022e2a82
14 files changed
+477 -17

No files matched your search

+4 -1
View File
@@ -132,7 +132,10 @@ The full-screen editor: its text (wrapping as typed and as given, a word
too long for a line, joining lines by Backspace and Delete, moving over
line ends, quoting, the line limit), and an SSH caller writing a post
with the cursor keys, replying with lines from the quote window and
`/S`, then choosing the line editor; settings kept from call to call
`/S`, then choosing the line editor; the new scan's areas, messages to
you and finding (the scan kept, LIKE's wildcards taken as text, areas
not read left out), through internal/app and in the store on every
engine; settings kept from call to call
(UTF-8 off over SSH, a Commodore's width) and through the API.
The HTTP API: logins, tokens and scopes, every REST endpoint and its
refusals, rate limits, the OpenAPI document against the routes, server-sent
+2 -1
View File
@@ -51,7 +51,8 @@ The same caller on a 3270:
What there is:
- [message areas](Administration#message-areas): read new, list, read by number, post, reply (quoting
- [message areas](Message-Areas): a new scan of the areas you choose, messages to you, finding
messages by their words, read by number, post, reply (quoting
from a window in the [full-screen editor](Writing-Messages)),
reply by mail; areas only the sysop posts in; authors and the sysop
delete messages
+54
View File
@@ -0,0 +1,54 @@
What a caller does in the message areas, on any terminal: the letters
are a text terminal's, the PF keys a 3270's.
## The areas
```
Message areas
Area Description Msgs New
1 General Talk 42 * 3
2 Other More talk 17
Area number, [N]ew scan, [T]o you, [F]ind, [S]can setup, [Q]uit:
```
| | key | PF | |
|---|---|---|---|
| an area | its number | `S` by it | its messages, a page at a time |
| new scan | `N` | PF5 | reads the new messages of each area in the scan, area after area |
| to you | `T` | PF4 | the newest 100 messages addressed to you (in any case), in the areas you read; `*` those you have not read |
| find | `F` | PF10 | messages whose subject, text or author has the words in them (in any case, two characters or more), newest first, up to 100 |
| scan setup | `S` | PF11 | which areas the new scan goes through |
| add area | `+` | PF6 | the sysop only |
## Scan setup
Every area is in the new scan until it is taken out: the area's number
(or `S` by it on a 3270) switches it, `A` (PF5) puts all in, `X` (PF6)
takes all out. Areas marked `*` are in. The choice is kept with the
account.
## In an area
The messages a page at a time (Enter for more on a text terminal,
PF7/PF8 on a 3270); `*` marks those not read yet. A message's number
reads it, even one not on the page. `R` (PF5) reads from the first new
one, `P` (PF6) posts.
## Reading
| | key | PF |
|---|---|---|
| next | `N`, Enter, space | PF11, Enter |
| previous | `P` | PF10 |
| reply in the area | `R` | PF4 |
| reply by mail | `M` | PF5 |
| delete (yours, or any for the sysop) | `D` | PF9 |
| back | `Q` | PF3 |
Reading in an area marks it read up to there. Reading what *To you* or
*Find* found does not: the new scan still finds those messages new.
Writing: [Writing messages](Writing-Messages).
**See also:** [Administration](Administration#message-areas), [TN3270](TN3270)
+2 -2
View File
@@ -12,9 +12,9 @@ and the caller gets the 3270 screens:
| PF5 | new user (at the logon); new scan (the areas); read new (in an area); send (in the editor); reply by mail (in a message); change where you call from (the profile) |
| PF6 | post (in an area), new mail (in the mail), add an area (the sysop), your password (the profile) |
| PF7 / PF8 | up / down a page, or the message's text |
| PF4 | reply |
| PF4 | reply; messages to you (the areas) |
| PF9 | delete, remove |
| PF10 / PF11 | previous / next message |
| PF10 / PF11 | previous / next message; find messages / scan setup (the areas) |
The key line at the foot of each screen says which of these it takes.
The screens are the text BBS's (see [Development](Development#screens)):
+1
View File
@@ -18,6 +18,7 @@
- [Terminal identification](Terminal-Identification)
**Features**
- [Message areas](Message-Areas)
- [Writing messages](Writing-Messages)
- [Files and FTP](Files-and-FTP)
- [File transfers](File-Transfers)
+42
View File
@@ -202,6 +202,48 @@ func TestPostAndRead(t *testing.T) {
has(t, "screens", f.shown, "table General: alice|Hello|")
}
func TestScanToYouFind(t *testing.T) {
b, alice, sysop := setup(t)
other, _ := b.Store.CreateArea("Other", "More talk", false)
general, _ := b.Store.AreaByName("General")
for _, m := range []struct {
area int64
to, sub, body string
}{{general.ID, "alice", "For you", "hello there"}, {other.ID, "All", "Weather", "rain today"},
{other.ID, "Alice", "Also for you", "more rain"}} {
if _, err := sysop.Post(map[int64]*store.Area{general.ID: general, other.ID: other}[m.area],
m.to, m.sub, []string{m.body}, 0); err != nil {
t.Fatal(err)
}
}
f := run(t, b, alice,
"M",
// Other out of the scan: the new scan reads General's only
view.Choice{Action: "scan"}, view.Choice{Action: view.Pick, Row: 1}, view.Choice{Action: view.Back},
view.Choice{Action: "new"}, "next",
// to alice: both, newest first; the second read, then on past the end
view.Choice{Action: "toyou"}, view.Choice{Action: view.Pick, Row: 1}, "next", view.Choice{Action: view.Back},
// rain: the two in Other
view.Choice{Action: "find"}, map[string]string{"text": "RAIN"}, view.Choice{Action: view.Back},
view.Choice{Action: "find"}, map[string]string{"text": "x"},
view.Choice{Action: view.Back})
has(t, "screens", f.shown, "table Your new scan: General|Talk|yes; Other|More talk|yes")
has(t, "screens", f.shown, "table Your new scan: General|Talk|yes; Other|More talk|no")
has(t, "screens", f.shown, "message For you: hello there")
has(t, "screens", f.shown, "table Messages to you: Other|sysop|Also for you|")
has(t, "said", f.said, "That was the last.")
has(t, "screens", f.shown, "table Found: RAIN: Other|sysop|Also for you|")
has(t, "said", f.said, "Give two characters or more.")
for _, s := range f.shown {
if strings.Contains(s, "message Weather") {
t.Errorf("the new scan went into Other: %q", f.shown)
}
}
if off, _ := b.Store.ScanOff(alice.User().ID); !off[other.ID] {
t.Errorf("off %v", off)
}
}
func TestMailAndWho(t *testing.T) {
b, alice, sysop := setup(t)
f := run(t, b, alice,
+22 -3
View File
@@ -23,9 +23,12 @@ func (s *Session) areas() error {
Pick: "Area number",
Columns: []view.Column{{Title: "Area", Width: 20}, {Title: "Description", Width: 36, Wide: true},
{Title: "Msgs", Width: 5, Right: true}, {Title: "New", Width: 5, Right: true}},
Actions: []view.Action{{ID: "new", Label: "New scan", Key: 'N', PF: 5}}}
Actions: []view.Action{{ID: "new", Label: "New scan", Key: 'N', PF: 5, Short: "New"},
{ID: "toyou", Label: "To you", Key: 'T', PF: 4},
{ID: "find", Label: "Find", Key: 'F', PF: 10},
{ID: "scan", Label: "Scan setup", Key: 'S', PF: 11, Short: "Scan"}}}
if s.User.Sysop {
t.Actions = append(t.Actions, view.Action{ID: "add", Label: "add area", Key: '+', PF: 6, Short: "Add area"})
t.Actions = append(t.Actions, view.Action{ID: "add", Label: "add area", Key: '+', PF: 6, Short: "Add"})
}
for i, a := range areas {
nw := ""
@@ -42,10 +45,26 @@ func (s *Session) areas() error {
switch c.Action {
case view.Back:
return nil
case "toyou":
if err := s.toYou(areas); err != nil {
return err
}
case "find":
if err := s.find(areas); err != nil {
return err
}
case "scan":
if err := s.scanSetup(areas); err != nil {
return err
}
case "new":
off, err := s.B.Store.ScanOff(s.User.ID)
if err != nil {
return err
}
found := false
for _, a := range areas {
if a.New == 0 {
if a.New == 0 || off[a.ID] {
continue
}
found = true
+191
View File
@@ -0,0 +1,191 @@
package app
import (
"fmt"
"strconv"
"strings"
"github.com/Neo-Desktop/bbs-sec/internal/bbs"
"github.com/Neo-Desktop/bbs-sec/internal/store"
"github.com/Neo-Desktop/bbs-sec/internal/view"
)
// The new scan's areas, messages to the caller, and finding messages.
// most is how many messages a list of found ones holds.
const most = 100
// scanSetup: which areas the new scan goes through
func (s *Session) scanSetup(areas []bbs.AreaNew) error {
for {
s.N.Doing("New scan setup")
off, err := s.B.Store.ScanOff(s.User.ID)
if err != nil {
return err
}
t := &view.Table{Title: "Your new scan", Empty: "There are no message areas yet.",
Pick: "Area number to switch",
Note: []view.Line{view.T(view.Dim, "The new scan goes through the areas marked *.")},
Columns: []view.Column{{Title: "Area", Width: 20}, {Title: "Description", Width: 36, Wide: true},
{Title: "Scan", Width: 4}},
Actions: []view.Action{{ID: "all", Label: "All in", Key: 'A', PF: 5},
{ID: "none", Label: "None", Key: 'X', PF: 6}}}
for i, a := range areas {
in := map[bool]string{true: "yes", false: "no"}[!off[a.ID]]
t.Rows = append(t.Rows, view.Row{Num: strconv.Itoa(i + 1), Mark: !off[a.ID],
Cells: []string{a.Name, a.Description, in}})
}
c, err := s.UI.Table(t)
if err != nil {
return err
}
switch c.Action {
case view.Back:
return nil
case "all", "none":
for _, a := range areas {
if err := s.B.Store.SetScan(s.User.ID, a.ID, c.Action == "all"); err != nil {
return err
}
}
case view.Pick:
if c.Row < 0 {
s.UI.Say(view.Bad, "No such area.")
continue
}
a := areas[c.Row]
if err := s.B.Store.SetScan(s.User.ID, a.ID, off[a.ID]); err != nil {
return err
}
}
}
}
// byID are areas by their ids.
func byID(areas []bbs.AreaNew) map[int64]*store.Area {
out := map[int64]*store.Area{}
for _, a := range areas {
out[a.ID] = a.Area
}
return out
}
// toYou: the newest messages to the caller, in the areas they read
func (s *Session) toYou(areas []bbs.AreaNew) error {
s.N.Doing("Messages to them")
all, err := s.B.Store.MessagesTo(s.User.Name, most)
if err != nil {
return err
}
return s.found("Messages to you", "There are no messages to you.", all, byID(areas))
}
// find: messages with words in them
func (s *Session) find(areas []bbs.AreaNew) error {
v, ok, err := s.UI.Form(&view.Form{Title: "Find messages", Submit: "Find", Fields: []view.Field{
{Name: "text", Label: "Find", Prompt: "Find (in subjects, text and authors): ", Width: 40}}})
text := strings.TrimSpace(v["text"])
if err != nil || !ok || text == "" {
return err
}
if len([]rune(text)) < 2 {
s.UI.Say(view.Bad, "Give two characters or more.")
return nil
}
s.N.Doing("Finding messages")
ids := make([]int64, len(areas))
for i, a := range areas {
ids[i] = a.ID
}
ms, err := s.B.Store.SearchMessages(ids, text, most)
if err != nil {
return err
}
return s.found("Found: "+text, "Nothing has "+text+" in it.", ms, byID(areas))
}
// found lists messages found (in the areas the caller reads) to read.
func (s *Session) found(title, empty string, all []*store.Message, areas map[int64]*store.Area) error {
var ms []*store.Message
for _, m := range all {
if areas[m.AreaID] != nil {
ms = append(ms, m)
}
}
for {
t := &view.Table{Title: title, Empty: empty, Pick: "Number to read",
Columns: []view.Column{{Title: "Area", Width: 14}, {Title: "From", Width: 16},
{Title: "Subject", Width: 30}, {Title: "Date", Width: 11, Wide: true}}}
last := map[int64]int64{}
for i, m := range ms {
l, ok := last[m.AreaID]
if !ok {
l, _ = s.B.Store.LastRead(s.User.ID, m.AreaID)
last[m.AreaID] = l
}
t.Rows = append(t.Rows, view.Row{Num: strconv.Itoa(i + 1), Mark: m.ID > l,
Cells: []string{areas[m.AreaID].Name, m.From, m.Subject, m.Created.Format("01-02 15:04")}})
}
c, err := s.UI.Table(t)
if err != nil || c.Action == view.Back {
return err
}
if c.Action != view.Pick {
continue
}
if c.Row < 0 {
s.UI.Say(view.Bad, "No such message here.")
continue
}
if err := s.browse(ms, c.Row, areas); err != nil {
return err
}
}
}
// browse reads messages found, from the i'th, in their order; where the
// caller has read up to in each area stays as it was.
func (s *Session) browse(ms []*store.Message, i int, areas map[int64]*store.Area) error {
for {
m := ms[i]
a := areas[m.AreaID]
s.N.Doing("Reading " + a.Name)
vm := message(m, fmt.Sprintf("%s #%d (%d of %d)", a.Name, m.ID, i+1, len(ms)))
vm.Actions = []view.Action{{ID: "next", Label: "Next", Key: 'N', PF: 11},
{ID: "prev", Label: "Previous", Key: 'P', PF: 10, Short: "Prev"}}
if s.B.CanPost(s.User, a) {
vm.Actions = append(vm.Actions, view.Action{ID: "reply", Label: "Reply", Key: 'R', PF: 4})
}
vm.Actions = append(vm.Actions, view.Action{ID: "mail", Label: "Mail reply", Key: 'M', PF: 5, Short: "Mail"})
act, err := s.UI.Message(vm)
if err != nil {
return err
}
switch act {
case view.Back:
return nil
case "next":
if i+1 >= len(ms) {
s.UI.Say(view.Plain, "That was the last.")
return nil
}
i++
case "prev":
if i == 0 {
s.UI.Say(view.Plain, "That is the first.")
continue
}
i--
case "reply":
if s.B.CanPost(s.User, a) {
if err := s.post(a, m.From, bbs.ReplySubject(m.Subject), bbs.Quote(m.From, m.Body, 8), m.ID); err != nil {
return err
}
}
case "mail":
if err := s.compose(m.From, bbs.ReplySubject(m.Subject), bbs.Quote(m.From, m.Body, 8), 0); err != nil {
return err
}
}
}
}
+2 -2
View File
@@ -37,7 +37,7 @@ func TestShared3270(t *testing.T) {
if err != nil {
t.Fatalf("s3270: %v\n%s", err, out)
}
for _, want := range []string{"Welcome, alice.", "Message areas", "General", "PF5=New scan",
for _, want := range []string{"Welcome, alice.", "Message areas", "General", "PF5=New", "PF10=Find",
"Posted as #1.", "Hello from a 3270", "A line of the body.", "PF4=Reply",
"Your profile", "Access:", "Terminal:", "PF5=Location"} {
if !strings.Contains(string(out), want) {
@@ -47,7 +47,7 @@ func TestShared3270(t *testing.T) {
d := login(e, "sysop", "sysoppass1")
d.send("M")
d.expect("Area number, [N]ew scan, [+] add area, [Q]uit: ")
d.expect("Area number, [N]ew scan, [T]o you, [F]ind, [S]can setup, [+] add area, [Q]uit: ")
d.send("1\r")
d.expect("Hello from a 3270")
d.expect("Number to read, [R]ead new, [P]ost, [Q]uit: ")
+1 -1
View File
@@ -8,7 +8,7 @@ import (
)
// copyOrder is the tables in an order their references allow.
var copyOrder = []string{"users", "areas", "messages", "lastread", "mail", "file_areas", "files",
var copyOrder = []string{"users", "areas", "messages", "lastread", "scan_off", "mail", "file_areas", "files",
"history", "peer_groups", "peer_push", "netmail_out", "api_tokens", "ssh_keys"}
var columnPat = regexp.MustCompile(`(?m)^\s*("?\w+"?)\s+(\{\w+\})`)
+80
View File
@@ -0,0 +1,80 @@
package store
import "strings"
// ScanOff are the areas a user has left out of their new scan.
func (s *Store) ScanOff(user int64) (map[int64]bool, error) {
rows, err := s.db.Query(`SELECT area_id FROM scan_off WHERE user_id = ?`, user)
if err != nil {
return nil, err
}
defer rows.Close()
out := map[int64]bool{}
for rows.Next() {
var id int64
if err := rows.Scan(&id); err != nil {
return nil, err
}
out[id] = true
}
return out, rows.Err()
}
// SetScan puts an area in a user's new scan, or leaves it out.
func (s *Store) SetScan(user, area int64, on bool) error {
if on {
_, err := s.db.Exec(`DELETE FROM scan_off WHERE user_id = ? AND area_id = ?`, user, area)
return err
}
_, err := s.db.Exec(`INSERT OR IGNORE INTO scan_off (user_id, area_id) VALUES (?, ?)`, user, area)
return err
}
func (s *Store) messageList(q string, args ...any) ([]*Message, error) {
rows, err := s.db.Query(q, args...)
if err != nil {
return nil, err
}
defer rows.Close()
var out []*Message
for rows.Next() {
m, err := scanMessage(rows)
if err != nil {
return nil, err
}
out = append(out, m)
}
return out, rows.Err()
}
// MessagesTo are the newest messages in the areas addressed to name (in
// any case), up to limit, newest first.
func (s *Store) MessagesTo(name string, limit int) ([]*Message, error) {
return s.messageList(`SELECT `+msgCols+` FROM messages WHERE LOWER(to_name) = LOWER(?)
ORDER BY id DESC LIMIT ?`, name, limit)
}
// likeEscape makes text a LIKE pattern that matches it anywhere.
func likeEscape(text string) string {
r := strings.NewReplacer("!", "!!", "%", "!%", "_", "!_")
return "%" + r.Replace(strings.ToLower(text)) + "%"
}
// SearchMessages are the newest messages of the areas whose subject,
// body or author has text in it (in any case), up to limit, newest first.
func (s *Store) SearchMessages(areas []int64, text string, limit int) ([]*Message, error) {
if len(areas) == 0 {
return nil, nil
}
args := []any{}
marks := make([]string, len(areas))
for i, a := range areas {
marks[i] = "?"
args = append(args, a)
}
p := likeEscape(text)
args = append(args, p, p, p, limit)
return s.messageList(`SELECT `+msgCols+` FROM messages WHERE area_id IN (`+strings.Join(marks, ", ")+`)
AND (LOWER(subject) LIKE ? ESCAPE '!' OR LOWER(body) LIKE ? ESCAPE '!' OR LOWER(from_name) LIKE ? ESCAPE '!')
ORDER BY id DESC LIMIT ?`, args...)
}
+5
View File
@@ -61,6 +61,11 @@ CREATE TABLE IF NOT EXISTS lastread (
message_id {int} NOT NULL,
PRIMARY KEY (user_id, area_id)
)`, `
CREATE TABLE IF NOT EXISTS scan_off (
user_id {int} NOT NULL REFERENCES users(id) ON DELETE CASCADE,
area_id {int} NOT NULL REFERENCES areas(id) ON DELETE CASCADE,
PRIMARY KEY (user_id, area_id)
)`, `
CREATE TABLE IF NOT EXISTS mail (
id {id},
from_id {int} NOT NULL,
+58
View File
@@ -276,3 +276,61 @@ func TestCopy(t *testing.T) {
t.Error("copied into a database with users")
}
}
func TestScanAndSearch(t *testing.T) {
s := open(t)
u, _ := s.CreateUser("alice", "password1", "", false)
a, _ := s.CreateArea("General", "", false)
b, _ := s.CreateArea("Other", "", false)
post := func(area int64, to, subject, body string) int64 {
id, err := s.Post(&Message{AreaID: area, FromID: u.ID, From: "bob", To: to, Subject: subject, Body: body})
if err != nil {
t.Fatal(err)
}
return id
}
post(a.ID, "Alice", "Hello", "about 100% of it")
post(b.ID, "All", "Weather", "rain_today and snow")
post(a.ID, "alice", "Again", "x")
if err := s.SetScan(u.ID, b.ID, false); err != nil {
t.Fatal(err)
}
s.SetScan(u.ID, b.ID, false) // twice is once
off, err := s.ScanOff(u.ID)
if err != nil || len(off) != 1 || !off[b.ID] {
t.Fatalf("off %v %v", off, err)
}
s.SetScan(u.ID, b.ID, true)
if off, _ := s.ScanOff(u.ID); len(off) != 0 {
t.Errorf("still off %v", off)
}
to, err := s.MessagesTo("ALICE", 10)
if err != nil || len(to) != 2 || to[0].Subject != "Again" {
t.Fatalf("to alice: %v %v", to, err)
}
find := func(areas []int64, text string) []string {
ms, err := s.SearchMessages(areas, text, 10)
if err != nil {
t.Fatal(err)
}
var out []string
for _, m := range ms {
out = append(out, m.Subject)
}
return out
}
for _, c := range []struct {
areas []int64
text string
want string
}{{[]int64{a.ID, b.ID}, "RAIN", "Weather"}, {[]int64{a.ID}, "rain", ""},
{[]int64{a.ID, b.ID}, "100%", "Hello"}, {[]int64{a.ID, b.ID}, "0%", "Hello"},
{[]int64{a.ID, b.ID}, "n_t", "Weather"}, {[]int64{a.ID, b.ID}, "n t", ""},
{[]int64{a.ID, b.ID}, "BOB", "Again Weather Hello"}, {nil, "x", ""}} {
if got := strings.Join(find(c.areas, c.text), " "); got != c.want {
t.Errorf("%q in %v: %q", c.text, c.areas, got)
}
}
}
+13 -7
View File
@@ -180,14 +180,20 @@ func (u *ui) Table(t *view.Table) (view.Choice, error) {
per -= 2
}
pick := t.Pick != ""
keys := []string{}
if pick {
keys = append(keys, "S+Enter=Select")
keyLine := func(sel, sep string) string {
keys := []string{}
if pick {
keys = append(keys, sel)
}
if k := pfKeys(t.Actions, sep); k != "" {
keys = append(keys, k)
}
return strings.Join(append(keys, "PF3=Back", "PF7/8=Page"), sep)
}
if k := pfKeys(t.Actions, " "); k != "" {
keys = append(keys, k)
keys := keyLine("S+Enter=Select", " ")
if len(keys) > u.cols-1 {
keys = keyLine("S=Select", " ") // many actions: closer
}
keys = append(keys, "PF3=Back", "PF7/8=Page")
numW := 0
mark := false
for _, r := range t.Rows {
@@ -205,7 +211,7 @@ func (u *ui) Table(t *view.Table) (view.Choice, error) {
top := 0
msg := ""
for {
scr := u.frame(t.Title, strings.Join(keys, " "), msg)
scr := u.frame(t.Title, keys, msg)
msg = ""
if t.Command != "" {
// the command line first: the cursor goes to it, where an