@@ -17,6 +17,9 @@ limitations under the License.
1717import isIp from "is-ip" ;
1818import * as utils from "matrix-js-sdk/src/utils" ;
1919import { Room } from "matrix-js-sdk/src/models/room" ;
20+ import { EventType } from "matrix-js-sdk/src/@types/event" ;
21+ import { MatrixEvent } from "matrix-js-sdk/src/models/event" ;
22+ import { RoomMember } from "matrix-js-sdk/src/models/room-member" ;
2023
2124import { MatrixClientPeg } from "../../MatrixClientPeg" ;
2225import SpecPermalinkConstructor , { baseUrl as matrixtoBaseUrl } from "./SpecPermalinkConstructor" ;
@@ -99,9 +102,6 @@ export class RoomPermalinkCreator {
99102 if ( ! this . roomId ) {
100103 throw new Error ( "Failed to resolve a roomId for the permalink creator to use" ) ;
101104 }
102-
103- this . onMembership = this . onMembership . bind ( this ) ;
104- this . onRoomState = this . onRoomState . bind ( this ) ;
105105 }
106106
107107 load ( ) {
@@ -140,11 +140,11 @@ export class RoomPermalinkCreator {
140140 return this . started ;
141141 }
142142
143- forEvent ( eventId ) {
143+ forEvent ( eventId : string ) : string {
144144 return getPermalinkConstructor ( ) . forEvent ( this . roomId , eventId , this . _serverCandidates ) ;
145145 }
146146
147- forShareableRoom ( ) {
147+ forShareableRoom ( ) : string {
148148 if ( this . room ) {
149149 // Prefer to use canonical alias for permalink if possible
150150 const alias = this . room . getCanonicalAlias ( ) ;
@@ -155,26 +155,26 @@ export class RoomPermalinkCreator {
155155 return getPermalinkConstructor ( ) . forRoom ( this . roomId , this . _serverCandidates ) ;
156156 }
157157
158- forRoom ( ) {
158+ forRoom ( ) : string {
159159 return getPermalinkConstructor ( ) . forRoom ( this . roomId , this . _serverCandidates ) ;
160160 }
161161
162- private onRoomState ( event ) {
162+ private onRoomState = ( event : MatrixEvent ) => {
163163 switch ( event . getType ( ) ) {
164- case "m.room.server_acl" :
164+ case EventType . RoomServerAcl :
165165 this . updateAllowedServers ( ) ;
166166 this . updateHighestPlUser ( ) ;
167167 this . updatePopulationMap ( ) ;
168168 this . updateServerCandidates ( ) ;
169169 return ;
170- case "m.room.power_levels" :
170+ case EventType . RoomPowerLevels :
171171 this . updateHighestPlUser ( ) ;
172172 this . updateServerCandidates ( ) ;
173173 return ;
174174 }
175175 }
176176
177- private onMembership ( evt , member , oldMembership ) {
177+ private onMembership = ( evt : MatrixEvent , member : RoomMember , oldMembership : string ) => {
178178 const userId = member . userId ;
179179 const membership = member . membership ;
180180 const serverName = getServerName ( userId ) ;
@@ -282,11 +282,11 @@ export function makeGenericPermalink(entityId: string): string {
282282 return getPermalinkConstructor ( ) . forEntity ( entityId ) ;
283283}
284284
285- export function makeUserPermalink ( userId ) {
285+ export function makeUserPermalink ( userId : string ) : string {
286286 return getPermalinkConstructor ( ) . forUser ( userId ) ;
287287}
288288
289- export function makeRoomPermalink ( roomId ) {
289+ export function makeRoomPermalink ( roomId : string ) : string {
290290 if ( ! roomId ) {
291291 throw new Error ( "can't permalink a falsey roomId" ) ;
292292 }
@@ -305,7 +305,7 @@ export function makeRoomPermalink(roomId) {
305305 return permalinkCreator . forRoom ( ) ;
306306}
307307
308- export function makeGroupPermalink ( groupId ) {
308+ export function makeGroupPermalink ( groupId : string ) : string {
309309 return getPermalinkConstructor ( ) . forGroup ( groupId ) ;
310310}
311311
@@ -437,24 +437,24 @@ export function parseAppLocalLink(localLink: string): PermalinkParts {
437437 return null ;
438438}
439439
440- function getServerName ( userId ) {
440+ function getServerName ( userId : string ) : string {
441441 return userId . split ( ":" ) . splice ( 1 ) . join ( ":" ) ;
442442}
443443
444- function getHostnameFromMatrixDomain ( domain ) {
444+ function getHostnameFromMatrixDomain ( domain : string ) : string {
445445 if ( ! domain ) return null ;
446446 return new URL ( `https://${ domain } ` ) . hostname ;
447447}
448448
449- function isHostInRegex ( hostname , regexps ) {
449+ function isHostInRegex ( hostname : string , regexps : RegExp [ ] ) {
450450 hostname = getHostnameFromMatrixDomain ( hostname ) ;
451451 if ( ! hostname ) return true ; // assumed
452- if ( regexps . length > 0 && ! regexps [ 0 ] . test ) throw new Error ( regexps [ 0 ] ) ;
452+ if ( regexps . length > 0 && ! regexps [ 0 ] . test ) throw new Error ( regexps [ 0 ] . toString ( ) ) ;
453453
454454 return regexps . filter ( h => h . test ( hostname ) ) . length > 0 ;
455455}
456456
457- function isHostnameIpAddress ( hostname ) {
457+ function isHostnameIpAddress ( hostname : string ) : boolean {
458458 hostname = getHostnameFromMatrixDomain ( hostname ) ;
459459 if ( ! hostname ) return false ;
460460
0 commit comments