mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-10 12:22:50 +02:00
Make a helper for the room hierarchy
This commit is contained in:
parent
89696fd161
commit
3a84658e8b
3 changed files with 31 additions and 27 deletions
|
@ -32,24 +32,18 @@ sync.addTemporaryListener(as, "type:m.room.name", /** @param {Ty.Event.StateOute
|
|||
})
|
||||
|
||||
// Manage adding to the cache
|
||||
async function getHierarchy(spaceID) {
|
||||
async function getCachedHierarchy(spaceID) {
|
||||
return cache.get(spaceID) || (() => {
|
||||
const entry = (async () => {
|
||||
const result = await api.getFullHierarchy(spaceID)
|
||||
/** @type {{name: string, value: string}[]} */
|
||||
let childRooms = []
|
||||
/** @type {string | undefined} */
|
||||
let nextBatch = undefined
|
||||
do {
|
||||
/** @type {Ty.HierarchyPagination<Ty.R.Hierarchy>} */
|
||||
const res = await api.getHierarchy(spaceID, {from: nextBatch})
|
||||
for (const room of res.rooms) {
|
||||
if (room.name) {
|
||||
childRooms.push({name: room.name, value: room.room_id})
|
||||
reverseCache.set(room.room_id, spaceID)
|
||||
}
|
||||
const childRooms = []
|
||||
for (const room of result) {
|
||||
if (room.name) {
|
||||
childRooms.push({name: room.name, value: room.room_id})
|
||||
reverseCache.set(room.room_id, spaceID)
|
||||
}
|
||||
nextBatch = res.next_batch
|
||||
} while (nextBatch)
|
||||
}
|
||||
return childRooms
|
||||
})()
|
||||
cache.set(spaceID, entry)
|
||||
|
@ -74,7 +68,7 @@ async function interactAutocomplete({id, token, data, guild_id}) {
|
|||
})
|
||||
}
|
||||
|
||||
let rooms = await getHierarchy(spaceID)
|
||||
let rooms = await getCachedHierarchy(spaceID)
|
||||
// @ts-ignore
|
||||
rooms = rooms.filter(r => r.name.startsWith(data.options[0].value))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue