@@ -15,7 +15,7 @@ export class RealtimeClientConnection {
1515 this . realtime = require ( './realtime' )
1616 }
1717
18- registerEventHandler ( ) {
18+ registerEventHandler ( ) : void {
1919 // received client refresh request
2020 this . socket . on ( 'refresh' , this . refreshEventHandler . bind ( this ) )
2121 // received user status
@@ -40,27 +40,27 @@ export class RealtimeClientConnection {
4040 this . socket . on ( 'permission' , this . permissionChangeEventHandler . bind ( this ) )
4141 }
4242
43- isUserLoggedIn ( ) {
43+ isUserLoggedIn ( ) : boolean {
4444 return this . socket . request . user && this . socket . request . user . logged_in
4545 }
4646
47- isNoteAndUserExists ( ) {
47+ isNoteAndUserExists ( ) : boolean {
4848 const note = this . realtime . getNoteFromNotePool ( this . socket . noteId )
4949 const user = this . realtime . getUserFromUserPool ( this . socket . id )
5050 return note && user
5151 }
5252
53- isNoteOwner ( ) {
53+ isNoteOwner ( ) : boolean {
5454 const note = this . getCurrentNote ( )
5555 return get ( note , 'owner' ) === this . getCurrentLoggedInUserId ( )
5656 }
5757
58- isAnonymousEnable ( ) {
58+ isAnonymousEnable ( ) : boolean {
5959 // TODO: move this method to config module
6060 return config . allowAnonymous || config . allowAnonymousEdits
6161 }
6262
63- getAvailablePermissions ( ) {
63+ getAvailablePermissions ( ) : string [ ] {
6464 // TODO: move this method to config module
6565 const availablePermission = Object . assign ( { } , config . permission )
6666 if ( ! config . allowAnonymous && ! config . allowAnonymousViews ) {
@@ -78,7 +78,7 @@ export class RealtimeClientConnection {
7878 return this . realtime . getUserFromUserPool ( this . socket . id )
7979 }
8080
81- getCurrentLoggedInUserId ( ) {
81+ getCurrentLoggedInUserId ( ) : string {
8282 return get ( this . socket , 'request.user.id' )
8383 }
8484
@@ -91,13 +91,13 @@ export class RealtimeClientConnection {
9191 return this . socket . broadcast . to ( this . socket . noteId )
9292 }
9393
94- async destroyNote ( id ) {
94+ async destroyNote ( id : string ) : Promise < number > {
9595 return Note . destroy ( {
9696 where : { id : id }
9797 } )
9898 }
9999
100- async changeNotePermission ( newPermission ) {
100+ async changeNotePermission ( newPermission : string ) : Promise < void > {
101101 const [ changedRows ] = await Note . update ( {
102102 permission : newPermission
103103 } , {
@@ -110,7 +110,7 @@ export class RealtimeClientConnection {
110110 }
111111 }
112112
113- notifyPermissionChanged ( ) {
113+ notifyPermissionChanged ( ) : void {
114114 this . realtime . io . to ( this . getCurrentNote ( ) . id ) . emit ( 'permission' , {
115115 permission : this . getCurrentNote ( ) . permission
116116 } )
@@ -128,11 +128,11 @@ export class RealtimeClientConnection {
128128 } )
129129 }
130130
131- refreshEventHandler ( ) {
131+ refreshEventHandler ( ) : void {
132132 this . realtime . emitRefresh ( this . socket )
133133 }
134134
135- checkVersionEventHandler ( ) {
135+ checkVersionEventHandler ( ) : void {
136136 this . socket . emit ( 'version' , {
137137 version : config . fullversion ,
138138 minimumCompatibleVersion : config . minimumCompatibleVersion
@@ -152,7 +152,7 @@ export class RealtimeClientConnection {
152152 this . realtime . emitUserStatus ( this . socket )
153153 }
154154
155- userChangedEventHandler ( ) {
155+ userChangedEventHandler ( ) : void {
156156 logger . info ( 'user changed' )
157157
158158 const note = this . getCurrentNote ( )
@@ -164,7 +164,7 @@ export class RealtimeClientConnection {
164164 this . realtime . emitOnlineUsers ( this . socket )
165165 }
166166
167- onlineUsersEventHandler ( ) {
167+ onlineUsersEventHandler ( ) : void {
168168 if ( ! this . isNoteAndUserExists ( ) ) return
169169
170170 const currentNote = this . getCurrentNote ( )
@@ -193,7 +193,7 @@ export class RealtimeClientConnection {
193193 this . getNoteChannel ( ) . emit ( 'cursor activity' , out )
194194 }
195195
196- cursorBlurEventHandler ( ) {
196+ cursorBlurEventHandler ( ) : void {
197197 if ( ! this . isNoteAndUserExists ( ) ) return
198198 const user = this . getCurrentUser ( )
199199 user . cursor = null
@@ -202,7 +202,7 @@ export class RealtimeClientConnection {
202202 } )
203203 }
204204
205- deleteNoteEventHandler ( ) {
205+ deleteNoteEventHandler ( ) : void {
206206 // need login to do more actions
207207 if ( this . isUserLoggedIn ( ) && this . isNoteAndUserExists ( ) ) {
208208 const note = this . getCurrentNote ( )
@@ -220,7 +220,7 @@ export class RealtimeClientConnection {
220220 }
221221 }
222222
223- permissionChangeEventHandler ( permission ) {
223+ permissionChangeEventHandler ( permission : string ) : void {
224224 if ( ! this . isUserLoggedIn ( ) ) return
225225 if ( ! this . isNoteAndUserExists ( ) ) return
226226
@@ -237,7 +237,7 @@ export class RealtimeClientConnection {
237237 . catch ( err => logger . error ( 'update note permission failed: ' + err ) )
238238 }
239239
240- disconnectEventHandler ( ) {
240+ disconnectEventHandler ( ) : void {
241241 if ( this . realtime . disconnectProcessQueue . checkTaskIsInQueue ( this . socket . id ) ) {
242242 return
243243 }
0 commit comments