diff --git a/lexicons/space/remanso/note.json b/lexicons/space/remanso/note.json index 5af3ee2..2ffc297 100644 --- a/lexicons/space/remanso/note.json +++ b/lexicons/space/remanso/note.json @@ -46,6 +46,10 @@ "type": "string", "description": "Display theme for the note.", "knownValues": ["light", "dark"] + }, + "listed": { + "type": "boolean", + "description": "Whether the note appears in public listings. Defaults to true." } } } diff --git a/src/data/db.ts b/src/data/db.ts index a55ece5..df622d1 100644 --- a/src/data/db.ts +++ b/src/data/db.ts @@ -22,10 +22,10 @@ type NoteRow = { export const getNotes = (cursor?: string, limit = 20) => { const notes = cursor ? db.prepare( - "SELECT did, rkey, title, publishedAt, createdAt FROM note WHERE rkey < ? ORDER BY rkey DESC LIMIT ?", + "SELECT did, rkey, title, publishedAt, createdAt FROM note WHERE listed = 1 AND rkey < ? ORDER BY rkey DESC LIMIT ?", ).all(cursor, limit) : db.prepare( - "SELECT did, rkey, title, publishedAt, createdAt FROM note ORDER BY rkey DESC LIMIT ?", + "SELECT did, rkey, title, publishedAt, createdAt FROM note WHERE listed = 1 ORDER BY rkey DESC LIMIT ?", ).all(limit); return { @@ -37,10 +37,10 @@ export const getNotes = (cursor?: string, limit = 20) => { export const getNotesByDid = (did: string, cursor?: string, limit = 20) => { const notes = cursor ? db.prepare( - "SELECT did, rkey, title, publishedAt, createdAt FROM note WHERE did = ? AND rkey < ? ORDER BY rkey DESC LIMIT ?", + "SELECT did, rkey, title, publishedAt, createdAt FROM note WHERE listed = 1 AND did = ? AND rkey < ? ORDER BY rkey DESC LIMIT ?", ).all(did, cursor, limit) : db.prepare( - "SELECT did, rkey, title, publishedAt, createdAt FROM note WHERE did = ? ORDER BY rkey DESC LIMIT ?", + "SELECT did, rkey, title, publishedAt, createdAt FROM note WHERE listed = 1 AND did = ? ORDER BY rkey DESC LIMIT ?", ).all(did, limit); return { @@ -107,18 +107,21 @@ export const upsertNote = (note: Note) => { publishedAt, createdAt, did, - rkey + rkey, + listed ) - VALUES (?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, ?) ON CONFLICT(did, rkey) DO UPDATE SET title = excluded.title, - publishedAt = excluded.publishedAt + publishedAt = excluded.publishedAt, + listed = excluded.listed `, note.title, note.publishedAt ? new Date(note.publishedAt).toISOString() : now, note.createdAt ? new Date(note.createdAt).toISOString() : now, note.did, note.rkey, + note.listed !== false ? 1 : 0, ); }; diff --git a/src/data/note.ts b/src/data/note.ts index 96ea80f..c9d80d6 100644 --- a/src/data/note.ts +++ b/src/data/note.ts @@ -4,4 +4,5 @@ export type Note = { title: string; publishedAt: string; createdAt: string; + listed?: boolean; }; diff --git a/src/migrations/init.ts b/src/migrations/init.ts index edd7c69..d0fc238 100644 --- a/src/migrations/init.ts +++ b/src/migrations/init.ts @@ -7,10 +7,19 @@ db.exec(` createdAt DATETIME NOT NULL, did TEXT NOT NULL, rkey TEXT NOT NULL, + listed INTEGER NOT NULL DEFAULT 1, PRIMARY KEY (did, rkey) ); `); +try { + db.exec( + `ALTER TABLE note ADD COLUMN listed INTEGER NOT NULL DEFAULT 1;`, + ); +} catch { + // Column already exists — no-op +} + db.exec(` CREATE TABLE IF NOT EXISTS state ( key TEXT PRIMARY KEY,