From 03be63572d1531962ca5f6182757a11d136096dd Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 18 May 2021 11:07:19 +0200 Subject: [PATCH] ask to join when room id is unknown --- src/domain/session/RoomViewModelObservable.js | 2 + src/domain/session/SessionViewModel.js | 8 +++ .../session/room/UnknownRoomViewModel.js | 59 +++++++++++++++++++ src/platform/web/ui/session/SessionView.js | 5 +- .../web/ui/session/room/UnknownRoomView.js | 38 ++++++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/domain/session/room/UnknownRoomViewModel.js create mode 100644 src/platform/web/ui/session/room/UnknownRoomView.js diff --git a/src/domain/session/RoomViewModelObservable.js b/src/domain/session/RoomViewModelObservable.js index 8a8254e7..a7aeea07 100644 --- a/src/domain/session/RoomViewModelObservable.js +++ b/src/domain/session/RoomViewModelObservable.js @@ -65,6 +65,8 @@ export class RoomViewModelObservable extends ObservableValue { return this._sessionViewModel._createRoomViewModel(this.id); } else if (status.archived) { return await this._sessionViewModel._createArchivedRoomViewModel(this.id); + } else { + return this._sessionViewModel._createUnknownRoomViewModel(this.id); } return null; } diff --git a/src/domain/session/SessionViewModel.js b/src/domain/session/SessionViewModel.js index ae697c72..6f2c9797 100644 --- a/src/domain/session/SessionViewModel.js +++ b/src/domain/session/SessionViewModel.js @@ -17,6 +17,7 @@ limitations under the License. import {LeftPanelViewModel} from "./leftpanel/LeftPanelViewModel.js"; import {RoomViewModel} from "./room/RoomViewModel.js"; +import {UnknownRoomViewModel} from "./room/UnknownRoomViewModel.js"; import {InviteViewModel} from "./room/InviteViewModel.js"; import {LightboxViewModel} from "./room/LightboxViewModel.js"; import {SessionStatusViewModel} from "./SessionStatusViewModel.js"; @@ -162,6 +163,13 @@ export class SessionViewModel extends ViewModel { return null; } + _createUnknownRoomViewModel(roomIdOrAlias) { + return new UnknownRoomViewModel(this.childOptions({ + roomIdOrAlias, + session: this._sessionContainer.session, + })); + } + async _createArchivedRoomViewModel(roomId) { const room = await this._sessionContainer.session.loadArchivedRoom(roomId); if (room) { diff --git a/src/domain/session/room/UnknownRoomViewModel.js b/src/domain/session/room/UnknownRoomViewModel.js new file mode 100644 index 00000000..d896d4cf --- /dev/null +++ b/src/domain/session/room/UnknownRoomViewModel.js @@ -0,0 +1,59 @@ +/* +Copyright 2020 Bruno Windels +Copyright 2020 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import {ViewModel} from "../../ViewModel.js"; + +export class UnknownRoomViewModel extends ViewModel { + constructor(options) { + super(options); + const {roomIdOrAlias, session} = options; + this._session = session; + this._roomIdOrAlias = roomIdOrAlias; + this._error = null; + this._busy = false; + } + + get error() { + return this._error?.message; + } + + get description() { + return this.i18n`You are currently not in ${this._roomIdOrAlias}. Want to join it?`; + } + + async join() { + this._busy = true; + this.emitChange("busy"); + try { + const roomId = await this._session.joinRoom(this._roomIdOrAlias); + // navigate to roomId if we were at the alias + this.navigation.push("room", roomId); + } catch (err) { + this._error = err; + this._busy = false; + this.emitChange("error"); + } + } + + get busy() { + return this._busy; + } + + get kind() { + return "unknown"; + } +} \ No newline at end of file diff --git a/src/platform/web/ui/session/SessionView.js b/src/platform/web/ui/session/SessionView.js index 214db2a3..c8a77a1b 100644 --- a/src/platform/web/ui/session/SessionView.js +++ b/src/platform/web/ui/session/SessionView.js @@ -17,6 +17,7 @@ limitations under the License. import {LeftPanelView} from "./leftpanel/LeftPanelView.js"; import {RoomView} from "./room/RoomView.js"; +import {UnknownRoomView} from "./room/UnknownRoomView.js"; import {InviteView} from "./room/InviteView.js"; import {LightboxView} from "./room/LightboxView.js"; import {TemplateView} from "../general/TemplateView.js"; @@ -43,8 +44,10 @@ export class SessionView extends TemplateView { } else if (vm.currentRoomViewModel) { if (vm.currentRoomViewModel.kind === "invite") { return new InviteView(vm.currentRoomViewModel); - } else { + } else if (vm.currentRoomViewModel.kind === "room") { return new RoomView(vm.currentRoomViewModel); + } else { + return new UnknownRoomView(vm.currentRoomViewModel); } } else { return new StaticView(t => t.div({className: "room-placeholder"}, t.h2(vm.i18n`Choose a room on the left side.`))); diff --git a/src/platform/web/ui/session/room/UnknownRoomView.js b/src/platform/web/ui/session/room/UnknownRoomView.js new file mode 100644 index 00000000..03076885 --- /dev/null +++ b/src/platform/web/ui/session/room/UnknownRoomView.js @@ -0,0 +1,38 @@ +/* +Copyright 2020 Bruno Windels +Copyright 2020 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import {TemplateView} from "../../general/TemplateView.js"; +import {Popup} from "../../general/Popup.js"; +import {Menu} from "../../general/Menu.js"; +import {TimelineList} from "./TimelineList.js"; +import {TimelineLoadingView} from "./TimelineLoadingView.js"; +import {MessageComposer} from "./MessageComposer.js"; +import {RoomArchivedView} from "./RoomArchivedView.js"; +import {AvatarView} from "../../avatar.js"; + +export class UnknownRoomView extends TemplateView { + render(t, vm) { + return t.main({className: "UnknownRoomView middle"}, [ + t.h2(vm.description), + t.div(t.button({ + className: "button-action primary", + onClick: () => vm.join(), + disabled: vm => vm.busy, + }, vm.i18n`Join room`)) + ]); + } +}