feat: complete Ancestor quote bot with production-ready Docker support
This commit is contained in:
32
node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.js
generated
vendored
32
node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.js
generated
vendored
@@ -1,4 +1,11 @@
|
||||
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.KeyClaimManager = void 0;
|
||||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
||||
/*
|
||||
Copyright 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
@@ -22,12 +29,12 @@ limitations under the License.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export class KeyClaimManager {
|
||||
class KeyClaimManager {
|
||||
constructor(olmMachine, outgoingRequestProcessor) {
|
||||
_defineProperty(this, "currentClaimPromise", void 0);
|
||||
_defineProperty(this, "stopped", false);
|
||||
this.olmMachine = olmMachine;
|
||||
this.outgoingRequestProcessor = outgoingRequestProcessor;
|
||||
(0, _defineProperty2.default)(this, "currentClaimPromise", void 0);
|
||||
(0, _defineProperty2.default)(this, "stopped", false);
|
||||
this.currentClaimPromise = Promise.resolve();
|
||||
}
|
||||
|
||||
@@ -44,35 +51,30 @@ export class KeyClaimManager {
|
||||
* Given a list of users, attempt to ensure that we have Olm Sessions active with each of their devices
|
||||
*
|
||||
* If we don't have an active olm session, we will claim a one-time key and start one.
|
||||
* @param logger - logger to use
|
||||
*
|
||||
* @param userList - list of userIDs to claim
|
||||
*/
|
||||
ensureSessionsForUsers(logger, userList) {
|
||||
ensureSessionsForUsers(userList) {
|
||||
// The Rust-SDK requires that we only have one getMissingSessions process in flight at once. This little dance
|
||||
// ensures that, by only having one call to ensureSessionsForUsersInner active at once (and making them
|
||||
// queue up in order).
|
||||
const prom = this.currentClaimPromise.catch(() => {
|
||||
// any errors in the previous claim will have been reported already, so there is nothing to do here.
|
||||
// we just throw away the error and start anew.
|
||||
}).then(() => this.ensureSessionsForUsersInner(logger, userList));
|
||||
}).then(() => this.ensureSessionsForUsersInner(userList));
|
||||
this.currentClaimPromise = prom;
|
||||
return prom;
|
||||
}
|
||||
async ensureSessionsForUsersInner(logger, userList) {
|
||||
async ensureSessionsForUsersInner(userList) {
|
||||
// bail out quickly if we've been stopped.
|
||||
if (this.stopped) {
|
||||
throw new Error(`Cannot ensure Olm sessions: shutting down`);
|
||||
}
|
||||
logger.info("Checking for missing Olm sessions");
|
||||
// By passing the userId array to rust we transfer ownership of the items to rust, causing
|
||||
// them to be invalidated on the JS side as soon as the method is called.
|
||||
// As we haven't created the `userList` let's clone the users, to not break the caller from re-using it.
|
||||
const claimRequest = await this.olmMachine.getMissingSessions(userList.map(u => u.clone()));
|
||||
const claimRequest = await this.olmMachine.getMissingSessions(userList);
|
||||
if (claimRequest) {
|
||||
logger.info("Making /keys/claim request");
|
||||
await this.outgoingRequestProcessor.makeOutgoingRequest(claimRequest);
|
||||
}
|
||||
logger.info("Olm sessions prepared");
|
||||
}
|
||||
}
|
||||
exports.KeyClaimManager = KeyClaimManager;
|
||||
//# sourceMappingURL=KeyClaimManager.js.map
|
||||
Reference in New Issue
Block a user