Make a helper for the room hierarchy

This commit is contained in:
Cadence Ember 2024-08-27 19:10:38 +12:00
commit 3a84658e8b
3 changed files with 31 additions and 27 deletions

View file

@ -135,6 +135,24 @@ function getHierarchy(roomID, pagination) {
return mreq.mreq("GET", path)
}
/**
* Like `getHierarchy` but collects all pages for you.
* @param {string} roomID
*/
async function getFullHierarchy(roomID) {
/** @type {Ty.R.Hierarchy[]} */
let rooms = []
/** @type {string | undefined} */
let nextBatch = undefined
do {
/** @type {Ty.HierarchyPagination<Ty.R.Hierarchy>} */
const res = await getHierarchy(roomID, {from: nextBatch})
rooms.push(...res.rooms)
nextBatch = res.next_batch
} while (nextBatch)
return rooms
}
/**
* @param {string} roomID
* @param {string} eventID
@ -254,6 +272,7 @@ module.exports.getAllState = getAllState
module.exports.getStateEvent = getStateEvent
module.exports.getJoinedMembers = getJoinedMembers
module.exports.getHierarchy = getHierarchy
module.exports.getFullHierarchy = getFullHierarchy
module.exports.getRelations = getRelations
module.exports.sendState = sendState
module.exports.sendEvent = sendEvent