Cotton code
292 lines · 7.0 KB · JSONRaw
{  "format_version": 1,  "id": "thread_member",  "name": "Chat member",  "plural": "Chat members",  "builtin": true,  "visibility": "owner",  "columns": [    {      "key": "thread_id",      "type": "link",      "link_to": "thread",      "required": true,      "readonly": true,      "contributes": false    },    {      "key": "contact_id",      "type": "link",      "link_to": "message_contact",      "readonly": true    },    {      "key": "display_name",      "type": "text",      "readonly": true    },    {      "key": "role",      "type": "text",      "readonly": true    },    {      "key": "left_at",      "type": "date",      "readonly": true    },    {      "key": "is_self",      "type": "bool",      "readonly": true    },    {      "key": "name",      "type": "text",      "readonly": true    },    {      "key": "person_id",      "type": "link",      "link_to": "person",      "readonly": true,      "contributes": false    }  ],  "seal": {    "clear": [      "thread_id",      "contact_id",      "person_id",      "left_at"    ],    "blind": [      "display_name",      "name"    ]  },  "instructions": "One person in a conversation, as the thread lists them: the name the chat shows, the person they are in the owner's contacts when one is known, their role in a group, and when they left it. Members are read only here; the messages engine keeps them in step with the conversation.",  "tables": [    {      "name": "cotton_msg_thread_participants",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "thread_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    thread_id TEXT NOT NULL",          "position": 1        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 2        },        {          "name": "contact_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    contact_id TEXT",          "position": 3        },        {          "name": "display_name",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    display_name TEXT",          "position": 4        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 5        },        {          "name": "role",          "type": "TEXT",          "default": "'member'",          "nullable": false,          "primary_key": false,          "declaration": "\n    role TEXT NOT NULL DEFAULT 'member'",          "position": 6        },        {          "name": "left_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    left_at TEXT",          "position": 7        },        {          "name": "is_self",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    is_self INTEGER NOT NULL DEFAULT 0",          "position": 8        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 9        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 10        }      ],      "constraints": [        {          "declaration": "\n    CHECK (role IN ('admin', 'member'))",          "position": 11        },        {          "declaration": "\n    CHECK ((is_self = 1) OR (contact_id IS NOT NULL) OR (NULLIF(trim(COALESCE(display_name, '')), '') IS NOT NULL))",          "position": 12        },        {          "declaration": "\n    FOREIGN KEY (contact_id) REFERENCES cotton_msg_contacts(id)",          "position": 13        },        {          "declaration": "\n    FOREIGN KEY (thread_id) REFERENCES cotton_msg_threads(id)",          "position": 14        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 15        }      ],      "prefix": "CREATE TABLE \"cotton_msg_thread_participants\" (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_msg_thread_participants_contact ON cotton_msg_thread_participants (contact_id)",        "CREATE INDEX idx_cotton_msg_thread_participants_workspace ON cotton_msg_thread_participants (workspace_id)",        "CREATE INDEX idx_cotton_msg_thread_participants_thread_label ON cotton_msg_thread_participants (thread_id, display_name)",        "CREATE INDEX idx_cotton_msg_thread_participants_thread_contact ON cotton_msg_thread_participants (thread_id, contact_id)",        "CREATE INDEX IF NOT EXISTS idx_cotton_msg_thread_participants_author ON cotton_msg_thread_participants (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    }  ],  "picture": null,  "engine": "messages",  "title": "name",  "date": null,  "project": null,  "order": null,  "slip": {    "title": "name",    "subtitle": "role",    "trailing": null,    "photo": null,    "toggle": null  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "name",        "person_id",        "role",        "left_at"      ]    }  ],  "delete": false,  "commands": [    {      "id": "person",      "label": "Open person",      "object": "person",      "kind": "open",      "opens": "person_id"    },    {      "id": "chat",      "label": "Open chat",      "object": "bubble",      "kind": "open",      "opens": "thread_id"    }  ],  "card": {    "face": "plain",    "fields": [      {        "slot": "title",        "column": "name"      },      {        "slot": "subtitle",        "column": "role"      },      {        "slot": "facts",        "column": "left_at"      }    ]  },  "parts": {    "shape": "sheet",    "head": {      "facts": []    },    "links": [],    "lists": [],    "acts": {      "more": [        "person",        "chat"      ]    },    "cards": [      {        "column": "role"      },      {        "column": "left_at"      }    ],    "strip": []  }}