From 63afecb53f12d02597b3cf6c870aa415dfe6bd51 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Tue, 24 Dec 2024 00:38:52 -0300 Subject: [PATCH] fix roomMemberEvent tests --- .../core/src/events/m.room.member-invite.spec.ts | 12 ++++++------ packages/core/src/events/m.room.member.spec.ts | 4 +++- packages/core/src/events/m.room.member.ts | 14 ++++++++++++-- packages/homeserver/src/procedures/createRoom.ts | 4 +++- packages/homeserver/src/procedures/makeJoin.ts | 11 ++++++++++- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/packages/core/src/events/m.room.member-invite.spec.ts b/packages/core/src/events/m.room.member-invite.spec.ts index e48a355b..557600a8 100644 --- a/packages/core/src/events/m.room.member-invite.spec.ts +++ b/packages/core/src/events/m.room.member-invite.spec.ts @@ -72,12 +72,12 @@ test("roomMemberInviteEvent", async () => { state_key: "@asd6:rc1", ts: 1733107418773, depth: 7, - auth_events: [ - "$0AQU5dG_mtjH6qavAxYrQsDC0a_-6T3DHs1yoxf5fz4", - "$T20EETjD2OuaC1OVyg8iIbJGTNeGBsMiWoAagBOVRNE", - "$Uxo9MgF-4HQNEZdkkQDzgh9wlZ1yJbDXTMXCh6aZBi4", - "$tZRt2bwceX4sG913Ee67tJiwe-gk859kY2mCeYSncw8", - ], + auth_events: { + create: "$0AQU5dG_mtjH6qavAxYrQsDC0a_-6T3DHs1yoxf5fz4", + power_levels: "$T20EETjD2OuaC1OVyg8iIbJGTNeGBsMiWoAagBOVRNE", + join_rules: "$Uxo9MgF-4HQNEZdkkQDzgh9wlZ1yJbDXTMXCh6aZBi4", + history_visibility: "$tZRt2bwceX4sG913Ee67tJiwe-gk859kY2mCeYSncw8", + }, prev_events: ["$gdAY3-3DdjuG-uyFkDn8q5wPS4fbymH__fch9BQmOas"], content: { is_direct: true, diff --git a/packages/core/src/events/m.room.member.spec.ts b/packages/core/src/events/m.room.member.spec.ts index 8bb6fcfb..2ec17846 100644 --- a/packages/core/src/events/m.room.member.spec.ts +++ b/packages/core/src/events/m.room.member.spec.ts @@ -51,7 +51,9 @@ test("roomMemberEvent", async () => { state_key: "@admin:hs1", ts: 1733107418672, depth: 2, - auth_events: [createEventId], + auth_events: { + create: createEventId, + }, prev_events: [createEventId], }); const signed = await signEvent(memberEvent, signature, "hs1"); diff --git a/packages/core/src/events/m.room.member.ts b/packages/core/src/events/m.room.member.ts index 3295e3e3..ecc3c8f0 100644 --- a/packages/core/src/events/m.room.member.ts +++ b/packages/core/src/events/m.room.member.ts @@ -86,7 +86,12 @@ export const roomMemberEvent = ({ roomId: string; sender: string; state_key: string; - auth_events: string[]; + auth_events: { + create: string; + power_levels?: string; + join_rules?: string; + history_visibility?: string; + }; prev_events: string[]; depth: number; unsigned?: RoomMemberEvent["unsigned"]; @@ -97,7 +102,12 @@ export const roomMemberEvent = ({ return createEventBase("m.room.member", { roomId, sender, - auth_events, + auth_events: [ + auth_events.create, + auth_events.power_levels, + auth_events.join_rules, + auth_events.history_visibility, + ].filter(Boolean) as string[], prev_events, depth, content: { diff --git a/packages/homeserver/src/procedures/createRoom.ts b/packages/homeserver/src/procedures/createRoom.ts index bd6133dc..bd6525b2 100644 --- a/packages/homeserver/src/procedures/createRoom.ts +++ b/packages/homeserver/src/procedures/createRoom.ts @@ -55,7 +55,9 @@ export const createRoom = async ( displayname: sender, }, state_key: sender, - auth_events: [createEvent._id], + auth_events: { + create: createEvent._id, + }, prev_events: [createEvent._id], }); diff --git a/packages/homeserver/src/procedures/makeJoin.ts b/packages/homeserver/src/procedures/makeJoin.ts index 17314a3b..b4249962 100644 --- a/packages/homeserver/src/procedures/makeJoin.ts +++ b/packages/homeserver/src/procedures/makeJoin.ts @@ -31,12 +31,21 @@ export const makeJoinEventBuilder = } const authEvents = await getAuthEvents(roomId); + + const authEventsMap = new Map( + authEvents.map((event) => [event.event.type, event]), + ); + const event = roomMemberEvent({ membership: "join", roomId, sender: userId, state_key: userId, - auth_events: authEvents.map((event) => event._id), + auth_events: { + create: authEventsMap.get("m.room.create")!._id, + power_levels: authEventsMap.get("m.room.power_levels")!._id, + join_rules: authEventsMap.get("m.room.join_rules")!._id, + }, prev_events: [lastEvent._id], depth: lastEvent.event.depth + 1, origin,