mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
add helper function for removing contact
This commit is contained in:
parent
fdc83c2f78
commit
2e3ecdb15e
2 changed files with 32 additions and 1 deletions
|
|
@ -352,7 +352,7 @@
|
|||
}
|
||||
|
||||
// remove contact from device
|
||||
await this.connection.sendCommandRemoveContact(contact.publicKey);
|
||||
await this.connection.removeContact(contact.publicKey);
|
||||
|
||||
// reload contacts
|
||||
await this.loadContacts();
|
||||
|
|
|
|||
|
|
@ -788,6 +788,37 @@ class Connection extends EventEmitter {
|
|||
});
|
||||
}
|
||||
|
||||
removeContact(pubKey) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
|
||||
// resolve promise when we receive ok
|
||||
const onOk = () => {
|
||||
this.off(Constants.ResponseCodes.Ok, onOk);
|
||||
this.off(Constants.ResponseCodes.Err, onErr);
|
||||
resolve();
|
||||
}
|
||||
|
||||
// reject promise when we receive err
|
||||
const onErr = () => {
|
||||
this.off(Constants.ResponseCodes.Ok, onOk);
|
||||
this.off(Constants.ResponseCodes.Err, onErr);
|
||||
reject();
|
||||
}
|
||||
|
||||
// listen for events
|
||||
this.once(Constants.ResponseCodes.Ok, onOk);
|
||||
this.once(Constants.ResponseCodes.Err, onErr);
|
||||
|
||||
// remove contact
|
||||
await this.sendCommandRemoveContact(pubKey);
|
||||
|
||||
} catch(e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Connection;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue