mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
support deleting the session from the container
This commit is contained in:
parent
de7dcf6a40
commit
bb7fca0592
@ -39,6 +39,8 @@ export class SessionContainer {
|
|||||||
this._reconnector = null;
|
this._reconnector = null;
|
||||||
this._session = null;
|
this._session = null;
|
||||||
this._sync = null;
|
this._sync = null;
|
||||||
|
this._sessionId = null;
|
||||||
|
this._storage = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_createNewSessionId() {
|
_createNewSessionId() {
|
||||||
@ -119,17 +121,18 @@ export class SessionContainer {
|
|||||||
request: this._request,
|
request: this._request,
|
||||||
reconnector: this._reconnector,
|
reconnector: this._reconnector,
|
||||||
});
|
});
|
||||||
const storage = await this._storageFactory.create(sessionInfo.id);
|
this._sessionId = sessionInfo.id;
|
||||||
|
this._storage = await this._storageFactory.create(sessionInfo.id);
|
||||||
// no need to pass access token to session
|
// no need to pass access token to session
|
||||||
const filteredSessionInfo = {
|
const filteredSessionInfo = {
|
||||||
deviceId: sessionInfo.deviceId,
|
deviceId: sessionInfo.deviceId,
|
||||||
userId: sessionInfo.userId,
|
userId: sessionInfo.userId,
|
||||||
homeServer: sessionInfo.homeServer,
|
homeServer: sessionInfo.homeServer,
|
||||||
};
|
};
|
||||||
this._session = new Session({storage, sessionInfo: filteredSessionInfo, hsApi});
|
this._session = new Session({storage: this._storage, sessionInfo: filteredSessionInfo, hsApi});
|
||||||
await this._session.load();
|
await this._session.load();
|
||||||
|
|
||||||
this._sync = new Sync({hsApi, storage, session: this._session});
|
this._sync = new Sync({hsApi, storage: this._storage, session: this._session});
|
||||||
// notify sync and session when back online
|
// notify sync and session when back online
|
||||||
this._reconnectSubscription = this._reconnector.connectionStatus.subscribe(state => {
|
this._reconnectSubscription = this._reconnector.connectionStatus.subscribe(state => {
|
||||||
if (state === ConnectionStatus.Online) {
|
if (state === ConnectionStatus.Online) {
|
||||||
@ -206,6 +209,21 @@ export class SessionContainer {
|
|||||||
this._waitForFirstSyncHandle.dispose();
|
this._waitForFirstSyncHandle.dispose();
|
||||||
this._waitForFirstSyncHandle = null;
|
this._waitForFirstSyncHandle = null;
|
||||||
}
|
}
|
||||||
|
if (this._storage) {
|
||||||
|
this._storage.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteSession() {
|
||||||
|
if (this._sessionId) {
|
||||||
|
// if one fails, don't block the other from trying
|
||||||
|
// also, run in parallel
|
||||||
|
await Promise.all([
|
||||||
|
this._storageFactory.delete(this._sessionId),
|
||||||
|
this._sessionInfoStorage.delete(this._sessionId),
|
||||||
|
]);
|
||||||
|
this._sessionId = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,4 +37,8 @@ export class Storage {
|
|||||||
throw new StorageError("readWriteTxn failed", err);
|
throw new StorageError("readWriteTxn failed", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this._db.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user