@@ -308,6 +308,16 @@ class ParseUser extends ParseObject {
308308 return ! ! current && current . id === this . id ;
309309 }
310310
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+
311321 /**
312322 * Returns get("username").
313323 *
@@ -458,13 +468,13 @@ class ParseUser extends ParseObject {
458468 * @param {...any } args
459469 * @returns {Promise }
460470 */
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 ;
468478 }
469479
470480 /**
@@ -474,13 +484,13 @@ class ParseUser extends ParseObject {
474484 * @param { ...any } args
475485 * @returns { Parse . User }
476486 */
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 ;
484494 }
485495
486496 /**
@@ -490,13 +500,13 @@ class ParseUser extends ParseObject {
490500 * @param { ...any } args
491501 * @returns { Parse . User }
492502 */
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 ;
500510 }
501511
502512 /**
@@ -506,13 +516,13 @@ class ParseUser extends ParseObject {
506516 * @param { ...any } args
507517 * @returns { Parse . User }
508518 */
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 ;
516526 }
517527
518528 /**
@@ -1161,7 +1171,7 @@ const DefaultController = {
11611171 return RESTController . request ( 'POST' , 'requestPasswordReset' , { email : email } , options ) ;
11621172 } ,
11631173
1164- upgradeToRevocableSession ( user : ParseUser , options : RequestOptions ) {
1174+ async upgradeToRevocableSession ( user : ParseUser , options : RequestOptions ) {
11651175 const token = user . getSessionToken ( ) ;
11661176 if ( ! token ) {
11671177 return Promise . reject (
@@ -1172,15 +1182,15 @@ const DefaultController = {
11721182 options . sessionToken = token ;
11731183
11741184 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 ) ;
11841194 } ,
11851195
11861196 linkWith ( user : ParseUser , authData : AuthData , options : FullOptions ) {
0 commit comments