Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ULMS-3379 Added listStateSet method #164

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})
}