@@ -33,6 +33,7 @@ import { isSecretStorageBeingAccessed, accessSecretStorage } from "./SecurityMan
3333import { isSecureBackupRequired } from './utils/WellKnownUtils' ;
3434import { isLoggedIn } from './components/structures/MatrixChat' ;
3535import { MatrixEvent } from "matrix-js-sdk/src/models/event" ;
36+ import { ActionPayload } from "./dispatcher/payloads" ;
3637
3738const KEY_BACKUP_POLL_INTERVAL = 5 * 60 * 1000 ;
3839
@@ -58,28 +59,28 @@ export default class DeviceListener {
5859 }
5960
6061 start ( ) {
61- MatrixClientPeg . get ( ) . on ( 'crypto.willUpdateDevices' , this . _onWillUpdateDevices ) ;
62- MatrixClientPeg . get ( ) . on ( 'crypto.devicesUpdated' , this . _onDevicesUpdated ) ;
63- MatrixClientPeg . get ( ) . on ( 'deviceVerificationChanged' , this . _onDeviceVerificationChanged ) ;
64- MatrixClientPeg . get ( ) . on ( 'userTrustStatusChanged' , this . _onUserTrustStatusChanged ) ;
65- MatrixClientPeg . get ( ) . on ( 'crossSigning.keysChanged' , this . _onCrossSingingKeysChanged ) ;
66- MatrixClientPeg . get ( ) . on ( 'accountData' , this . _onAccountData ) ;
67- MatrixClientPeg . get ( ) . on ( 'sync' , this . _onSync ) ;
68- MatrixClientPeg . get ( ) . on ( 'RoomState.events' , this . _onRoomStateEvents ) ;
69- this . dispatcherRef = dis . register ( this . _onAction ) ;
70- this . _recheck ( ) ;
62+ MatrixClientPeg . get ( ) . on ( 'crypto.willUpdateDevices' , this . onWillUpdateDevices ) ;
63+ MatrixClientPeg . get ( ) . on ( 'crypto.devicesUpdated' , this . onDevicesUpdated ) ;
64+ MatrixClientPeg . get ( ) . on ( 'deviceVerificationChanged' , this . onDeviceVerificationChanged ) ;
65+ MatrixClientPeg . get ( ) . on ( 'userTrustStatusChanged' , this . onUserTrustStatusChanged ) ;
66+ MatrixClientPeg . get ( ) . on ( 'crossSigning.keysChanged' , this . onCrossSingingKeysChanged ) ;
67+ MatrixClientPeg . get ( ) . on ( 'accountData' , this . onAccountData ) ;
68+ MatrixClientPeg . get ( ) . on ( 'sync' , this . onSync ) ;
69+ MatrixClientPeg . get ( ) . on ( 'RoomState.events' , this . onRoomStateEvents ) ;
70+ this . dispatcherRef = dis . register ( this . onAction ) ;
71+ this . recheck ( ) ;
7172 }
7273
7374 stop ( ) {
7475 if ( MatrixClientPeg . get ( ) ) {
75- MatrixClientPeg . get ( ) . removeListener ( 'crypto.willUpdateDevices' , this . _onWillUpdateDevices ) ;
76- MatrixClientPeg . get ( ) . removeListener ( 'crypto.devicesUpdated' , this . _onDevicesUpdated ) ;
77- MatrixClientPeg . get ( ) . removeListener ( 'deviceVerificationChanged' , this . _onDeviceVerificationChanged ) ;
78- MatrixClientPeg . get ( ) . removeListener ( 'userTrustStatusChanged' , this . _onUserTrustStatusChanged ) ;
79- MatrixClientPeg . get ( ) . removeListener ( 'crossSigning.keysChanged' , this . _onCrossSingingKeysChanged ) ;
80- MatrixClientPeg . get ( ) . removeListener ( 'accountData' , this . _onAccountData ) ;
81- MatrixClientPeg . get ( ) . removeListener ( 'sync' , this . _onSync ) ;
82- MatrixClientPeg . get ( ) . removeListener ( 'RoomState.events' , this . _onRoomStateEvents ) ;
76+ MatrixClientPeg . get ( ) . removeListener ( 'crypto.willUpdateDevices' , this . onWillUpdateDevices ) ;
77+ MatrixClientPeg . get ( ) . removeListener ( 'crypto.devicesUpdated' , this . onDevicesUpdated ) ;
78+ MatrixClientPeg . get ( ) . removeListener ( 'deviceVerificationChanged' , this . onDeviceVerificationChanged ) ;
79+ MatrixClientPeg . get ( ) . removeListener ( 'userTrustStatusChanged' , this . onUserTrustStatusChanged ) ;
80+ MatrixClientPeg . get ( ) . removeListener ( 'crossSigning.keysChanged' , this . onCrossSingingKeysChanged ) ;
81+ MatrixClientPeg . get ( ) . removeListener ( 'accountData' , this . onAccountData ) ;
82+ MatrixClientPeg . get ( ) . removeListener ( 'sync' , this . onSync ) ;
83+ MatrixClientPeg . get ( ) . removeListener ( 'RoomState.events' , this . onRoomStateEvents ) ;
8384 }
8485 if ( this . dispatcherRef ) {
8586 dis . unregister ( this . dispatcherRef ) ;
@@ -103,15 +104,15 @@ export default class DeviceListener {
103104 this . dismissed . add ( d ) ;
104105 }
105106
106- this . _recheck ( ) ;
107+ this . recheck ( ) ;
107108 }
108109
109110 dismissEncryptionSetup ( ) {
110111 this . dismissedThisDeviceToast = true ;
111- this . _recheck ( ) ;
112+ this . recheck ( ) ;
112113 }
113114
114- _ensureDeviceIdsAtStartPopulated ( ) {
115+ private ensureDeviceIdsAtStartPopulated ( ) {
115116 if ( this . ourDeviceIdsAtStart === null ) {
116117 const cli = MatrixClientPeg . get ( ) ;
117118 this . ourDeviceIdsAtStart = new Set (
@@ -120,39 +121,39 @@ export default class DeviceListener {
120121 }
121122 }
122123
123- _onWillUpdateDevices = async ( users : string [ ] , initialFetch ?: boolean ) => {
124+ private onWillUpdateDevices = async ( users : string [ ] , initialFetch ?: boolean ) => {
124125 // If we didn't know about *any* devices before (ie. it's fresh login),
125126 // then they are all pre-existing devices, so ignore this and set the
126127 // devicesAtStart list to the devices that we see after the fetch.
127128 if ( initialFetch ) return ;
128129
129130 const myUserId = MatrixClientPeg . get ( ) . getUserId ( ) ;
130- if ( users . includes ( myUserId ) ) this . _ensureDeviceIdsAtStartPopulated ( ) ;
131+ if ( users . includes ( myUserId ) ) this . ensureDeviceIdsAtStartPopulated ( ) ;
131132
132133 // No need to do a recheck here: we just need to get a snapshot of our devices
133134 // before we download any new ones.
134135 } ;
135136
136- _onDevicesUpdated = ( users : string [ ] ) => {
137+ private onDevicesUpdated = ( users : string [ ] ) => {
137138 if ( ! users . includes ( MatrixClientPeg . get ( ) . getUserId ( ) ) ) return ;
138- this . _recheck ( ) ;
139+ this . recheck ( ) ;
139140 } ;
140141
141- _onDeviceVerificationChanged = ( userId : string ) => {
142+ private onDeviceVerificationChanged = ( userId : string ) => {
142143 if ( userId !== MatrixClientPeg . get ( ) . getUserId ( ) ) return ;
143- this . _recheck ( ) ;
144+ this . recheck ( ) ;
144145 } ;
145146
146- _onUserTrustStatusChanged = ( userId : string ) => {
147+ private onUserTrustStatusChanged = ( userId : string ) => {
147148 if ( userId !== MatrixClientPeg . get ( ) . getUserId ( ) ) return ;
148- this . _recheck ( ) ;
149+ this . recheck ( ) ;
149150 } ;
150151
151- _onCrossSingingKeysChanged = ( ) => {
152- this . _recheck ( ) ;
152+ private onCrossSingingKeysChanged = ( ) => {
153+ this . recheck ( ) ;
153154 } ;
154155
155- _onAccountData = ( ev ) => {
156+ private onAccountData = ( ev : MatrixEvent ) => {
156157 // User may have:
157158 // * migrated SSSS to symmetric
158159 // * uploaded keys to secret storage
@@ -163,32 +164,32 @@ export default class DeviceListener {
163164 ev . getType ( ) . startsWith ( 'm.cross_signing.' ) ||
164165 ev . getType ( ) === 'm.megolm_backup.v1'
165166 ) {
166- this . _recheck ( ) ;
167+ this . recheck ( ) ;
167168 }
168169 } ;
169170
170- _onSync = ( state , prevState ) => {
171- if ( state === 'PREPARED' && prevState === null ) this . _recheck ( ) ;
171+ private onSync = ( state , prevState ) => {
172+ if ( state === 'PREPARED' && prevState === null ) this . recheck ( ) ;
172173 } ;
173174
174- _onRoomStateEvents = ( ev : MatrixEvent ) => {
175+ private onRoomStateEvents = ( ev : MatrixEvent ) => {
175176 if ( ev . getType ( ) !== "m.room.encryption" ) {
176177 return ;
177178 }
178179
179180 // If a room changes to encrypted, re-check as it may be our first
180181 // encrypted room. This also catches encrypted room creation as well.
181- this . _recheck ( ) ;
182+ this . recheck ( ) ;
182183 } ;
183184
184- _onAction = ( { action } ) => {
185+ private onAction = ( { action } : ActionPayload ) => {
185186 if ( action !== "on_logged_in" ) return ;
186- this . _recheck ( ) ;
187+ this . recheck ( ) ;
187188 } ;
188189
189190 // The server doesn't tell us when key backup is set up, so we poll
190191 // & cache the result
191- async _getKeyBackupInfo ( ) {
192+ private async getKeyBackupInfo ( ) {
192193 const now = ( new Date ( ) ) . getTime ( ) ;
193194 if ( ! this . keyBackupInfo || this . keyBackupFetchedAt < now - KEY_BACKUP_POLL_INTERVAL ) {
194195 this . keyBackupInfo = await MatrixClientPeg . get ( ) . getKeyBackupVersion ( ) ;
@@ -206,7 +207,7 @@ export default class DeviceListener {
206207 return cli && cli . getRooms ( ) . some ( r => cli . isRoomEncrypted ( r . roomId ) ) ;
207208 }
208209
209- async _recheck ( ) {
210+ private async recheck ( ) {
210211 const cli = MatrixClientPeg . get ( ) ;
211212
212213 if ( ! await cli . doesServerSupportUnstableFeature ( "org.matrix.e2e_cross_signing" ) ) return ;
@@ -235,7 +236,7 @@ export default class DeviceListener {
235236 // Cross-signing on account but this device doesn't trust the master key (verify this session)
236237 showSetupEncryptionToast ( SetupKind . VERIFY_THIS_SESSION ) ;
237238 } else {
238- const backupInfo = await this . _getKeyBackupInfo ( ) ;
239+ const backupInfo = await this . getKeyBackupInfo ( ) ;
239240 if ( backupInfo ) {
240241 // No cross-signing on account but key backup available (upgrade encryption)
241242 showSetupEncryptionToast ( SetupKind . UPGRADE_ENCRYPTION ) ;
@@ -256,7 +257,7 @@ export default class DeviceListener {
256257
257258 // This needs to be done after awaiting on downloadKeys() above, so
258259 // we make sure we get the devices after the fetch is done.
259- this . _ensureDeviceIdsAtStartPopulated ( ) ;
260+ this . ensureDeviceIdsAtStartPopulated ( ) ;
260261
261262 // Unverified devices that were there last time the app ran
262263 // (technically could just be a boolean: we don't actually
0 commit comments