@@ -21,7 +21,7 @@ import {
2121import { DataStore } from ".//datastore" ;
2222import { PgDataStore } from "./postgres/PgDataStore" ;
2323import { Api } from "./Api" ;
24- import { IConfig } from "./config/config" ;
24+ import { AppserviceConfig } from "./config/config" ;
2525import { AccessControl } from "./AccessControl" ;
2626import { AppserviceCommandHandler } from "./bot/AppserviceCommandHandler" ;
2727import { getStoragePath , SOFTWARE_VERSION } from "../config" ;
@@ -30,7 +30,6 @@ import {
3030 ClientCapabilityFactory ,
3131 RoomStateManagerFactory ,
3232 joinedRoomsSafe ,
33- resolveRoomReferenceSafe ,
3433} from "matrix-protection-suite-for-matrix-bot-sdk" ;
3534import {
3635 ClientsInRoomMap ,
@@ -43,11 +42,11 @@ import {
4342} from "matrix-protection-suite" ;
4443import { AppServiceDraupnirManager } from "./AppServiceDraupnirManager" ;
4544import {
45+ isStringRoomAlias ,
46+ isStringRoomID ,
4647 MatrixRoomReference ,
4748 StringRoomID ,
4849 StringUserID ,
49- isStringRoomAlias ,
50- isStringRoomID ,
5150} from "@the-draupnir-project/matrix-basic-types" ;
5251import { SqliteRoomStateBackingStore } from "../backingstore/better-sqlite3/SqliteRoomStateBackingStore" ;
5352
@@ -65,7 +64,7 @@ export class MjolnirAppService {
6564 * use `makeMjolnirAppService`.
6665 */
6766 private constructor (
68- public readonly config : IConfig ,
67+ public readonly config : AppserviceConfig ,
6968 public readonly bridge : Bridge ,
7069 public readonly draupnirManager : AppServiceDraupnirManager ,
7170 public readonly accessControl : AccessControl ,
@@ -97,7 +96,7 @@ export class MjolnirAppService {
9796 * @returns A new `MjolnirAppService`.
9897 */
9998 public static async makeMjolnirAppService (
100- config : IConfig ,
99+ config : AppserviceConfig ,
101100 dataStore : DataStore ,
102101 eventDecoder : EventDecoder ,
103102 registrationFilePath : string ,
@@ -122,24 +121,6 @@ export class MjolnirAppService {
122121 disableStores : true ,
123122 } ) ;
124123 await bridge . initialise ( ) ;
125- const adminRoom = ( ( ) => {
126- if ( isStringRoomID ( config . adminRoom ) ) {
127- return MatrixRoomReference . fromRoomID ( config . adminRoom ) ;
128- } else if ( isStringRoomAlias ( config . adminRoom ) ) {
129- return MatrixRoomReference . fromRoomIDOrAlias ( config . adminRoom ) ;
130- } else {
131- const parseResult = MatrixRoomReference . fromPermalink ( config . adminRoom ) ;
132- if ( isError ( parseResult ) ) {
133- throw new TypeError (
134- `${ config . adminRoom } needs to be a room id, alias or permalink`
135- ) ;
136- }
137- return parseResult . ok ;
138- }
139- } ) ( ) ;
140- const accessControlRoom = (
141- await resolveRoomReferenceSafe ( bridge . getBot ( ) . getClient ( ) , adminRoom )
142- ) . expect ( "Unable to resolve the admin room" ) ;
143124 const clientsInRoomMap = new StandardClientsInRoomMap ( ) ;
144125 const clientProvider = async ( clientUserID : StringUserID ) =>
145126 bridge . getIntent ( clientUserID ) . matrixClient ;
@@ -162,6 +143,24 @@ export class MjolnirAppService {
162143 const botRoomJoiner = clientCapabilityFactory
163144 . makeClientPlatform ( botUserID , bridge . getBot ( ) . getClient ( ) )
164145 . toRoomJoiner ( ) ;
146+ const adminRoom = ( ( ) => {
147+ if ( isStringRoomID ( config . adminRoom ) ) {
148+ return MatrixRoomReference . fromRoomID ( config . adminRoom ) ;
149+ } else if ( isStringRoomAlias ( config . adminRoom ) ) {
150+ return MatrixRoomReference . fromRoomIDOrAlias ( config . adminRoom ) ;
151+ } else {
152+ const parseResult = MatrixRoomReference . fromPermalink ( config . adminRoom ) ;
153+ if ( isError ( parseResult ) ) {
154+ throw new TypeError (
155+ `${ config . adminRoom } needs to be a room id, alias or permalink`
156+ ) ;
157+ }
158+ return parseResult . ok ;
159+ }
160+ } ) ( ) ;
161+ const accessControlRoom = (
162+ await botRoomJoiner . resolveRoom ( adminRoom )
163+ ) . expect ( "Unable to resolve the admin room" ) ;
165164 const appserviceBotPolicyRoomManager =
166165 await roomStateManagerFactory . getPolicyRoomManager ( botUserID ) ;
167166 const accessControl = (
@@ -224,15 +223,15 @@ export class MjolnirAppService {
224223 */
225224 public static async run (
226225 port : number ,
227- config : IConfig ,
226+ config : AppserviceConfig ,
228227 registrationFilePath : string
229228 ) : Promise < MjolnirAppService > {
230229 Logger . configure ( config . logging ?? { console : "debug" } ) ;
231230 const dataStore = new PgDataStore ( config . db . connectionString ) ;
232231 await dataStore . init ( ) ;
233232 const eventDecoder = DefaultEventDecoder ;
234233 const storagePath = getStoragePath ( config . dataPath ) ;
235- const backingStore = config . roomStateBackingStore . enabled
234+ const backingStore = config . roomStateBackingStore ? .enabled
236235 ? SqliteRoomStateBackingStore . create ( storagePath , eventDecoder )
237236 : undefined ;
238237 const service = await MjolnirAppService . makeMjolnirAppService (
0 commit comments