Change Phone Number notifications

This commit is contained in:
Fedor Indutny 2021-08-05 16:34:49 -07:00 committed by GitHub
parent 4b82ac387b
commit a001882d58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 277 additions and 39 deletions

View file

@ -3,6 +3,7 @@
import { WebAPICredentials } from '../Types.d';
import { strictAssert } from '../../util/assert';
import { StorageInterface } from '../../types/Storage.d';
import Helpers from '../Helpers';
@ -27,6 +28,25 @@ export class User {
window.log.info('storage.user: uuid and device id changed');
}
public async setNumber(number: string): Promise<void> {
if (this.getNumber() === number) {
return;
}
const deviceId = this.getDeviceId();
strictAssert(
deviceId !== undefined,
'Cannot update device number without knowing device id'
);
window.log.info('storage.user: number changed');
await this.storage.put('number_id', `${number}.${deviceId}`);
// Notify redux about phone number change
window.Whisper.events.trigger('userChanged');
}
public getNumber(): string | undefined {
const numberId = this.storage.get('number_id');
if (numberId === undefined) return undefined;