add managementRoomId to provisionNewMjolnir

This commit is contained in:
jesopo 2022-08-16 11:31:10 +00:00 committed by gnuxie
parent c1d79a698b
commit 6d604190a4
3 changed files with 15 additions and 16 deletions

View File

@ -89,13 +89,11 @@ export class Api {
return;
}
const managementRoom = request.params.query["roomId"] || null;
const managementRoom = request.params.query["roomId"];
const userId = await this.resolveAccessToken(accessToken);
const mjolnirId = this.appService.provisionNewMjolnir(
userId,
// method doesn't take a managementRoom yet
//managementRoom,
userId, managementRoom,
);
// privisionNewMjolnir can't fail yet, but it should be able to

View File

@ -41,7 +41,7 @@ class MjolnirAppService {
});
}
public async provisionNewMjolnir(requestingUserId: string) {
public async provisionNewMjolnir(requestingUserId: string, managementRoomId: string|undefined) {
// FIXME: we need to restrict who can do it (special list? ban remote users?)
const issuedMjolnirs = await this.bridge.getUserStore()!.getRemoteUsersFromMatrixId(requestingUserId);
if (issuedMjolnirs.length === 0) {
@ -51,7 +51,7 @@ class MjolnirAppService {
// we're only doing this because it's complaining about missing profiles.
// actually the user id wasn't even right, so this might not be necessary anymore.
await mjIntent.ensureProfile('Mjolnir');
this.mjolnirManager.createNew(requestingUserId, mjIntent);
this.mjolnirManager.createNew(requestingUserId, managementRoomId, mjIntent);
// Technically the mjolnir is a remote user, but also not because it's matrix-matrix.
//const mjAsRemote = new RemoteUser(mjIntent.userId)
//const bridgeStore = this.bridge.getUserStore()!;

View File

@ -11,7 +11,7 @@ export class MjolnirManager {
return setDefaults({managementRoom});
}
public async createNew(requestingUserId: string, intent: Intent) {
public async createNew(requestingUserId: string, managementRoomId: string|undefined, intent: Intent) {
// FIXME: We should be creating the intent here and generating the id surely?
// rather than externally...
// FIXME: We need to verify that we haven't stored a mjolnir already if we aren't doing the above.
@ -19,18 +19,19 @@ export class MjolnirManager {
// get mjolnir list wroking by just avoiding it for now and see if protections work
// and bans.
// Find out trade offs of changing mjolnir to make it work vs making new subcomponent of mjolnir.
const managementRoomId = (await intent.createRoom({
createAsClient: true,
options: {
preset: 'private_chat',
invite: [requestingUserId],
name: `${requestingUserId}'s mjolnir`
}
})).room_id;
if (managementRoomId === undefined) {
managementRoomId = (await intent.createRoom({
createAsClient: true,
options: {
preset: 'private_chat',
invite: [requestingUserId],
name: `${requestingUserId}'s mjolnir`
}
})).room_id;
}
const managedMjolnir = new ManagedMjolnir(intent, await Mjolnir.setupMjolnirFromConfig(intent.matrixClient, this.getDefaultMjolnirConfig(managementRoomId)));
await managedMjolnir.moveMeSomewhereCommonAndStopImplementingFunctionalityOnACommandFirstBasis(requestingUserId, 'list')
this.mjolnirs.set(intent.userId, managedMjolnir);
}
public onEvent(request: Request<WeakEvent>, context: BridgeContext) {