Skip to content

Commit e301dfd

Browse files
committed
feat(here-now): add offset parameter for here now
Add a zero-based `offset` index parameter to be used together with `limit` for `here now` pagination.
1 parent 2c39f2b commit e301dfd

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/core/endpoints/presence/here_now.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ export class HereNowRequest extends AbstractRequest<Presence.HereNowResponse, Se
142142
this.parameters.queryParameters ??= {};
143143
this.parameters.includeUUIDs ??= INCLUDE_UUID;
144144
this.parameters.includeState ??= INCLUDE_STATE;
145-
if (this.parameters.limit) this.parameters.limit = Math.min(this.parameters.limit, MAXIMUM_COUNT);
146-
else this.parameters.limit = MAXIMUM_COUNT;
145+
this.parameters.limit ??= MAXIMUM_COUNT;
147146
}
148147

149148
operation(): RequestOperation {
@@ -212,10 +211,11 @@ export class HereNowRequest extends AbstractRequest<Presence.HereNowResponse, Se
212211
}
213212

214213
protected get queryParameters(): Query {
215-
const { channelGroups, includeUUIDs, includeState, limit, queryParameters } = this.parameters;
214+
const { channelGroups, includeUUIDs, includeState, limit, offset, queryParameters } = this.parameters;
216215

217216
return {
218217
...(this.operation() === RequestOperation.PNHereNowOperation ? { limit } : {}),
218+
...(this.operation() === RequestOperation.PNHereNowOperation && (offset ?? 0 > 0) ? { offset } : {}),
219219
...(!includeUUIDs! ? { disable_uuids: '1' } : {}),
220220
...((includeState ?? false) ? { state: '1' } : {}),
221221
...(channelGroups && channelGroups.length > 0 ? { 'channel-group': channelGroups.join(',') } : {}),

src/core/types/api/presence.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,15 @@ export type HereNowParameters = {
195195
/**
196196
* Limit the number of results returned.
197197
*
198-
* **Important:** Maximum value is `1000` users per request.
199-
*
200198
* @default `1000`.
201199
*/
202200
limit?: number;
203201

202+
/**
203+
* Zero-based starting index for pagination.
204+
*/
205+
offset?: number;
206+
204207
/**
205208
* Additional query parameters.
206209
*/

test/integration/endpoints/presence.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,13 @@ describe('presence endpoints', () => {
444444
.query({
445445
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
446446
uuid: 'myUUID',
447-
limit: 1000,
447+
limit: 10000,
448448
})
449449
.reply(200, '{"status": 200, "message": "OK", "occupancy": 1, "service": "Presence"}', {
450450
'content-type': 'text/javascript',
451451
});
452452

453-
pubnub.hereNow({ channels: ['game1'] }, (status, response) => {
453+
pubnub.hereNow({ channels: ['game1'], limit: 10000, offset: 0 }, (status, response) => {
454454
try {
455455
assert.equal(status.error, false);
456456
assert(response !== null);
@@ -477,14 +477,15 @@ describe('presence endpoints', () => {
477477
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
478478
uuid: 'myUUID',
479479
limit: 1000,
480+
offset: 1,
480481
})
481482
.reply(
482483
200,
483484
'{"status": 200, "message": "OK", "payload": {"channels": {"game1": {"uuids": ["a3ffd012-a3b9-478c-8705-64089f24d71e"], "occupancy": 1}}, "total_channels": 1, "total_occupancy": 1}, "service": "Presence"}',
484485
{ 'content-type': 'text/javascript' },
485486
);
486487

487-
pubnub.hereNow({ channels: ['ch1', 'ch2'] }, (status, response) => {
488+
pubnub.hereNow({ channels: ['ch1', 'ch2'], offset: 1 }, (status, response) => {
488489
try {
489490
assert.equal(status.error, false);
490491
assert(response !== null);
@@ -560,7 +561,7 @@ describe('presence endpoints', () => {
560561
.get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2')
561562
.query({
562563
pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`,
563-
limit: 1000,
564+
limit: 10000,
564565
uuid: 'myUUID',
565566
})
566567
.reply(

0 commit comments

Comments
 (0)