src/store/indexeddb-local-backend.js
function(roomId) {
        return new Promise((resolve, reject) =>{
            const tx = this.db.transaction(["oob_membership_events"], "readonly");
            const store = tx.objectStore("oob_membership_events");
            const roomIndex = store.index("room");
            const range = IDBKeyRange.only(roomId);
            const request = roomIndex.openCursor(range);

            const membershipEvents = [];
            // did we encounter the oob_written marker object
            // amongst the results? That means OOB member
            // loading already happened for this room
            // but there were no members to persist as they
            // were all known already
            let oobWritten = false;

            request.onsuccess = (event) => {
                const cursor = event.target.result;
                if (!cursor) {
                    // Unknown room
                    if (!membershipEvents.length && !oobWritten) {
                        return resolve(null);
                    }
                    return resolve(membershipEvents);
                }
                const record = cursor.value;
                if (record.oob_written) {
                    oobWritten = true;
                } else {
                    membershipEvents.push(record);
                }
                cursor.continue();
            };
            request.onerror = (err) => {
                reject(err);
            };
        }).then((events) => {
            console.log(`LL: got ${events && events.length}` +
                ` membershipEvents from storage for room ${roomId} ...`);
            return events;
        });
    }
function(roomId) {
        return new Promise((resolve, reject) =>{
            const tx = this.db.transaction(["oob_membership_events"], "readonly");
            const store = tx.objectStore("oob_membership_events");
            const roomIndex = store.index("room");
            const range = IDBKeyRange.only(roomId);
            const request = roomIndex.openCursor(range);

            const membershipEvents = [];
            // did we encounter the oob_written marker object
            // amongst the results? That means OOB member
            // loading already happened for this room
            // but there were no members to persist as they
            // were all known already
            let oobWritten = false;

            request.onsuccess = (event) => {
                const cursor = event.target.result;
                if (!cursor) {
                    // Unknown room
                    if (!membershipEvents.length && !oobWritten) {
                        return resolve(null);
                    }
                    return resolve(membershipEvents);
                }
                const record = cursor.value;
                if (record.oob_written) {
                    oobWritten = true;
                } else {
                    membershipEvents.push(record);
                }
                cursor.continue();
            };
            request.onerror = (err) => {
                reject(err);
            };
        }).then((events) => {
            console.log(`LL: got ${events && events.length}` +
                ` membershipEvents from storage for room ${roomId} ...`);
            return events;
        });
    }
function ( roomId ) { return new Promise ( ( resolve , reject ) => { const tx = this . db . transaction ( [ "oob_membership_events" ] , "readonly" ) ; const store = tx . objectStore ( "oob_membership_events" ) ; const roomIndex = store . index ( "room" ) ; const range = IDBKeyRange . only ( roomId ) ; const request = roomIndex . openCursor ( range ) ; const membershipEvents = [ ] ; // did we encounter the oob_written marker object // amongst the results? That means OOB member // loading already happened for this room // but there were no members to persist as they // were all known already let oobWritten = false ; request . onsuccess = ( event ) => { const cursor = event . target . result ; if ( ! cursor ) { // Unknown room if ( ! membershipEvents . length && ! oobWritten ) { return resolve ( null ) ; } return resolve ( membershipEvents ) ; } const record = cursor . value ; if ( record . oob_written ) { oobWritten = true ; } else { membershipEvents . push ( record ) ; } cursor . continue ( ) ; } ; request . onerror = ( err ) => { reject ( err ) ; } ; } ) . then ( ( events ) => { console . log ( ` ${ events && events . length } ` + ` ${ roomId } ` ) ; return events ; } ) ; }
Returns the out-of-band membership events for this room that
were previously loaded.
@param {string} roomId
@returns {Promise<event[]>} the events, potentially an empty array if OOB loading didn't yield any new members
@returns {null} in case the members for this room haven't been stored yet
Returns the out - of - band membership events for this room that were previously loaded .