Common Room schema
A Common Room is an optional shared desk beside one conversation. Members put notes, links, images, files and folders on it, move them around, and send things to a Lost & Found that never destroys anything. The author of an item can always take it home, which deletes it for real.
This page describes the database half of phase CR-1: migrations 20261029100000 to 20261029100600 (tables, switch,
policies, triggers, reports, functions, storage) and 20261029110000 (admin file access for moderation). They were applied
to the live database on 2026-10-29. CR-1 has no live sync, no windows, no ink and no presence: the room loads when it is
opened and when someone presses refresh. The front-end half is described under Front-end structure.
Every Common Room table starts with common_room_ (in this codebase "room" alone means a member's HomeRoom).
The switch
The Common Room ships behind a server-side switch, the same way Porch Light does. private.app_settings key common_room:
| Value | Who can use the Common Room |
|---|---|
absent or admins | Admins only (people with a row in admin_roles) |
on | Every member |
off, or anything else | Nobody |
The switch is enforced in the database: a restrictive policy on every table and on the storage bucket, and a check at the
start of every function. Two things work whatever the switch says, on purpose: taking your own things home (take_item_home
and deleting your own now-unused file), and an admin's moderation of a reported item (below). The browser asks
public.common_room_is_open() (yes or no, about the signed-in person only) to decide whether to show the feature at all; the
front end also needs the Artiol ID sign-in mode.
No migration inserts a switch row, so the Common Room starts open to admins only. To open it for everyone (the owner, in the Supabase SQL Editor):
insert into private.app_settings (key, value) values ('common_room', 'on')
on conflict (key) do update set value = excluded.value, updated_at = now();
Set the value to admins (or delete the row) to go back to admins only, or off to close it for everyone, administrators
included. Closing it never traps anyone's things: authors can still take them home.
Tables
common_room_config
The tunable limits, edited by the owner in the SQL Editor. Members can read them.
| Key | Default | Meaning |
|---|---|---|
max_active_desk_items | 200 | Active items allowed on one desk (a performance guard; folders and the Lost & Found do not count) |
room_quota_bytes | 524288000 (500 MB) | Total file bytes one room may hold, Lost & Found included |
max_file_bytes | 26214400 (25 MB) | Largest single file |
report_hold_threshold | 2 | Distinct members whose open reports hold an item for everyone |
common_rooms
One row per conversation that has a room (conversation_id is unique; the room is deleted with the conversation).
| Column | Notes |
|---|---|
status | active or archived (archiving arrives in CR-5) |
layout_mode | grid or freeform (freeform arrives in CR-2) |
background | {"type":"color","value":"default"}; CR-1 accepts colours only |
opened_by | Who opened it (set null if that account is deleted) |
storage_bytes | The room's quota meter, kept by triggers |
common_room_items
Everything on the desk, in folders or in the Lost & Found.
| Column | Notes |
|---|---|
kind | image, note, link, file, folder in CR-1 (window and voice are reserved for CR-2) |
created_by | The author. Deleted with the author's account |
name, alt_text | Up to 80 and 500 characters |
location | desk, folder (with parent_id) or lost_found |
prev_location | Where it was before the Lost & Found: {location, parent_id, x, y, grid_col, grid_row} |
grid_col, grid_row | The grid cell (0 to 9999), or null when the client should find a free cell |
x, y, w, h, z, rotation | Freeform geometry, kept separately so mode switches lose nothing |
data | Note text, link URL and similar, a JSON object up to 32 KB |
storage_path, file_bytes | For images and files. The size comes from Storage, never from the browser |
status | active, held (reported; only the author sees it) or removed (by a moderator; nobody sees it) |
lost_found_by, lost_found_at | Who moved it to the Lost & Found and when (members see this, for repair) |
version | Goes up with every edit, for the "someone else just changed this" check |
common_room_viewer_prefs
One row per person per room, readable and writable only by that person: hidden (chat only), calm_view, tidy_view,
list_view, seen_explainer, hidden_item_ids (items they reported, hidden for them at once), last_visit_at (their
own timestamp, never shown to anyone) and the ink and presence settings later phases use.
common_room_events
The repair log: opened, tidied, sent_to_lost_found, restored, taken_home (and later archive, layout and ink
actions). Ordinary moves and edits are never logged, so the log is not a record of who did what on the desk. Members read
it; an entry by someone in a block with the reader is not shown.
common_room_item_history (CR-H1, migrations 20261105100000 to 20261105100200)
Where each item was, for Look back (spec docs/specs/2026-11-05-common-room-look-back-and-time-view.md, Owner Decision
OD-009). One row per change to an item's place, holding its state after the change. Layout only: no name, text, data,
file or ink is ever kept, so a rewound desk shows every item as it is now at its old place and size.
| Column | Notes |
|---|---|
room_id | Deleted with the room (history lives as long as the room) |
item_id | No foreign key: a row outlives its item. The read function leaves out items that are gone anyway |
actor_id | Who made the change; set null when that account is deleted (the row stays, with no name), and null for changes no signed-in person made (cascades, the SQL Editor) |
changed_at | The server's time |
location | desk, folder, lost_found or gone (deleted) |
parent_id, grid_col, grid_row, w, h | The folder, the cell and a picture's size |
- Written only by a trigger on
common_room_items(after insert; after an update oflocation,parent_id,grid_col,grid_row,worhwhen one of them actually changed; after delete). A name, text, description, status or version change writes nothing. A deletion inside a room's own deletion writes nothing (the room's rows go with it). - Coalescing: when the item's latest row is by the same person and under 5 seconds old, that row is updated instead of a new one added, so arrow-key nudges and resize steps make one row. Anyone else's change in between starts a new row; changes with no person are never coalesced.
- No client role (anon, authenticated, the service role) can read or write it directly; it has the three restrictive
policies and no permissive one. It is read only through
common_room_desk_at. - Backfill: when the migration ran, every existing item got one row at its current place, stamped with its
created_atand its author. Before that moment a room's history is "as it is now". - Indexes
(room_id, changed_at),(item_id, changed_at)andactor_id.
No Common Room table stores a count of visits, views or reads.
Who can see and do what (row-level security)
Every table has row-level security and three restrictive policies: kernel_first_party_only, commonplace_members_only
and common_room_open (the switch).
- Rooms: active participants of the conversation read the room. Nobody writes it directly.
- Items: members read active items whose author is not in a block with them, in either direction. Authors also read
their own held items. Removed items are visible to nobody. Members may insert their own items into an editable room
(conversation
openorresting). There is no update or delete policy: every change goes through a function. - Viewer prefs: the owner only.
- Events: members read; only the functions write.
- Limits: members read.
- Layout history: nobody directly; members read it only through
common_room_desk_at. - Signed-out visitors have no access to anything.
Functions
All are SECURITY DEFINER with an empty search_path. Because they bypass row-level security, each one checks the switch,
membership, editability and blocks itself. Signed-out callers are refused.
| Function | Who | What it does |
|---|---|---|
open_common_room(p_conversation uuid) returns uuid | Any active participant | Creates the room (conversation open or resting) and posts one chat line, "Name opened the Common Room." Calling it again returns the same room with no side effects |
common_room_move_items(p_moves jsonb) returns void | Members | Moves items between cells and in or out of folders. p_moves is [{id, location: 'desk' or 'folder', parent_id, grid_col, grid_row, x, y, z}]. Not logged |
common_room_update_item(p_id uuid, p_name text, p_data jsonb, p_alt_text text, p_expected_version int) returns int | Members | Edits name, description and data if the version still matches; returns the new version. Null leaves a field alone; an empty name clears it. Images and files keep their data. Links must be http:// or https://. An item in the Lost & Found cannot be edited (restore it first) |
common_room_resize_item(p_id uuid, p_w numeric, p_h numeric) returns void | Members | Sets a picture's own width and height on the desk (or in a folder), rounded to whole pixels; each 48 to 624. Images only for now. The last write wins, like a move; not a content edit, so the version does not change, and not logged. Errors: not_permitted (not an image, in the Lost & Found, held, removed, blocked, unknown, or the caller is not in the room), not_editable, common_room_closed, invalid_input (a size missing, NaN, or outside 48 to 624). Migration 20261030100000 |
send_to_lost_found(p_item_ids uuid[]) returns void | Members | Moves items to the Lost & Found, remembering where they were. A folder's contents travel with it |
restore_from_lost_found(p_item_ids uuid[]) returns void | Members | Puts items back exactly where they were; if their folder is gone, onto the desk with no cell |
take_item_home(p_item_id uuid) returns text[] | The author only, in any room or conversation state, even after leaving, and whatever the switch says | Deletes the item for good and returns its storage path(s) so the app can delete the file. A folder's contents are moved to the desk first (or the Lost & Found if the desk is full) |
common_room_tidy(p_room uuid, p_columns int) returns void | Members | Reassigns grid cells in reading order |
common_room_set_background(p_room uuid, p_background jsonb) returns void | Members | {"type":"color","value":"#336699"} or a theme token such as "sage" |
common_room_moderate_item(p_item uuid, p_action text) returns void | Admins with resolve_reports | restore (held to active) or remove (gone for everyone, Lost & Found included) |
common_room_is_open() returns boolean | Signed-in people | Whether the switch lets this person in |
common_room_desk_at(p_room uuid, p_at timestamptz) returns table (item_id, location, parent_id, grid_col, grid_row, w, h) | Members | Look back (CR-H1, migration 20261105100200): the desk's layout at a moment. For each item that exists now, its latest history row at or before p_at that puts it on the desk or in a folder. Leaves out, on the server: items held or removed (for their author too), items made by or placed there by someone in a block with the caller, items in the caller's hidden_item_ids, and an item in a folder unless that folder is on the desk at that moment. A moment in the future answers as now. Stable; changes nothing. Errors: common_room_closed, not_permitted, invalid_input (no moment) |
common_room_orphan_files(p_limit int default 500) returns setof text | Service role only | Lists storage paths that no live item names (see The orphan list); 1 to 1000 per call |
admin_get_reported_common_room_item(p_item uuid) returns jsonb | Admins with view_reports | What the admin report queue shows for a reported item (see What an admin can reach) |
Adding items is a plain insert into common_room_items (columns id, room_id, created_by, kind, name, location, parent_id, x, y, grid_col, grid_row, z, rotation, data, storage_path, alt_text). A trigger checks everything.
Error codes
Errors carry the code as both the message and the hint, for the app's error map.
| Code | When |
|---|---|
common_room_closed | The switch is off for this person, or they are signed out (never raised by take_item_home) |
not_permitted | Not a participant, not the author (take home), an item that is held, removed, blocked or in another room, an item in the Lost & Found where that is not allowed, a batch that is empty, repeats an id, has over 500 ids or spans rooms, a kind CR-1 does not take (window, voice), a file that is not the caller's upload or not at {room}/{item}/{name}, or a non-admin calling common_room_moderate_item |
not_editable | The conversation is paused or closed, or the room is archived |
conversation_not_open | Opening a room in a conversation that is not open or resting |
desk_full | The desk already holds max_active_desk_items active items |
room_quota_exceeded | The file would take the room over room_quota_bytes |
file_too_large | The file is over max_file_bytes |
invalid_folder | The folder is not an active desk folder in this room, belongs to someone in a block with the caller, or a folder would go inside a folder |
version_conflict | Someone else changed the item since it was loaded |
invalid_link | A link that is not http:// or https:// (for example javascript:) |
invalid_background | Anything but a colour in CR-1 |
invalid_input | A name over 80 or description over 500 characters, a column count outside 1 to 200, a picture size that is missing, NaN or outside 48 to 624 (common_room_resize_item), or no moment given to common_room_desk_at |
Triggers
- New items (before insert): the access checks above, the CR-1 kinds, link schemes, folder placement, the desk cap, the file's real size from Storage, and the quota, under a lock on the room so two uploads cannot both squeeze in.
- Deleted items: the room's
storage_bytesgoes down. When a folder is deleted with its author's account, other people's things inside it move to the desk (or the Lost & Found), so nobody loses their things with someone else's folder. - Layout history (CR-H1): after an item is added, moved, resized or deleted, its new place goes into
common_room_item_history(see that table). - New room: the one chat system line.
- Reports: see below.
Reports and holds
reports.reported_type accepts common_room_item and common_room_ink_layer (ink arrives in CR-3), alongside every type
it already allowed.
- A member reports an item (through
submit_reportor the reports table). Only active participants of that room can report its items, and not a removed item. The report records the author asreported_user_id. An outsider's report is refused with the hintnot_allowed. - The item is added to the reporter's
hidden_item_idsstraight away: it is hidden for them. - When
report_hold_threshold(2) different members other than the author have open reports on it (statuspending,reviewingorescalated), the item becomesheld: invisible to everyone except its author, who can still take it home. Restoring a held item (step 4) does not close its reports, so any further report holds it again at once until an admin resolves the earlier ones in the report queue. - An admin decides with
common_room_moderate_item:restoreorremove. Both are written to the admin audit log. Removed items disappear from the desk, folders and the Lost & Found; their bytes stop counting. The admin report panel then deletes the file with the admin's own session; if that fails it says so, and the file stays in the private bucket (no sweeper exists yet).
What an admin can reach (CR-1h, migration 20261029110000)
No privileged key is used anywhere: an admin moderates with their own sign-in.
| What | Who | When |
|---|---|---|
admin_get_reported_common_room_item(p_item uuid) returns jsonb | Admins with view_reports | Only while a common_room_item report names the item. Returns kind, name, description, note text, link address, file path, status, place, room and conversation id, and the author's name; null once the author took it home |
| Read a room file (signed URL) | Admins with view_reports | Only while a report names the item that uses the file (any status, so a removed item's file can still be deleted) |
| Delete a room file | Admins with resolve_reports | Only once common_room_moderate_item has removed the item that names it |
The switch never blocks these (the restrictive common_room_open_read and common_room_open_delete policies let them
through, as they do taking your own things home). Members and outsiders gain nothing from them.
Files
Bucket common-room-files: private, 25 MB per file, image/jpeg, image/png, image/webp, image/gif,
application/pdf, text/plain, audio/webm, audio/mp4, audio/mpeg. Files are served only through short-lived
signed URLs.
Path: {room_id}/{item_id}/{filename}, where the filename uses lowercase letters, digits, dots and dashes (up to 80).
| Action | Who |
|---|---|
| Upload | A participant of an editable room, at a well-formed path |
| Read | Members who can see an item that names the file; the uploader always (unless a moderator removed its item); an admin only while a report names its item |
| Delete | The uploader, and only once no item names the file (after taking it home, or when the item insert failed), whatever the switch says; an admin only once moderation removed its item |
| Replace | Nobody |
The bucket is part of the members-only storage rule and has its own switch policies (one per command); the uploader's own no-longer-used file can still be read and deleted with the switch off.
What happens to your files
- The app's upload helper (CR-1c, front end) re-encodes JPEG, PNG and WebP images before upload, which removes EXIF and location data. GIFs, PDFs and text files are uploaded as they are; PDF metadata is not stripped.
- Taking an item home deletes the database row immediately; the app then deletes the file.
- A sweeper that deletes files nobody names any more is not built (see below). Until it is, a file the app could not delete stays in the private bucket: readable by nobody, except that its uploader can still delete it (taken-home files) and an admin can delete a moderator-removed item's file.
Storage policies on storage.objects
| Policy | Kind | Rule |
|---|---|---|
Common room files: members read | permissive select | The file is named by an active item the caller can see (not blocked), or the caller uploaded it; never a removed item's file |
Common room files: members upload | permissive insert | A well-formed path into an editable room the caller can access |
Common room files: uploaders remove unused files | permissive delete | The uploader, once no item names the file |
Common room files: admins read reported files | permissive select | An admin with view_reports, only while a common_room_item report names the item |
Common room files: admins remove removed files | permissive delete | An admin with resolve_reports, only once the item is removed |
common_room_open_read, _insert, _update, _delete | restrictive, one per command | The switch for this bucket. Read and delete also pass for the uploader's unused file and for the admin cases above; insert and update need the switch |
commonplace_members_only | restrictive, all | Rebuilt from its live bucket list plus common-room-files (the migration stops with an error rather than guess if it cannot read that list) |
The orphan list, and the sweeper that is not built
public.common_room_orphan_files(p_limit) (service role only) returns the paths in common-room-files that are more than 24
hours old and that no live item names, including files of items a moderator removed. It returns paths only. It exists so a
sweeper can delete those objects, because SQL cannot delete Storage objects.
The sweeper is not built. The prompts called for an Edge Function (sweep-room-orphans) and another for moderation
(remove-room-content). Both would need the privileged service key, which the owner's standing rule forbids in app code,
scripts and Edge Functions, so neither exists and no schedule was added. The app deletes a taken-home file itself, and an
admin deletes a removed item's file themselves under the narrow policies above. Everything else (a failed cleanup, an
abandoned upload) waits in the private bucket, readable by nobody. Until a sweeper exists, the owner can read the list from the
SQL Editor now and then.
Front-end structure
All Common Room code is in src/features/common-room/ (about 70 files, each under 300 lines); the page is lazy-loaded at the
route /messages/:conversationId/room in src/App.jsx. Nothing in the folder opens a realtime channel, polls or sets a timer
(a test checks).
| Area | Files |
|---|---|
| Server calls | common-room-api.js (every call, one frozen object), common-room-errors.js (error codes to plain sentences), common-room-files.js and common-room-upload.js (prepare, upload, clean up), room-file-urls.js and room-download.js (signed links) |
| Data hooks | useCommonRoomOpen.js (the switch), useCommonRoom.js (room and conversation state), useRoomItems.js (items, optimistic changes), useViewerPrefs.js, useRoomEntry.js, useRoomConversationIds.js, useRoomSafety.js |
| Entry from messaging | RoomEntry.jsx (glyph, Chat or Room toggle, menu item), RoomExplainer.jsx |
| Room page | CommonRoomView.jsx, RoomHeader.jsx (View menu), RoomChatDock.jsx (desktop), RoomChatDrawer.jsx (phone), RoomSkipLink.jsx |
| Desk | RoomDesk.jsx, DeskItem.jsx, ItemFace.jsx, ItemMenu.jsx, RoomToolbar.jsx, NoteEditor.jsx, RoomDialogs.jsx, MoveToDialog.jsx, useDeskActions.js, useDeskDrag.js, useDeskLayout.js, useDeskSelection.js, room-grid.js |
| Folders and Lost & Found | FolderWindow.jsx, LostFoundWindow.jsx, lost-found-model.js, RoomPanel.jsx (dialog on desktop, sheet on a phone) |
| Safety | SafetyButtons.jsx, RoomSafetyDialogs.jsx, room-safety-model.js |
| Phone | room-gesture-model.js, useTouchDrag.js, useGhostClickGuard.js, ItemSheet.jsx, common-room-mobile.css |
| List view | RoomListView.jsx, RoomListRow.jsx, room-list-model.js |
| Words | common-room-copy.js, common-room-desk-copy.js, common-room-list-copy.js, common-room-mobile-copy.js |
| Models and styles | room-item-model.js, room-items-model.js, room-item-actions.js, room-layout.js, room-layout-context.js, room-name.js, common-room*.css (one per area), index.js (exports for the messaging screens) |
| Tests | __tests__/ (34 test files, vitest with happy-dom and jest-axe). Database behaviour is proved separately by supabase/checks/common-room*.mjs on a throwaway stack |
Export and account deletion
The account export (keyring.export_my_data) includes the member's own Common Room rows: items they added, their viewer
preferences, rooms they opened, repair-log entries of their own actions, and the layout-history rows of the changes they
made (CR-H1). Deleting an account deletes their items and preferences; rooms they opened, log entries, layout-history rows
and Lost & Found provenance keep no name. Deleting a conversation deletes its room, and the room's layout history with it.