diff --git a/lexicons/social/psky/chat/room.json b/lexicons/social/psky/chat/room.json index 7fc46e7..c821c36 100644 --- a/lexicons/social/psky/chat/room.json +++ b/lexicons/social/psky/chat/room.json @@ -5,10 +5,9 @@ "main": { "type": "record", "description": "A Picosky room belonging to the user.", - "key": "tid", + "key": "any", "record": { "type": "object", - "required": ["name"], "properties": { "name": { "type": "string", diff --git a/src/db/init.ts b/src/db/init.ts index 121d5fd..8874378 100644 --- a/src/db/init.ts +++ b/src/db/init.ts @@ -40,7 +40,7 @@ export type RoomTable = { uri: ColumnType; cid: string; owner_did: ColumnType; - name: string; + name: string | null; languages: JSONColumnType | null; topic: string | null; tags: JSONColumnType | null; @@ -90,7 +90,7 @@ migrations["001"] = { .createTable("rooms") .addColumn("uri", "text", (col) => col.primaryKey()) .addColumn("cid", "text", (col) => col.notNull()) - .addColumn("name", "text", (col) => col.notNull()) + .addColumn("name", "text") .addColumn("owner_did", "text", (col) => col.notNull().references("users.did").onDelete("cascade"), ) diff --git a/src/db/room.ts b/src/db/room.ts index 77766a4..c6bb3ab 100644 --- a/src/db/room.ts +++ b/src/db/room.ts @@ -17,18 +17,9 @@ const getRoom = async (uri: string) => { .executeTakeFirst(); }; -const getRoomByName = async (name: string, did: string) => { - return ctx.db - .selectFrom("rooms") - .where("owner_did", "=", did) - .where("name", "=", name) - .selectAll() - .executeTakeFirst(); -}; - const addRoom = async (room: Room) => { if (!validateRoomName) return; - if (await getRoomByName(room.room.name, room.owner)) return; + if (await getRoom(room.uri)) return; const res = await ctx.db .insertInto("rooms") .values({ @@ -48,7 +39,7 @@ const addRoom = async (room: Room) => { const updateRoom = async (room: Room) => { if (!validateRoomName) return; - const a = await getRoomByName(room.room.name, room.owner); + const a = await getRoom(room.uri); if (a && a.uri !== room.uri) return; const res = (await getRoom(room.uri)) ?? (await addRoom(room)); await ctx.db diff --git a/src/lib/lexicon.ts b/src/lib/lexicon.ts index d13e3f5..568badc 100644 --- a/src/lib/lexicon.ts +++ b/src/lib/lexicon.ts @@ -37,17 +37,17 @@ declare module "@atcute/client/lexicons" { /** A Picosky room belonging to the user. */ interface Record { $type: "social.psky.chat.room"; - /** - * Maximum string length: 320 \ - * Maximum grapheme length: 32 - */ - name: string; /** List of users allowed to send messages in the room. */ allowlist?: ModlistRef; /** List of users disallowed to send messages in the room. */ denylist?: ModlistRef; /** Maximum array length: 3 */ languages?: string[]; + /** + * Maximum string length: 320 \ + * Maximum grapheme length: 32 + */ + name?: string; /** Maximum array length: 20 */ tags?: string[]; /**