@@ -308,6 +308,16 @@ class ParseUser extends ParseObject {
308
308
return ! ! current && current . id === this . id ;
309
309
}
310
310
311
+ /**
312
+ * Returns true if < code > current</ code > would return this user.
313
+ *
314
+ * @returns { Promise < boolean > } true if user is cached on disk
315
+ */
316
+ async isCurrentAsync(): Promise< boolean > {
317
+ const current = await ParseUser . currentAsync ( ) ;
318
+ return ! ! current && current . id === this . id ;
319
+ }
320
+
311
321
/**
312
322
* Returns get("username").
313
323
*
@@ -458,13 +468,13 @@ class ParseUser extends ParseObject {
458
468
* @param {...any } args
459
469
* @returns {Promise }
460
470
*/
461
- save ( ...args : Array < any > ): Promise< ParseUser > {
462
- return super . save . apply ( this , args ) . then ( ( ) => {
463
- if ( this . isCurrent ( ) ) {
464
- return CoreManager . getUserController ( ) . updateUserOnDisk ( this ) ;
465
- }
466
- return this ;
467
- } ) ;
471
+ async save ( ...args : Array < any > ): Promise< ParseUser > {
472
+ await super . save . apply ( this , args ) ;
473
+ const current = await this . isCurrentAsync ( ) ;
474
+ if ( current ) {
475
+ return CoreManager . getUserController ( ) . updateUserOnDisk ( this ) ;
476
+ }
477
+ return this ;
468
478
}
469
479
470
480
/**
@@ -474,13 +484,13 @@ class ParseUser extends ParseObject {
474
484
* @param { ...any } args
475
485
* @returns { Parse . User }
476
486
*/
477
- destroy(...args: Array< any > ): Promise< ParseUser > {
478
- return super . destroy . apply ( this , args ) . then ( ( ) => {
479
- if ( this . isCurrent ( ) ) {
480
- return CoreManager . getUserController ( ) . removeUserFromDisk ( ) ;
481
- }
482
- return this ;
483
- } ) ;
487
+ async destroy(...args: Array< any > ): Promise< ParseUser > {
488
+ await super . destroy . apply ( this , args ) ;
489
+ const current = await this . isCurrentAsync ( ) ;
490
+ if ( current ) {
491
+ return CoreManager . getUserController ( ) . removeUserFromDisk ( ) ;
492
+ }
493
+ return this ;
484
494
}
485
495
486
496
/**
@@ -490,13 +500,13 @@ class ParseUser extends ParseObject {
490
500
* @param { ...any } args
491
501
* @returns { Parse . User }
492
502
*/
493
- fetch(...args: Array< any > ): Promise< ParseUser > {
494
- return super . fetch . apply ( this , args ) . then ( ( ) => {
495
- if ( this . isCurrent ( ) ) {
496
- return CoreManager . getUserController ( ) . updateUserOnDisk ( this ) ;
497
- }
498
- return this ;
499
- } ) ;
503
+ async fetch(...args: Array< any > ): Promise< ParseUser > {
504
+ await super . fetch . apply ( this , args ) ;
505
+ const current = await this . isCurrentAsync ( ) ;
506
+ if ( current ) {
507
+ return CoreManager . getUserController ( ) . updateUserOnDisk ( this ) ;
508
+ }
509
+ return this ;
500
510
}
501
511
502
512
/**
@@ -506,13 +516,13 @@ class ParseUser extends ParseObject {
506
516
* @param { ...any } args
507
517
* @returns { Parse . User }
508
518
*/
509
- fetchWithInclude(...args: Array< any > ): Promise< ParseUser > {
510
- return super . fetchWithInclude . apply ( this , args ) . then ( ( ) => {
511
- if ( this . isCurrent ( ) ) {
512
- return CoreManager . getUserController ( ) . updateUserOnDisk ( this ) ;
513
- }
514
- return this ;
515
- } ) ;
519
+ async fetchWithInclude(...args: Array< any > ): Promise< ParseUser > {
520
+ await super . fetchWithInclude . apply ( this , args ) ;
521
+ const current = await this . isCurrentAsync ( ) ;
522
+ if ( current ) {
523
+ return CoreManager . getUserController ( ) . updateUserOnDisk ( this ) ;
524
+ }
525
+ return this ;
516
526
}
517
527
518
528
/**
@@ -1161,7 +1171,7 @@ const DefaultController = {
1161
1171
return RESTController . request ( 'POST' , 'requestPasswordReset' , { email : email } , options ) ;
1162
1172
} ,
1163
1173
1164
- upgradeToRevocableSession ( user : ParseUser , options : RequestOptions ) {
1174
+ async upgradeToRevocableSession ( user : ParseUser , options : RequestOptions ) {
1165
1175
const token = user . getSessionToken ( ) ;
1166
1176
if ( ! token ) {
1167
1177
return Promise . reject (
@@ -1172,15 +1182,15 @@ const DefaultController = {
1172
1182
options . sessionToken = token ;
1173
1183
1174
1184
const RESTController = CoreManager . getRESTController ( ) ;
1175
- return RESTController . request ( 'POST' , 'upgradeToRevocableSession' , { } , options ) . then ( result => {
1176
- const session = new ParseSession ( ) ;
1177
- session . _finishFetch ( result ) ;
1178
- user . _finishFetch ( { sessionToken : session . getSessionToken ( ) } ) ;
1179
- if ( user . isCurrent ( ) ) {
1180
- return DefaultController . setCurrentUser ( user ) ;
1181
- }
1182
- return Promise . resolve ( user ) ;
1183
- } ) ;
1185
+ const result = await RESTController . request ( 'POST' , 'upgradeToRevocableSession' , { } , options ) ;
1186
+ const session = new ParseSession ( ) ;
1187
+ session . _finishFetch ( result ) ;
1188
+ user . _finishFetch ( { sessionToken : session . getSessionToken ( ) } ) ;
1189
+ const current = await user . isCurrentAsync ( ) ;
1190
+ if ( current ) {
1191
+ return DefaultController . setCurrentUser ( user ) ;
1192
+ }
1193
+ return Promise . resolve ( user ) ;
1184
1194
} ,
1185
1195
1186
1196
linkWith ( user : ParseUser , authData : AuthData , options : FullOptions ) {
0 commit comments