Skip to content

Commit

Permalink
make room rkey any type
Browse files Browse the repository at this point in the history
  • Loading branch information
notjuliet committed Oct 23, 2024
1 parent 9e05893 commit f308ca3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
3 changes: 1 addition & 2 deletions lexicons/social/psky/chat/room.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/db/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type RoomTable = {
uri: ColumnType<string, string, never>;
cid: string;
owner_did: ColumnType<string, string, never>;
name: string;
name: string | null;
languages: JSONColumnType<string[]> | null;
topic: string | null;
tags: JSONColumnType<string[]> | null;
Expand Down Expand Up @@ -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"),
)
Expand Down
13 changes: 2 additions & 11 deletions src/db/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/lib/lexicon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
/**
Expand Down

0 comments on commit f308ca3

Please sign in to comment.