Skip to content

Commit

Permalink
ULMS-3379 Added listStateSet method
Browse files Browse the repository at this point in the history
  • Loading branch information
dkvovik committed Oct 4, 2024
1 parent 463e02e commit 7849473
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ulms/api-clients",
"version": "7.21.0",
"version": "7.22.0-dev.1-ULMS-3379",
"description": "JavaScript API clients for ULMS platform",
"keywords": [],
"homepage": "https://github.com/foxford/ulms-api-clients-js#readme",
Expand Down
44 changes: 44 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,47 @@ export function mergeSignals(signals) {

return controller.signal
}

// eslint-disable-next-line unicorn/prevent-abbreviations
export function listStateSet(client, roomId, set, params = {}) {
let result = []

function loop(room, parameters, callback) {
return rejectByTimeout(client.readState(room, [set], parameters))
.then((response) => {
if (response[set]?.length > 0) {
result = [...result, ...response[set]]

if (response.has_next) {
loop(
room,
{
...parameters,
original_occurred_at:
// eslint-disable-next-line unicorn/prefer-at
response[set][response[set].length - 1].original_occurred_at,
},
callback,
)
} else {
callback() // eslint-disable-line promise/no-callback-in-promise
}
} else {
callback() // eslint-disable-line promise/no-callback-in-promise
}
})
.catch((error) => callback(error)) // eslint-disable-line promise/no-callback-in-promise
}

return new Promise((resolve, reject) => {
loop(roomId, params, (error) => {
if (error) {
reject(error)

return
}

resolve(result)
})
})
}

0 comments on commit 7849473

Please sign in to comment.