@@ -25,6 +25,8 @@ import { JoinedRoom as JoinedRoomEvent } from "matrix-analytics-events/types/typ
25
25
import { JoinRule } from "matrix-js-sdk/src/@types/partials" ;
26
26
import { Room } from "matrix-js-sdk/src/models/room" ;
27
27
import { ClientEvent } from "matrix-js-sdk/src/client" ;
28
+ import { MatrixEvent } from "matrix-js-sdk/src/models/event" ;
29
+ import { Optional } from "matrix-events-sdk" ;
28
30
29
31
import dis from '../dispatcher/dispatcher' ;
30
32
import { MatrixClientPeg } from '../MatrixClientPeg' ;
@@ -53,30 +55,30 @@ const INITIAL_STATE = {
53
55
// Whether we're joining the currently viewed room (see isJoining())
54
56
joining : false ,
55
57
// Any error that has occurred during joining
56
- joinError : null ,
58
+ joinError : null as Error ,
57
59
// The room ID of the room currently being viewed
58
- roomId : null ,
60
+ roomId : null as string ,
59
61
60
62
// The event to scroll to when the room is first viewed
61
- initialEventId : null ,
62
- initialEventPixelOffset : null ,
63
+ initialEventId : null as string ,
64
+ initialEventPixelOffset : null as number ,
63
65
// Whether to highlight the initial event
64
66
isInitialEventHighlighted : false ,
65
67
// whether to scroll `event_id` into view
66
68
initialEventScrollIntoView : true ,
67
69
68
70
// The room alias of the room (or null if not originally specified in view_room)
69
- roomAlias : null ,
71
+ roomAlias : null as string ,
70
72
// Whether the current room is loading
71
73
roomLoading : false ,
72
74
// Any error that has occurred during loading
73
- roomLoadError : null ,
75
+ roomLoadError : null as MatrixError ,
74
76
75
- replyingToEvent : null ,
77
+ replyingToEvent : null as MatrixEvent ,
76
78
77
79
shouldPeek : false ,
78
80
79
- viaServers : [ ] ,
81
+ viaServers : [ ] as string [ ] ,
80
82
81
83
wasContextSwitch : false ,
82
84
} ;
@@ -103,12 +105,12 @@ export class RoomViewStore extends Store<ActionPayload> {
103
105
super ( dis ) ;
104
106
}
105
107
106
- public addRoomListener ( roomId : string , fn : Listener ) {
108
+ public addRoomListener ( roomId : string , fn : Listener ) : void {
107
109
if ( ! this . roomIdActivityListeners [ roomId ] ) this . roomIdActivityListeners [ roomId ] = [ ] ;
108
110
this . roomIdActivityListeners [ roomId ] . push ( fn ) ;
109
111
}
110
112
111
- public removeRoomListener ( roomId : string , fn : Listener ) {
113
+ public removeRoomListener ( roomId : string , fn : Listener ) : void {
112
114
if ( this . roomIdActivityListeners [ roomId ] ) {
113
115
const i = this . roomIdActivityListeners [ roomId ] . indexOf ( fn ) ;
114
116
if ( i > - 1 ) {
@@ -119,15 +121,15 @@ export class RoomViewStore extends Store<ActionPayload> {
119
121
}
120
122
}
121
123
122
- private emitForRoom ( roomId : string , isActive : boolean ) {
124
+ private emitForRoom ( roomId : string , isActive : boolean ) : void {
123
125
if ( ! this . roomIdActivityListeners [ roomId ] ) return ;
124
126
125
127
for ( const fn of this . roomIdActivityListeners [ roomId ] ) {
126
128
fn . call ( null , isActive ) ;
127
129
}
128
130
}
129
131
130
- private setState ( newState : Partial < typeof INITIAL_STATE > ) {
132
+ private setState ( newState : Partial < typeof INITIAL_STATE > ) : void {
131
133
// If values haven't changed, there's nothing to do.
132
134
// This only tries a shallow comparison, so unchanged objects will slip
133
135
// through, but that's probably okay for now.
@@ -160,7 +162,7 @@ export class RoomViewStore extends Store<ActionPayload> {
160
162
this . __emitChange ( ) ;
161
163
}
162
164
163
- protected __onDispatch ( payload ) { // eslint-disable-line @typescript-eslint/naming-convention
165
+ protected __onDispatch ( payload ) : void { // eslint-disable-line @typescript-eslint/naming-convention
164
166
switch ( payload . action ) {
165
167
// view_room:
166
168
// - room_alias: '#somealias:matrix.org'
@@ -367,7 +369,7 @@ export class RoomViewStore extends Store<ActionPayload> {
367
369
}
368
370
}
369
371
370
- private viewRoomError ( payload : ViewRoomErrorPayload ) {
372
+ private viewRoomError ( payload : ViewRoomErrorPayload ) : void {
371
373
this . setState ( {
372
374
roomId : payload . room_id ,
373
375
roomAlias : payload . room_alias ,
@@ -376,7 +378,7 @@ export class RoomViewStore extends Store<ActionPayload> {
376
378
} ) ;
377
379
}
378
380
379
- private async joinRoom ( payload : JoinRoomPayload ) {
381
+ private async joinRoom ( payload : JoinRoomPayload ) : Promise < void > {
380
382
this . setState ( {
381
383
joining : true ,
382
384
} ) ;
@@ -415,14 +417,14 @@ export class RoomViewStore extends Store<ActionPayload> {
415
417
private getInvitingUserId ( roomId : string ) : string {
416
418
const cli = MatrixClientPeg . get ( ) ;
417
419
const room = cli . getRoom ( roomId ) ;
418
- if ( room && room . getMyMembership ( ) === "invite" ) {
420
+ if ( room ? .getMyMembership ( ) === "invite" ) {
419
421
const myMember = room . getMember ( cli . getUserId ( ) ) ;
420
422
const inviteEvent = myMember ? myMember . events . member : null ;
421
423
return inviteEvent && inviteEvent . getSender ( ) ;
422
424
}
423
425
}
424
426
425
- public showJoinRoomError ( err : MatrixError , roomId : string ) {
427
+ public showJoinRoomError ( err : MatrixError , roomId : string ) : void {
426
428
let description : ReactNode = err . message ? err . message : JSON . stringify ( err ) ;
427
429
logger . log ( "Failed to join room:" , description ) ;
428
430
@@ -452,50 +454,50 @@ export class RoomViewStore extends Store<ActionPayload> {
452
454
} ) ;
453
455
}
454
456
455
- private joinRoomError ( payload : JoinRoomErrorPayload ) {
457
+ private joinRoomError ( payload : JoinRoomErrorPayload ) : void {
456
458
this . setState ( {
457
459
joining : false ,
458
460
joinError : payload . err ,
459
461
} ) ;
460
462
this . showJoinRoomError ( payload . err , payload . roomId ) ;
461
463
}
462
464
463
- public reset ( ) {
465
+ public reset ( ) : void {
464
466
this . state = Object . assign ( { } , INITIAL_STATE ) ;
465
467
}
466
468
467
469
// The room ID of the room currently being viewed
468
- public getRoomId ( ) {
470
+ public getRoomId ( ) : Optional < string > {
469
471
return this . state . roomId ;
470
472
}
471
473
472
474
// The event to scroll to when the room is first viewed
473
- public getInitialEventId ( ) {
475
+ public getInitialEventId ( ) : Optional < string > {
474
476
return this . state . initialEventId ;
475
477
}
476
478
477
479
// Whether to highlight the initial event
478
- public isInitialEventHighlighted ( ) {
480
+ public isInitialEventHighlighted ( ) : boolean {
479
481
return this . state . isInitialEventHighlighted ;
480
482
}
481
483
482
484
// Whether to avoid jumping to the initial event
483
- public initialEventScrollIntoView ( ) {
485
+ public initialEventScrollIntoView ( ) : boolean {
484
486
return this . state . initialEventScrollIntoView ;
485
487
}
486
488
487
489
// The room alias of the room (or null if not originally specified in view_room)
488
- public getRoomAlias ( ) {
490
+ public getRoomAlias ( ) : Optional < string > {
489
491
return this . state . roomAlias ;
490
492
}
491
493
492
494
// Whether the current room is loading (true whilst resolving an alias)
493
- public isRoomLoading ( ) {
495
+ public isRoomLoading ( ) : boolean {
494
496
return this . state . roomLoading ;
495
497
}
496
498
497
499
// Any error that has occurred during loading
498
- public getRoomLoadError ( ) {
500
+ public getRoomLoadError ( ) : Optional < MatrixError > {
499
501
return this . state . roomLoadError ;
500
502
}
501
503
@@ -522,25 +524,25 @@ export class RoomViewStore extends Store<ActionPayload> {
522
524
// // show join prompt
523
525
// }
524
526
// }
525
- public isJoining ( ) {
527
+ public isJoining ( ) : boolean {
526
528
return this . state . joining ;
527
529
}
528
530
529
531
// Any error that has occurred during joining
530
- public getJoinError ( ) {
532
+ public getJoinError ( ) : Optional < Error > {
531
533
return this . state . joinError ;
532
534
}
533
535
534
536
// The mxEvent if one is currently being replied to/quoted
535
- public getQuotingEvent ( ) {
537
+ public getQuotingEvent ( ) : Optional < MatrixEvent > {
536
538
return this . state . replyingToEvent ;
537
539
}
538
540
539
- public shouldPeek ( ) {
541
+ public shouldPeek ( ) : boolean {
540
542
return this . state . shouldPeek ;
541
543
}
542
544
543
- public getWasContextSwitch ( ) {
545
+ public getWasContextSwitch ( ) : boolean {
544
546
return this . state . wasContextSwitch ;
545
547
}
546
548
}
0 commit comments