@@ -262,14 +262,15 @@ export class CloudSocialProvider {
262262 }
263263
264264 // Saves contacts to storage.
265- private saveContacts_ = ( ) => {
265+ private saveContacts_ = ( ) : Promise < void > => {
266266 log . debug ( 'saveContacts' ) ;
267- this . storage_ . set ( STORAGE_KEY , JSON . stringify ( < SavedContacts > {
267+ return this . storage_ . set ( STORAGE_KEY , JSON . stringify ( < SavedContacts > {
268268 contacts : Object . keys ( this . savedContacts_ ) . map ( key => this . savedContacts_ [ key ] )
269269 } ) ) . then ( ( unused : string ) => {
270270 log . debug ( 'saved contacts' ) ;
271- } , ( e : Error ) => {
271+ } ) . catch ( ( e ) => {
272272 log . error ( 'could not save contacts: %1' , e ) ;
273+ Promise . reject ( e ) ;
273274 } ) ;
274275 }
275276
@@ -391,9 +392,19 @@ export class CloudSocialProvider {
391392 new Error ( 'blockUser unimplemented' ) ) ;
392393 }
393394
394- public removeUser = ( userId : string ) : Promise < void > => {
395- return Promise . reject (
396- new Error ( 'removeUser unimplemented' ) ) ;
395+ // Removes a cloud contact from storage
396+ public removeUser = ( host : string ) : Promise < void > => {
397+ log . debug ( 'removeUser %1' , host ) ;
398+ if ( ! ( host in this . savedContacts_ ) ) {
399+ // Do not return an error because result is as expected.
400+ log . warn ( 'cloud contact %1 is not in %2 - cannot remove from storage' , host , STORAGE_KEY ) ;
401+ return Promise . resolve < void > ( ) ;
402+ }
403+ // Remove host from savedContacts and clients
404+ delete this . savedContacts_ [ host ] ;
405+ delete this . clients_ [ host ] ;
406+ // Update storage with this.savedContacts_
407+ return this . saveContacts_ ( ) ;
397408 }
398409}
399410
0 commit comments