mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
implement loading all members
This commit is contained in:
parent
bfc5eb3ee5
commit
9edd1bb0bb
@ -62,11 +62,11 @@ export class QueryTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectWhile(range, predicate) {
|
selectWhile(range, predicate) {
|
||||||
return this._selectWhile(range, predicate, "next");
|
return this._selectWhile(range, predicate, "next", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectWhileReverse(range, predicate) {
|
selectWhileReverse(range, predicate) {
|
||||||
return this._selectWhile(range, predicate, "prev");
|
return this._selectWhile(range, predicate, "prev", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async selectAll(range, direction) {
|
async selectAll(range, direction) {
|
||||||
@ -153,15 +153,18 @@ export class QueryTarget {
|
|||||||
_selectLimit(range, amount, direction) {
|
_selectLimit(range, amount, direction) {
|
||||||
return this._selectWhile(range, (results) => {
|
return this._selectWhile(range, (results) => {
|
||||||
return results.length === amount;
|
return results.length === amount;
|
||||||
}, direction);
|
}, direction, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _selectWhile(range, predicate, direction) {
|
async _selectWhile(range, predicate, direction, includeFailingPredicateResult) {
|
||||||
const cursor = this._openCursor(range, direction);
|
const cursor = this._openCursor(range, direction);
|
||||||
const results = [];
|
const results = [];
|
||||||
await iterateCursor(cursor, (value) => {
|
await iterateCursor(cursor, (value) => {
|
||||||
results.push(value);
|
const passesPredicate = predicate(results, value);
|
||||||
return {done: predicate(results)};
|
if (passesPredicate || includeFailingPredicateResult) {
|
||||||
|
results.push(value);
|
||||||
|
}
|
||||||
|
return {done: passesPredicate};
|
||||||
});
|
});
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
@ -34,4 +34,10 @@ export class RoomMemberStore {
|
|||||||
return this._roomMembersStore.put(member);
|
return this._roomMembersStore.put(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAll(roomId) {
|
||||||
|
const range = IDBKeyRange.lowerBound(encodeKey(roomId, ""));
|
||||||
|
return this._roomMembersStore.selectWhile(range, member => {
|
||||||
|
return member.roomId === roomId;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user