Skip to content

Commit

Permalink
feat: save all pdus events received on db
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Dec 11, 2024
1 parent 2ab76f1 commit ea9666b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/homeserver/src/routes/federation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { makeJoinEndpoint } from "./makeJoin";
import { sendJoinEndpoint } from "./sendJoin";
import { getMissingEventsRoute } from "./getMissingEvents";
import validateHeaderSignature from "../../plugins/validateHeaderSignature";
import { isMongodbContext } from "../../plugins/isMongodbContext";
import { generateId } from "../../authentication";

const federationV1Endpoints = new Elysia({
prefix: "/_matrix/federation/v1",
Expand All @@ -18,10 +20,29 @@ const federationV1Endpoints = new Elysia({
.use(queryEndpoints)
.use(makeJoinEndpoint)
.use(getMissingEventsRoute)
.put("/send/:txnId", ({ params, body }) => {
.put("/send/:txnId", async ({ params, body, ...context }) => {
console.log("receive send ->", params);
console.log("body ->", body);

if (!isMongodbContext(context)) {
throw new Error("No mongodb context");
}

const {
mongo: { eventsCollection },
} = context;

const { pdus } = body as any;

if (pdus) {
await eventsCollection.insertMany(
pdus.map((event: any) => ({
_id: generateId(event),
event,
}))
);
}

return {
[params.txnId]: {},
};
Expand Down

0 comments on commit ea9666b

Please sign in to comment.