From 33b34d416942ae906eb176a6f2727f362b7b6d5a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 10 Jan 2022 08:58:11 +0000 Subject: [PATCH] Fix space ordering to match newer spec (#7481) --- src/stores/spaces/SpaceStore.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/stores/spaces/SpaceStore.ts b/src/stores/spaces/SpaceStore.ts index eedf2b767b..1379b47926 100644 --- a/src/stores/spaces/SpaceStore.ts +++ b/src/stores/spaces/SpaceStore.ts @@ -83,9 +83,9 @@ const validOrder = (order: string): string | undefined => { } }; -// For sorting space children using a validated `order`, `m.room.create`'s `origin_server_ts`, `room_id` -export const getChildOrder = (order: string, creationTs: number, roomId: string): Array>> => { - return [validOrder(order) ?? NaN, creationTs, roomId]; // NaN has lodash sort it at the end in asc +// For sorting space children using a validated `order`, `origin_server_ts`, `room_id` +export const getChildOrder = (order: string, ts: number, roomId: string): Array>> => { + return [validOrder(order) ?? NaN, ts, roomId]; // NaN has lodash sort it at the end in asc }; const getRoomFn: FetchRoomFn = (room: Room) => { @@ -296,10 +296,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient { const room = this.matrixClient?.getRoom(spaceId); const childEvents = room?.currentState.getStateEvents(EventType.SpaceChild).filter(ev => ev.getContent()?.via); return sortBy(childEvents, ev => { - const roomId = ev.getStateKey(); - const childRoom = this.matrixClient?.getRoom(roomId); - const createTs = childRoom?.currentState.getStateEvents(EventType.RoomCreate, "")?.getTs(); - return getChildOrder(ev.getContent().order, createTs, roomId); + return getChildOrder(ev.getContent().order, ev.getTs(), ev.getStateKey()); }).map(ev => { const history = this.matrixClient.getRoomUpgradeHistory(ev.getStateKey(), true); return history[history.length - 1];