Your music, beautifully tracked. All yours. (coming soon) teal.fm
teal-fm atproto

statuses should get committed to db correctly now

+24 -8
+24 -8
packages/jetstring/src/index.ts
··· 3 3 import { status } from "@teal/db/schema"; 4 4 import { CommitCreateEvent, Jetstream } from "@skyware/jetstream"; 5 5 6 + import { 7 + Record as XyzStatusphereStatus, 8 + isRecord as isStatusphereStatus, 9 + } from "@teal/lexicons/generated/server/types/xyz/statusphere/status"; 10 + 6 11 class Handler { 7 12 private static instance: Handler; 8 13 private constructor() {} ··· 13 18 return Handler.instance; 14 19 } 15 20 16 - handle(msg_type: string, msg: any) { 21 + handle(msg_type: string, record: CommitCreateEvent<string & {}>) { 17 22 // Handle message logic here 23 + const msg = record.commit.record; 18 24 console.log("Handling" + msg_type + "message:", msg); 19 - if (msg_type === "xyz.statusphere.status") { 20 - // serialize message as xyz.statusphere.status 21 - const st = db.insert(status).values({ 22 - status: msg.status, 23 - uri: msg.uri, 24 - authorDid: msg.authorDid, 25 - }); 25 + if (isStatusphereStatus(msg) && msg.$type === "xyz.statusphere.status") { 26 + if (record.commit.operation === "create") { 27 + // serialize message as xyz.statusphere.status 28 + db.insert(status).values({ 29 + createdAt: new Date().getSeconds().toString(), 30 + indexedAt: new Date(record.time_us).getSeconds().toString(), 31 + status: msg.status, 32 + // the AT path 33 + uri: record.commit.rkey, 34 + authorDid: record.did, 35 + }); 36 + } else { 37 + console.log("unsupported operation:", record.commit.operation); 38 + } 39 + } else { 40 + console.log("Unknown message type:", msg_type); 41 + console.log("Message:", record); 26 42 } 27 43 } 28 44 }