mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-11 11:27:03 +00:00
Fix duplicate rooms
This commit is contained in:
@@ -17,7 +17,6 @@ import {
|
|||||||
uniq,
|
uniq,
|
||||||
indexBy,
|
indexBy,
|
||||||
partition,
|
partition,
|
||||||
pushToMapKey,
|
|
||||||
shuffle,
|
shuffle,
|
||||||
parseJson,
|
parseJson,
|
||||||
memoize,
|
memoize,
|
||||||
@@ -492,7 +491,7 @@ export const roomMetaEventsByIdByUrl = deriveEventsByIdByUrl({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export const roomsByUrl = derived(roomMetaEventsByIdByUrl, roomMetaEventsByIdByUrl => {
|
export const roomsByUrl = derived(roomMetaEventsByIdByUrl, roomMetaEventsByIdByUrl => {
|
||||||
const result = new Map<string, Room[]>()
|
const metaByIdByUrl = new Map<string, Map<string, Room>>()
|
||||||
|
|
||||||
for (const [url, events] of roomMetaEventsByIdByUrl.entries()) {
|
for (const [url, events] of roomMetaEventsByIdByUrl.entries()) {
|
||||||
const [metaEvents, deleteEvents] = partition(spec({kind: ROOM_META}), events.values())
|
const [metaEvents, deleteEvents] = partition(spec({kind: ROOM_META}), events.values())
|
||||||
@@ -511,10 +510,24 @@ export const roomsByUrl = derived(roomMetaEventsByIdByUrl, roomMetaEventsByIdByU
|
|||||||
continue
|
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<string, Room[]>()
|
||||||
|
|
||||||
|
for (const [url, metaById] of metaByIdByUrl.entries()) {
|
||||||
|
result.set(url, Array.from(metaById.values()))
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user