fix(core): allow storage reset to be async

This commit is contained in:
alina 🌸 2023-12-19 23:39:22 +03:00
parent f4ab514b18
commit c538c2b059
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
3 changed files with 4 additions and 4 deletions

View file

@ -21,7 +21,7 @@ export async function logOut(client: BaseTelegramClient): Promise<true> {
client.emit('logged_out') client.emit('logged_out')
client.storage.reset() await client.storage.reset()
await client.saveStorage() await client.saveStorage()
return true return true

View file

@ -82,7 +82,7 @@ export interface ITelegramStorage {
* *
* @param [withAuthKeys=false] Whether to also reset auth keys * @param [withAuthKeys=false] Whether to also reset auth keys
*/ */
reset(withAuthKeys?: boolean): void reset(withAuthKeys?: boolean): MaybeAsync<void>
/** /**
* Set default datacenter to use with this session. * Set default datacenter to use with this session.

View file

@ -160,7 +160,7 @@ export function testStorage<T extends ITelegramStorage>(
it('should not reset auth keys on reset()', async () => { it('should not reset auth keys on reset()', async () => {
await s.setAuthKeyFor(2, key2) await s.setAuthKeyFor(2, key2)
await s.setAuthKeyFor(3, key3) await s.setAuthKeyFor(3, key3)
s.reset() await s.reset()
expect(maybeHexEncode(await s.getAuthKeyFor(2))).toEqual(hexEncode(key2)) expect(maybeHexEncode(await s.getAuthKeyFor(2))).toEqual(hexEncode(key2))
expect(maybeHexEncode(await s.getAuthKeyFor(3))).toEqual(hexEncode(key3)) expect(maybeHexEncode(await s.getAuthKeyFor(3))).toEqual(hexEncode(key3))
@ -169,7 +169,7 @@ export function testStorage<T extends ITelegramStorage>(
it('should reset auth keys on reset(true)', async () => { it('should reset auth keys on reset(true)', async () => {
await s.setAuthKeyFor(2, key2) await s.setAuthKeyFor(2, key2)
await s.setAuthKeyFor(3, key3) await s.setAuthKeyFor(3, key3)
s.reset(true) await s.reset(true)
expect(await s.getAuthKeyFor(2)).toBeNull() expect(await s.getAuthKeyFor(2)).toBeNull()
expect(await s.getAuthKeyFor(3)).toBeNull() expect(await s.getAuthKeyFor(3)).toBeNull()