diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2017-11-17 10:51:41 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2017-11-21 16:13:19 +0100 |
| commit | 3c1e0d96705532674b513b77d0a89c1f86e458dd (patch) | |
| tree | 2633ce0811683aa40339d21a246bb7358030f790 /app/lib | |
| parent | aeaf89a7cefa03bf94300c48ea4371dd15d9d0bb (diff) | |
| download | mullvadvpn-3c1e0d96705532674b513b77d0a89c1f86e458dd.tar.xz mullvadvpn-3c1e0d96705532674b513b77d0a89c1f86e458dd.zip | |
Add account history IPC
Diffstat (limited to 'app/lib')
| -rw-r--r-- | app/lib/backend.js | 25 | ||||
| -rw-r--r-- | app/lib/ipc-facade.js | 19 |
2 files changed, 42 insertions, 2 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js index fc2348961a..4dd389d759 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -161,6 +161,8 @@ export class Backend { log.info('Failed getting new location,', e.message); }); }); + + this._updateAccountHistory(); } serverInfo(identifier: string): ?ServerInfo { @@ -204,7 +206,7 @@ export class Backend { // TODO: This is not true. If there is a communication link failure the promise will be rejected too const err = new BackendError('INVALID_ACCOUNT'); this._store.dispatch(accountActions.loginFailed(err)); - }); + }).then(() => this._updateAccountHistory()); }); } @@ -248,7 +250,6 @@ export class Backend { .then( () => { return this._ipc.setAccount(null) .then(() => { - this._store.dispatch(accountActions.loggedOut()); // disconnect user during logout @@ -333,6 +334,26 @@ export class Backend { }); } + removeAccountFromHistory(accountToken: AccountToken): Promise<void> { + return this._ensureAuthenticated() + .then(() => this._ipc.removeAccountFromHistory(accountToken)) + .then(() => this._updateAccountHistory()) + .catch(e => { + log.error('Failed to remove account token from history', e.message); + }); + } + + _updateAccountHistory(): Promise<void> { + return this._ensureAuthenticated() + .then(() => this._ipc.getAccountHistory()) + .then((accountHistory) => { + this._store.dispatch( + accountActions.updateAccountHistory(accountHistory) + ); + }) + .catch(e => log.info('Failed to fetch account history,', e.message)); + } + _apiToReduxConstraints(constraint: *): * { if (typeof(constraint) === 'object') { return constraint.only; diff --git a/app/lib/ipc-facade.js b/app/lib/ipc-facade.js index 6cd224a441..143a2c0630 100644 --- a/app/lib/ipc-facade.js +++ b/app/lib/ipc-facade.js @@ -73,6 +73,8 @@ export interface IpcFacade { registerStateListener((BackendState) => void): void, setCloseConnectionHandler(() => void): void, authenticate(sharedSecret: string): Promise<void>, + getAccountHistory(): Promise<Array<AccountToken>>, + removeAccountFromHistory(accountToken: AccountToken): Promise<void>, } export class RealIpc implements IpcFacade { @@ -218,4 +220,21 @@ export class RealIpc implements IpcFacade { return this._ipc.send('auth', sharedSecret) .then(this._ignoreResponse); } + + getAccountHistory(): Promise<Array<AccountToken>> { + return this._ipc.send('get_account_history') + .then(raw => { + if(Array.isArray(raw) && raw.every(i => typeof i === 'string')) { + const checked: any = raw; + return (checked: Array<AccountToken>); + } else { + throw new InvalidReply(raw, 'Expected an array of strings'); + } + }); + } + + removeAccountFromHistory(accountToken: AccountToken): Promise<void> { + return this._ipc.send('remove_account_from_history', accountToken) + .then(this._ignoreResponse); + } } |
