| 1 | -- Contact messages (lib/contact.ts): what people send through /contact to the instance's site |
| 2 | -- administrators. A message from someone who isn't signed in is unconfirmed until its address follows |
| 3 | -- the emailed link; a signed-in person's arrives confirmed. Confirmed messages are new until a site |
| 4 | -- administrator marks them handled or spam. Only site administrators can read them; the audit log keeps |
| 5 | -- every change. Unconfirmed messages are deleted after 7 days, spam after 30, handled after 365. |
| 6 | CREATE TABLE IF NOT EXISTS contact_messages ( |
| 7 | id TEXT PRIMARY KEY, |
| 8 | email TEXT NOT NULL COLLATE NOCASE, -- where to reply: the address typed, or a signed-in sender's own |
| 9 | name TEXT NOT NULL, |
| 10 | topic TEXT NOT NULL, -- one of a fixed list |
| 11 | message TEXT NOT NULL, |
| 12 | account_id TEXT, -- the sender, when signed in |
| 13 | sender_login TEXT, |
| 14 | state TEXT NOT NULL DEFAULT 'unconfirmed' CHECK (state IN ('unconfirmed', 'new', 'handled', 'spam')), |
| 15 | confirm_hash TEXT, -- SHA-256 of the emailed confirmation token, until it is used |
| 16 | confirm_expires_at TEXT, |
| 17 | confirmed_at TEXT, |
| 18 | note TEXT, -- the site administrators' latest note |
| 19 | updated_by TEXT, -- the site administrator's login who last changed it |
| 20 | handled_at TEXT, -- when it was marked handled or spam |
| 21 | created_at TEXT NOT NULL, |
| 22 | updated_at TEXT NOT NULL |
| 23 | ); |
| 24 | CREATE INDEX IF NOT EXISTS contact_messages_state ON contact_messages(state, created_at); |
| 25 | CREATE INDEX IF NOT EXISTS contact_messages_email ON contact_messages(email, state); |
| 26 | CREATE INDEX IF NOT EXISTS contact_messages_account ON contact_messages(account_id, created_at); |
| 27 | CREATE UNIQUE INDEX IF NOT EXISTS contact_messages_confirm ON contact_messages(confirm_hash); |
| 28 | |
| 29 | -- One row per form submission from someone who isn't signed in, for the daily limits only: hashes of |
| 30 | -- the sender's IP address and of the address typed, never either in the clear. Rows older than a day |
| 31 | -- are deleted. |
| 32 | CREATE TABLE IF NOT EXISTS contact_attempts ( |
| 33 | id TEXT PRIMARY KEY, |
| 34 | ip_hash TEXT NOT NULL, |
| 35 | email_hash TEXT NOT NULL, |
| 36 | emailed INTEGER NOT NULL DEFAULT 0, -- 1 when this submission sent an email |
| 37 | created_at TEXT NOT NULL |
| 38 | ); |
| 39 | CREATE INDEX IF NOT EXISTS contact_attempts_ip ON contact_attempts(ip_hash, created_at); |
| 40 | CREATE INDEX IF NOT EXISTS contact_attempts_email ON contact_attempts(email_hash, created_at); |
| 41 | CREATE INDEX IF NOT EXISTS contact_attempts_at ON contact_attempts(created_at); |