tangled
alpha
login
or
join now
teal.fm
/
teal
110
fork
atom
Your music, beautifully tracked. All yours. (coming soon)
teal.fm
teal-fm
atproto
110
fork
atom
overview
issues
pulls
pipelines
statuses should get committed to db correctly now
natalie
1 year ago
ee6d0bb3
35e14e47
+24
-8
1 changed file
expand all
collapse all
unified
split
packages
jetstring
src
index.ts
+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
6
+
import {
7
7
+
Record as XyzStatusphereStatus,
8
8
+
isRecord as isStatusphereStatus,
9
9
+
} from "@teal/lexicons/generated/server/types/xyz/statusphere/status";
10
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
16
-
handle(msg_type: string, msg: any) {
21
21
+
handle(msg_type: string, record: CommitCreateEvent<string & {}>) {
17
22
// Handle message logic here
23
23
+
const msg = record.commit.record;
18
24
console.log("Handling" + msg_type + "message:", msg);
19
19
-
if (msg_type === "xyz.statusphere.status") {
20
20
-
// serialize message as xyz.statusphere.status
21
21
-
const st = db.insert(status).values({
22
22
-
status: msg.status,
23
23
-
uri: msg.uri,
24
24
-
authorDid: msg.authorDid,
25
25
-
});
25
25
+
if (isStatusphereStatus(msg) && msg.$type === "xyz.statusphere.status") {
26
26
+
if (record.commit.operation === "create") {
27
27
+
// serialize message as xyz.statusphere.status
28
28
+
db.insert(status).values({
29
29
+
createdAt: new Date().getSeconds().toString(),
30
30
+
indexedAt: new Date(record.time_us).getSeconds().toString(),
31
31
+
status: msg.status,
32
32
+
// the AT path
33
33
+
uri: record.commit.rkey,
34
34
+
authorDid: record.did,
35
35
+
});
36
36
+
} else {
37
37
+
console.log("unsupported operation:", record.commit.operation);
38
38
+
}
39
39
+
} else {
40
40
+
console.log("Unknown message type:", msg_type);
41
41
+
console.log("Message:", record);
26
42
}
27
43
}
28
44
}