2021-03-01 21:10:17 +03:00
|
|
|
/*
|
|
|
|
Copyright 2021 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 {Room} from "matrix-js-sdk/src/models/room";
|
|
|
|
import {MatrixClient} from "matrix-js-sdk/src/client";
|
|
|
|
import {EventType} from "matrix-js-sdk/src/@types/event";
|
|
|
|
|
2021-03-01 22:05:50 +03:00
|
|
|
import {calculateRoomVia} from "../utils/permalinks/Permalinks";
|
2021-03-02 13:34:28 +03:00
|
|
|
import Modal from "../Modal";
|
|
|
|
import SpaceSettingsDialog from "../components/views/dialogs/SpaceSettingsDialog";
|
2021-03-02 16:32:24 +03:00
|
|
|
import AddExistingToSpaceDialog from "../components/views/dialogs/AddExistingToSpaceDialog";
|
2021-03-02 16:28:05 +03:00
|
|
|
import CreateRoomDialog from "../components/views/dialogs/CreateRoomDialog";
|
|
|
|
import createRoom, {IOpts} from "../createRoom";
|
2021-03-01 22:05:50 +03:00
|
|
|
|
2021-03-01 21:10:17 +03:00
|
|
|
export const shouldShowSpaceSettings = (cli: MatrixClient, space: Room) => {
|
|
|
|
const userId = cli.getUserId();
|
|
|
|
return space.getMyMembership() === "join"
|
|
|
|
&& (space.currentState.maySendStateEvent(EventType.RoomAvatar, userId)
|
|
|
|
|| space.currentState.maySendStateEvent(EventType.RoomName, userId)
|
|
|
|
|| space.currentState.maySendStateEvent(EventType.RoomTopic, userId)
|
|
|
|
|| space.currentState.maySendStateEvent(EventType.RoomJoinRules, userId));
|
|
|
|
};
|
2021-03-01 22:05:50 +03:00
|
|
|
|
|
|
|
export const makeSpaceParentEvent = (room: Room, canonical = false) => ({
|
|
|
|
type: EventType.SpaceParent,
|
|
|
|
content: {
|
|
|
|
"via": calculateRoomVia(room),
|
|
|
|
"canonical": canonical,
|
|
|
|
},
|
|
|
|
state_key: room.roomId,
|
|
|
|
});
|
2021-03-02 13:34:28 +03:00
|
|
|
|
|
|
|
export const showSpaceSettings = (cli: MatrixClient, space: Room) => {
|
|
|
|
Modal.createTrackedDialog("Space Settings", "", SpaceSettingsDialog, {
|
|
|
|
matrixClient: cli,
|
|
|
|
space,
|
|
|
|
}, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true);
|
|
|
|
};
|
2021-03-02 16:28:05 +03:00
|
|
|
|
2021-03-02 16:32:24 +03:00
|
|
|
export const showAddExistingRooms = async (cli: MatrixClient, space: Room) => {
|
|
|
|
return Modal.createTrackedDialog(
|
|
|
|
"Space Landing",
|
|
|
|
"Add Existing",
|
|
|
|
AddExistingToSpaceDialog,
|
|
|
|
{
|
|
|
|
matrixClient: cli,
|
|
|
|
onCreateRoomClick: showCreateNewRoom,
|
|
|
|
space,
|
|
|
|
},
|
|
|
|
"mx_AddExistingToSpaceDialog_wrapper",
|
|
|
|
).finished;
|
|
|
|
};
|
|
|
|
|
2021-03-02 16:28:05 +03:00
|
|
|
export const showCreateNewRoom = async (cli: MatrixClient, space: Room) => {
|
|
|
|
const modal = Modal.createTrackedDialog<[boolean, IOpts]>(
|
|
|
|
"Space Landing",
|
|
|
|
"Create Room",
|
|
|
|
CreateRoomDialog,
|
|
|
|
{
|
|
|
|
defaultPublic: space.getJoinRule() === "public",
|
|
|
|
parentSpace: space,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
const [shouldCreate, opts] = await modal.finished;
|
|
|
|
if (shouldCreate) {
|
|
|
|
await createRoom(opts);
|
|
|
|
}
|
|
|
|
};
|