diff --git a/.gitignore b/.gitignore index c952823f..a804428a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ /release/ .env.*.local /svn/ -/.yarn/ +.yarn* diff --git a/.yarnrc b/.yarnrc deleted file mode 100644 index d9df8550..00000000 --- a/.yarnrc +++ /dev/null @@ -1,5 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -yarn-path ".yarn/releases/yarn-1.22.21.cjs" diff --git a/.yarnrc.yml b/.yarnrc.yml deleted file mode 100644 index 82069dd8..00000000 --- a/.yarnrc.yml +++ /dev/null @@ -1 +0,0 @@ -yarnPath: .yarn/releases/yarn-1.22.19.cjs diff --git a/frontend/iframe/styles/theme/theme.css b/frontend/iframe/styles/theme/theme.css index f480ae05..d037de13 100644 --- a/frontend/iframe/styles/theme/theme.css +++ b/frontend/iframe/styles/theme/theme.css @@ -34,9 +34,19 @@ body { 320px 1fr; } -/* Always show the back button in single-room mode. */ -.RootView.single-room-mode .close-middle { - display: block; +/* Don't show the back button when in a Room, when in single-room mode. */ +.RootView.single-room-mode .RoomHeader .close-middle { + display: none !important; +} + +/* Don't show the back button in room list. */ +.LeftPanel .close-session { + display: none !important; +} + +/* Don't show the back button in the login screen. */ +.LoginView_back { + display: none !important; } /* Remove horizontal scrollbars in pre-session screen. */ diff --git a/frontend/iframe/viewmodels/RoomViewModel.ts b/frontend/iframe/viewmodels/RoomViewModel.ts index 436f1f25..503c29e9 100644 --- a/frontend/iframe/viewmodels/RoomViewModel.ts +++ b/frontend/iframe/viewmodels/RoomViewModel.ts @@ -1,5 +1,3 @@ -import { SegmentType } from "hydrogen-web/src/domain/navigation"; -import { Segment } from "hydrogen-web/src/domain/navigation/Navigation"; import { RoomViewModel as BaseRoomViewModel } from "hydrogen-web/src/domain/session/room/RoomViewModel"; import { URLRouter } from "../platform/URLRouter"; @@ -18,16 +16,6 @@ export class RoomViewModel extends BaseRoomViewModel { return super.urlRouter; } - get closeUrl() { - if (this.singleRoomMode) { - const path = this.navigation.path.with(new Segment("session")); - - return this.urlRouter.urlForPath(path); - } - - return super.closeUrl; - } - get singleRoomMode(): boolean { return this._singleRoomMode; } diff --git a/frontend/iframe/viewmodels/RootViewModel.ts b/frontend/iframe/viewmodels/RootViewModel.ts index 13701de7..1fe93d13 100644 --- a/frontend/iframe/viewmodels/RootViewModel.ts +++ b/frontend/iframe/viewmodels/RootViewModel.ts @@ -106,9 +106,16 @@ export class RootViewModel extends ViewModel { const isLogin = this.navigation.path.get("login"); const logoutSessionId = this.navigation.path.get("logout")?.value; const isForcedLogout = this.navigation.path.get("forced")?.value; - const sessionId = this.navigation.path.get("session")?.value; const loginToken = this.navigation.path.get("sso")?.value; + let sessionId = this.navigation.path.get("session")?.value; + if (sessionId === true) { + // When logging out, we end up here (sessionId = true). + // Since user is now logged out and as there can only be a single session, + // we want to show the login screen directly. + sessionId = null; + } + if (isLogin) { if (this.activeSection !== Section.Login) { this._showLogin(undefined); @@ -121,10 +128,6 @@ export class RootViewModel extends ViewModel { if (this.activeSection !== Section.Logout) { this._showLogout(logoutSessionId); } - } else if (sessionId === true) { - if (this.activeSection !== Section.SessionPicker) { - void this._showPicker(); - } } else if (sessionId) { const singleRoomId = await this.getSingleRoomId(); if (singleRoomId) { @@ -153,7 +156,7 @@ export class RootViewModel extends ViewModel { } } else { try { - await this._showInitialScreen(shouldRestoreLastUrl); + await this._showInitialScreen(); } catch (err) { console.error(err); this._setSection(() => this._error = err); @@ -161,68 +164,47 @@ export class RootViewModel extends ViewModel { } } - private async _showInitialScreen(shouldRestoreLastUrl: boolean) { - const sessionInfos = await this.platform.sessionInfoStorage.getAll(); - const singleRoomId = await this.getSingleRoomId(); + private async _showInitialScreen() { + let sessionInfos = await this.platform.sessionInfoStorage.getAll(); - if (shouldRestoreLastUrl && singleRoomId) { - // Do not restore last URL to Login if we're in single-room mode. - // We do this so that we can try guest login when appropriate. - const willShowLogin = this.platform.history.getLastSessionUrl() === "#/login"; - if (willShowLogin) { - shouldRestoreLastUrl = false; + // In previous versions, it was possible to have multiple sessions open. + // When we have multiple sessions, we want to log out all of them except one. + if (sessionInfos.length > 1) { + for (let i = 0; i < sessionInfos.length - 1; i++) { + await this.platform.sessionInfoStorage.delete(sessionInfos[i].id); } - // Do not restore last URL to session picker if we're in single-room mode and there are zero or one sessions. - // We do this so that we can try guest login when there are no sessions, or in the case where there is one - // session, use that session. - const willShowSessionPicker = this.platform.history.getLastSessionUrl() === "#/session"; - if (shouldRestoreLastUrl && willShowSessionPicker && sessionInfos.length <= 1) { - shouldRestoreLastUrl = false; + sessionInfos = await this.platform.sessionInfoStorage.getAll(); + if (sessionInfos.length > 1) { + console.error("Expected to have a single session, but multiple sessions were found."); } } + // Only restore last url if there is already a session. + // This will result in the user being sent to login screen. + let shouldRestoreLastUrl = sessionInfos.length > 1; + + // We never want to show the session picker, even if it was the last url. + const willShowSessionPicker = this.platform.history.getLastSessionUrl() === "#/session"; + if (willShowSessionPicker) { + shouldRestoreLastUrl = false; + } + if (shouldRestoreLastUrl && this.urlRouter.tryRestoreLastUrl()) { // Restored last URL. - // By the time we get here, _applyNavigation() has run for the restored URL, so we have nothing else - // to do. + // By the time we get here, _applyNavigation() has run for the restored URL, so we have nothing else to do. return; } // We were not able to restore the last URL. // So we send the user to the screen that makes the most sense, according to how many sessions they have. - // Go to Login or, when in single-room mode, try registering guest user. - if (sessionInfos.length === 0) { - if (!singleRoomId) { - this.navigation.push(Section.Login); - return; - } - - // Attempt to log in as guest. If it fails, go to Login. - const homeserver = await lookupHomeserver(singleRoomId.split(':')[1], this.platform.request); - const client = new Client(this.platform); - - await client.doGuestLogin(homeserver); - if (client.loadError) { - console.warn("Failed to login as guest. Guest registration is probably disabled on the homeserver", client.loadError); - this.navigation.push(Section.Login); - return; - } - - this._pendingClient = client; - this.navigation.push(Section.Session, client.sessionId); - return; - } - - // Open session. if (sessionInfos.length === 1) { this.navigation.push(Section.Session, sessionInfos[0].id); return; } - // Open session picker. - this.navigation.push(Section.Session); + this.navigation.push(Section.Login); } private async resolveRoomAlias(roomIdOrAlias: string): Promise { diff --git a/frontend/iframe/views/RootView.ts b/frontend/iframe/views/RootView.ts index 571cb613..3a671c95 100644 --- a/frontend/iframe/views/RootView.ts +++ b/frontend/iframe/views/RootView.ts @@ -4,8 +4,8 @@ import { TemplateView } from "hydrogen-web/src/platform/web/ui/general/TemplateV import { LoginView } from "hydrogen-web/src/platform/web/ui/login/LoginView"; import { SessionLoadView } from "hydrogen-web/src/platform/web/ui/login/SessionLoadView"; import { SessionPickerView } from "hydrogen-web/src/platform/web/ui/login/SessionPickerView"; -import { UnknownRoomView } from "hydrogen-web/src/platform/web/ui/session/room/UnknownRoomView"; import { LogoutView } from "hydrogen-web/src/platform/web/ui/LogoutView"; +import { UnknownRoomView } from "hydrogen-web/src/platform/web/ui/session/room/UnknownRoomView"; import { Section } from "../platform/Navigation"; import { RootViewModel } from "../viewmodels/RootViewModel"; import { SessionView } from "./SessionView"; @@ -34,7 +34,7 @@ export class RootView extends TemplateView { case Section.SessionPicker: return new SessionPickerView(vm.sessionPickerViewModel); case Section.Redirecting: - return new StaticView(t => t.p("Redirecting...")); + return new StaticView(t => t.p("Loading...")); case Section.SessionLoading: return new SessionLoadView(vm.sessionLoadViewModel); case Section.UnknownRoom: