import { MatrixClient } from "../MatrixClient" ; import { EncryptionEventContent } from "../models/events/EncryptionEvent" ; category export class RoomTracker { public constructor ( private client ) { this . client . on ( "room.join" , ( roomId ) => { this . queueRoomCheck ( roomId ) ; } ) ; this . client . on ( "room.event" , ( roomId , event ) => { if ( event [ 'type' ] === 'm.room.encryption' && event [ 'state_key' ] === '' ) { this . queueRoomCheck ( roomId ) ; } } ) ; } param { string [ ] } roomIds public async prepare ( roomIds ) { for ( const roomId of roomIds ) { await this . queueRoomCheck ( roomId ) ; } } param { string } roomId public async queueRoomCheck ( roomId ) { const config = await this . client . cryptoStore . getRoom ( roomId ) ; if ( config ) { if ( config . algorithm !== undefined ) { return ; } } let encEvent ; try { encEvent = await this . client . getRoomStateEvent ( roomId , "m.room.encryption" , "" ) ; encEvent . algorithm = encEvent . algorithm ?? 'UNKNOWN' ; } catch ( e ) { return ; } await this . client . cryptoStore . storeRoom ( roomId , encEvent ) ; } param { string } roomId returns { Promise < Partial < EncryptionEventContent > > } public async getRoomCryptoConfig ( roomId ) { let config = await this . client . cryptoStore . getRoom ( roomId ) ; if ( ! config ) { await this . queueRoomCheck ( roomId ) ; config = await this . client . cryptoStore . getRoom ( roomId ) ; } if ( ! config ) { return { } ; } return config ; } }