Skip to content

Commit

Permalink
fix roomMemberEvent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Dec 24, 2024
1 parent 714042e commit 63afecb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
12 changes: 6 additions & 6 deletions packages/core/src/events/m.room.member-invite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/events/m.room.member.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
14 changes: 12 additions & 2 deletions packages/core/src/events/m.room.member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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: {
Expand Down
4 changes: 3 additions & 1 deletion packages/homeserver/src/procedures/createRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
});

Expand Down
11 changes: 10 additions & 1 deletion packages/homeserver/src/procedures/makeJoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 63afecb

Please sign in to comment.