add logout button in settings
This commit is contained in:
parent
2b884e73db
commit
f998041748
6 changed files with 55 additions and 10 deletions
|
@ -230,7 +230,7 @@ export class SessionViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
if (settingsOpen) {
|
if (settingsOpen) {
|
||||||
this._settingsViewModel = this.track(new SettingsViewModel(this.childOptions({
|
this._settingsViewModel = this.track(new SettingsViewModel(this.childOptions({
|
||||||
session: this._sessionContainer.session,
|
sessionContainer: this._sessionContainer,
|
||||||
})));
|
})));
|
||||||
this._settingsViewModel.load();
|
this._settingsViewModel.load();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,18 +41,36 @@ export class SettingsViewModel extends ViewModel {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
this._updateService = options.updateService;
|
this._updateService = options.updateService;
|
||||||
const session = options.session;
|
const {sessionContainer} = options;
|
||||||
this._session = session;
|
this._sessionContainer = sessionContainer;
|
||||||
this._sessionBackupViewModel = this.track(new SessionBackupViewModel(this.childOptions({session})));
|
this._sessionBackupViewModel = this.track(new SessionBackupViewModel(this.childOptions({session: this._session})));
|
||||||
this._closeUrl = this.urlCreator.urlUntilSegment("session");
|
this._closeUrl = this.urlCreator.urlUntilSegment("session");
|
||||||
this._estimate = null;
|
this._estimate = null;
|
||||||
|
|
||||||
this.sentImageSizeLimit = null;
|
this.sentImageSizeLimit = null;
|
||||||
this.minSentImageSizeLimit = 400;
|
this.minSentImageSizeLimit = 400;
|
||||||
this.maxSentImageSizeLimit = 4000;
|
this.maxSentImageSizeLimit = 4000;
|
||||||
this.pushNotifications = new PushNotificationStatus();
|
this.pushNotifications = new PushNotificationStatus();
|
||||||
|
this._isLoggingOut = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get _session() {
|
||||||
|
return this._sessionContainer.session;
|
||||||
|
}
|
||||||
|
|
||||||
|
logout() {
|
||||||
|
return this.logger.run("logout", async log => {
|
||||||
|
this._isLoggingOut = true;
|
||||||
|
this.emitChange("isLoggingOut");
|
||||||
|
try {
|
||||||
|
await this._session.logout(log);
|
||||||
|
} catch (err) {}
|
||||||
|
await this._sessionContainer.deleteSession(log);
|
||||||
|
this.navigation.push("session", true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get isLoggingOut() { return this._isLoggingOut; }
|
||||||
|
|
||||||
setSentImageSizeLimit(size) {
|
setSentImageSizeLimit(size) {
|
||||||
if (size > this.maxSentImageSizeLimit || size < this.minSentImageSizeLimit) {
|
if (size > this.maxSentImageSizeLimit || size < this.minSentImageSizeLimit) {
|
||||||
this.sentImageSizeLimit = null;
|
this.sentImageSizeLimit = null;
|
||||||
|
|
|
@ -106,6 +106,11 @@ export class Session {
|
||||||
return this._sessionInfo.userId;
|
return this._sessionInfo.userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async logout(log = undefined) {
|
||||||
|
const response = await this._hsApi.logout({log}).response();
|
||||||
|
console.log("logout", response);
|
||||||
|
}
|
||||||
|
|
||||||
// called once this._e2eeAccount is assigned
|
// called once this._e2eeAccount is assigned
|
||||||
_setupEncryption() {
|
_setupEncryption() {
|
||||||
// TODO: this should all go in a wrapper in e2ee/ that is bootstrapped by passing in the account
|
// TODO: this should all go in a wrapper in e2ee/ that is bootstrapped by passing in the account
|
||||||
|
|
|
@ -252,7 +252,9 @@ export class SessionContainer {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await log.wrap("wait first sync", () => this._waitForFirstSync());
|
await log.wrap("wait first sync", () => this._waitForFirstSync());
|
||||||
|
if (this._isDisposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._status.set(LoadStatus.Ready);
|
this._status.set(LoadStatus.Ready);
|
||||||
|
|
||||||
// if the sync failed, and then the reconnector
|
// if the sync failed, and then the reconnector
|
||||||
|
@ -261,6 +263,9 @@ export class SessionContainer {
|
||||||
// to prevent an extra /versions request
|
// to prevent an extra /versions request
|
||||||
if (!this._sessionStartedByReconnector) {
|
if (!this._sessionStartedByReconnector) {
|
||||||
const lastVersionsResponse = await hsApi.versions({timeout: 10000, log}).response();
|
const lastVersionsResponse = await hsApi.versions({timeout: 10000, log}).response();
|
||||||
|
if (this._isDisposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// log as ref as we don't want to await it
|
// log as ref as we don't want to await it
|
||||||
await log.wrap("session start", log => this._session.start(lastVersionsResponse, log));
|
await log.wrap("session start", log => this._session.start(lastVersionsResponse, log));
|
||||||
}
|
}
|
||||||
|
@ -322,11 +327,16 @@ export class SessionContainer {
|
||||||
return this._reconnector;
|
return this._reconnector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get _isDisposed() {
|
||||||
|
return !this._reconnector;
|
||||||
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
if (this._reconnectSubscription) {
|
if (this._reconnectSubscription) {
|
||||||
this._reconnectSubscription();
|
this._reconnectSubscription();
|
||||||
this._reconnectSubscription = null;
|
this._reconnectSubscription = null;
|
||||||
}
|
}
|
||||||
|
this._reconnector = null;
|
||||||
if (this._requestScheduler) {
|
if (this._requestScheduler) {
|
||||||
this._requestScheduler.stop();
|
this._requestScheduler.stop();
|
||||||
}
|
}
|
||||||
|
@ -346,13 +356,17 @@ export class SessionContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteSession() {
|
async deleteSession(log) {
|
||||||
if (this._sessionId) {
|
if (this._sessionId) {
|
||||||
|
// need to dispose first, so the storage is closed,
|
||||||
|
// and also first sync finishing won't call Session.start anymore,
|
||||||
|
// which assumes that the storage works.
|
||||||
|
this.dispose();
|
||||||
// if one fails, don't block the other from trying
|
// if one fails, don't block the other from trying
|
||||||
// also, run in parallel
|
// also, run in parallel
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this._platform.storageFactory.delete(this._sessionId),
|
log.wrap("storageFactory", () => this._platform.storageFactory.delete(this._sessionId)),
|
||||||
this._platform.sessionInfoStorage.delete(this._sessionId),
|
log.wrap("sessionInfoStorage", () => this._platform.sessionInfoStorage.delete(this._sessionId)),
|
||||||
]);
|
]);
|
||||||
this._sessionId = null;
|
this._sessionId = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,6 +225,10 @@ export class HomeServerApi {
|
||||||
forget(roomId, options = null) {
|
forget(roomId, options = null) {
|
||||||
return this._post(`/rooms/${encodeURIComponent(roomId)}/forget`, null, null, options);
|
return this._post(`/rooms/${encodeURIComponent(roomId)}/forget`, null, null, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logout(options = null) {
|
||||||
|
return this._post(`/logout`, null, null, options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
import {Request as MockRequest} from "../../mocks/Request.js";
|
import {Request as MockRequest} from "../../mocks/Request.js";
|
||||||
|
|
|
@ -40,7 +40,11 @@ export class SettingsView extends TemplateView {
|
||||||
t.h3("Session"),
|
t.h3("Session"),
|
||||||
row(t, vm.i18n`User ID`, vm.userId),
|
row(t, vm.i18n`User ID`, vm.userId),
|
||||||
row(t, vm.i18n`Session ID`, vm.deviceId, "code"),
|
row(t, vm.i18n`Session ID`, vm.deviceId, "code"),
|
||||||
row(t, vm.i18n`Session key`, vm.fingerprintKey, "code")
|
row(t, vm.i18n`Session key`, vm.fingerprintKey, "code"),
|
||||||
|
row(t, "", t.button({
|
||||||
|
onClick: () => vm.logout(),
|
||||||
|
disabled: vm => vm.isLoggingOut
|
||||||
|
}, "Logout"))
|
||||||
);
|
);
|
||||||
settingNodes.push(
|
settingNodes.push(
|
||||||
t.h3("Session Backup"),
|
t.h3("Session Backup"),
|
||||||
|
|
Reference in a new issue