diff --git a/src/app/core/state.ts b/src/app/core/state.ts index d35cd3fa..a8497854 100644 --- a/src/app/core/state.ts +++ b/src/app/core/state.ts @@ -17,7 +17,6 @@ import { uniq, indexBy, partition, - pushToMapKey, shuffle, parseJson, memoize, @@ -492,7 +491,7 @@ export const roomMetaEventsByIdByUrl = deriveEventsByIdByUrl({ }) export const roomsByUrl = derived(roomMetaEventsByIdByUrl, roomMetaEventsByIdByUrl => { - const result = new Map() + const metaByIdByUrl = new Map>() for (const [url, events] of roomMetaEventsByIdByUrl.entries()) { const [metaEvents, deleteEvents] = partition(spec({kind: ROOM_META}), events.values()) @@ -511,10 +510,24 @@ export const roomsByUrl = derived(roomMetaEventsByIdByUrl, roomMetaEventsByIdByU continue } - pushToMapKey(result, url, {...meta, url, id: makeRoomId(url, meta.h)}) + let metaById = metaByIdByUrl.get(url) + if (!metaById) { + metaById = new Map() + metaByIdByUrl.set(url, metaById) + } + + const id = makeRoomId(url, meta.h) + + metaById.set(id, {...meta, url, id}) } } + const result = new Map() + + for (const [url, metaById] of metaByIdByUrl.entries()) { + result.set(url, Array.from(metaById.values())) + } + return result })