2020-08-05 22:08:55 +05:30
|
|
|
/*
|
|
|
|
Copyright 2020 Bruno Windels <bruno@windels.cloud>
|
2020-08-17 20:04:25 +05:30
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2020-08-05 22:08:55 +05:30
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2022-02-10 13:15:10 +05:30
|
|
|
import { text } from "../../general/html";
|
2021-09-16 19:16:02 +05:30
|
|
|
import {TemplateView} from "../../general/TemplateView";
|
2021-05-12 17:29:08 +05:30
|
|
|
import {Popup} from "../../general/Popup.js";
|
|
|
|
import {Menu} from "../../general/Menu.js";
|
2021-09-06 21:21:32 +05:30
|
|
|
import {TimelineView} from "./TimelineView";
|
2020-08-17 20:04:25 +05:30
|
|
|
import {TimelineLoadingView} from "./TimelineLoadingView.js";
|
2020-04-21 00:56:39 +05:30
|
|
|
import {MessageComposer} from "./MessageComposer.js";
|
2021-05-11 16:41:11 +05:30
|
|
|
import {RoomArchivedView} from "./RoomArchivedView.js";
|
2021-06-30 23:34:23 +05:30
|
|
|
import {AvatarView} from "../../AvatarView.js";
|
2019-02-28 03:20:08 +05:30
|
|
|
|
2020-04-21 00:56:39 +05:30
|
|
|
export class RoomView extends TemplateView {
|
2021-05-12 17:29:08 +05:30
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
this._optionsPopup = null;
|
|
|
|
}
|
|
|
|
|
2019-06-27 02:44:39 +05:30
|
|
|
render(t, vm) {
|
2021-05-11 16:41:11 +05:30
|
|
|
let bottomView;
|
|
|
|
if (vm.composerViewModel.kind === "composer") {
|
|
|
|
bottomView = new MessageComposer(vm.composerViewModel);
|
|
|
|
} else if (vm.composerViewModel.kind === "archived") {
|
|
|
|
bottomView = new RoomArchivedView(vm.composerViewModel);
|
|
|
|
}
|
2020-10-19 18:22:18 +05:30
|
|
|
return t.main({className: "RoomView middle"}, [
|
2021-04-27 13:58:09 +05:30
|
|
|
t.div({className: "RoomHeader middle-header"}, [
|
|
|
|
t.a({className: "button-utility close-middle", href: vm.closeUrl, title: vm.i18n`Close room`}),
|
|
|
|
t.view(new AvatarView(vm, 32)),
|
|
|
|
t.div({className: "room-description"}, [
|
2021-04-27 18:32:29 +05:30
|
|
|
t.h2(vm => vm.name),
|
2019-06-16 18:51:20 +05:30
|
|
|
]),
|
2021-05-12 17:29:08 +05:30
|
|
|
t.button({
|
|
|
|
className: "button-utility room-options",
|
2021-05-28 20:37:36 +05:30
|
|
|
"aria-label":vm.i18n`Room options`,
|
2021-05-12 17:29:08 +05:30
|
|
|
onClick: evt => this._toggleOptionsMenu(evt)
|
2021-05-28 15:47:06 +05:30
|
|
|
})
|
2021-04-27 13:58:09 +05:30
|
|
|
]),
|
|
|
|
t.div({className: "RoomView_body"}, [
|
2019-06-16 18:51:20 +05:30
|
|
|
t.div({className: "RoomView_error"}, vm => vm.error),
|
2020-08-17 20:04:25 +05:30
|
|
|
t.mapView(vm => vm.timelineViewModel, timelineViewModel => {
|
|
|
|
return timelineViewModel ?
|
2021-09-02 12:23:44 +05:30
|
|
|
new TimelineView(timelineViewModel) :
|
2020-08-17 20:04:25 +05:30
|
|
|
new TimelineLoadingView(vm); // vm is just needed for i18n
|
|
|
|
}),
|
2022-02-10 13:15:10 +05:30
|
|
|
bottomView ? t.view(bottomView) : text(''),
|
2019-06-16 18:51:20 +05:30
|
|
|
])
|
2019-02-28 03:20:08 +05:30
|
|
|
]);
|
2019-06-16 18:51:20 +05:30
|
|
|
}
|
2021-05-12 17:29:08 +05:30
|
|
|
|
|
|
|
_toggleOptionsMenu(evt) {
|
|
|
|
if (this._optionsPopup && this._optionsPopup.isOpen) {
|
|
|
|
this._optionsPopup.close();
|
|
|
|
} else {
|
|
|
|
const vm = this.value;
|
|
|
|
const options = [];
|
2021-06-15 14:30:27 +05:30
|
|
|
options.push(Menu.option(vm.i18n`Room details`, () => vm.openDetailsPanel()))
|
2021-05-12 17:29:08 +05:30
|
|
|
if (vm.canLeave) {
|
2021-07-15 18:00:16 +05:30
|
|
|
options.push(Menu.option(vm.i18n`Leave room`, () => this._confirmToLeaveRoom()).setDestructive());
|
2021-05-12 17:29:08 +05:30
|
|
|
}
|
2021-05-12 19:08:54 +05:30
|
|
|
if (vm.canForget) {
|
2021-06-04 23:19:25 +05:30
|
|
|
options.push(Menu.option(vm.i18n`Forget room`, () => vm.forgetRoom()).setDestructive());
|
2021-05-12 19:08:54 +05:30
|
|
|
}
|
2021-05-18 14:37:46 +05:30
|
|
|
if (vm.canRejoin) {
|
2021-06-04 23:19:25 +05:30
|
|
|
options.push(Menu.option(vm.i18n`Rejoin room`, () => vm.rejoinRoom()));
|
2021-05-18 14:37:46 +05:30
|
|
|
}
|
2021-05-12 17:29:08 +05:30
|
|
|
if (!options.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._optionsPopup = new Popup(new Menu(options));
|
|
|
|
this._optionsPopup.trackInTemplateView(this);
|
2021-09-24 21:58:06 +05:30
|
|
|
this._optionsPopup.showRelativeTo(evt.target, 10);
|
2021-05-12 17:29:08 +05:30
|
|
|
}
|
|
|
|
}
|
2021-07-15 18:00:16 +05:30
|
|
|
|
|
|
|
_confirmToLeaveRoom() {
|
|
|
|
if (confirm(this.value.i18n`Are you sure you want to leave "${this.value.name}"?`)) {
|
|
|
|
this.value.leaveRoom();
|
|
|
|
}
|
|
|
|
}
|
2019-02-28 03:20:08 +05:30
|
|
|
}
|