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.
|
|
|
|
*/
|
|
|
|
|
2020-04-21 00:56:39 +05:30
|
|
|
import {TemplateView} from "../../general/TemplateView.js";
|
2021-05-12 17:29:08 +05:30
|
|
|
import {Popup} from "../../general/Popup.js";
|
|
|
|
import {Menu} from "../../general/Menu.js";
|
2020-04-21 00:56:39 +05:30
|
|
|
import {TimelineList} from "./TimelineList.js";
|
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-04-15 18:42:14 +05:30
|
|
|
import {AvatarView} from "../../avatar.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 ?
|
|
|
|
new TimelineList(timelineViewModel) :
|
|
|
|
new TimelineLoadingView(vm); // vm is just needed for i18n
|
|
|
|
}),
|
2021-05-11 16:41:11 +05:30
|
|
|
t.view(bottomView),
|
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 = [];
|
|
|
|
if (vm.canLeave) {
|
2021-05-31 16:38:06 +05:30
|
|
|
options.push(Menu.option(vm.i18n`Leave room`, () => vm.leaveRoom()).setDestructive());
|
2021-05-12 17:29:08 +05:30
|
|
|
}
|
2021-05-12 19:08:54 +05:30
|
|
|
if (vm.canForget) {
|
2021-05-31 16:38:06 +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) {
|
|
|
|
options.push(Menu.option(vm.i18n`Rejoin room`, () => vm.rejoinRoom()));
|
|
|
|
}
|
2021-05-12 17:29:08 +05:30
|
|
|
if (!options.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._optionsPopup = new Popup(new Menu(options));
|
|
|
|
this._optionsPopup.trackInTemplateView(this);
|
|
|
|
this._optionsPopup.showRelativeTo(evt.target, {
|
|
|
|
horizontal: {
|
|
|
|
relativeTo: "end",
|
|
|
|
align: "start",
|
|
|
|
after: 0
|
|
|
|
},
|
|
|
|
vertical: {
|
|
|
|
relativeTo: "start",
|
2021-05-18 15:28:06 +05:30
|
|
|
align: "end",
|
|
|
|
before: -32 - 4
|
2021-05-12 17:29:08 +05:30
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-02-28 03:20:08 +05:30
|
|
|
}
|