2021-03-01 18:10:17 +00: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 19:05:50 +00:00
|
|
|
import {calculateRoomVia} from "../utils/permalinks/Permalinks";
|
|
|
|
|
|
2021-03-01 18:10:17 +00: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 19:05:50 +00:00
|
|
|
|
|
|
|
|
export const makeSpaceParentEvent = (room: Room, canonical = false) => ({
|
|
|
|
|
type: EventType.SpaceParent,
|
|
|
|
|
content: {
|
|
|
|
|
"via": calculateRoomVia(room),
|
|
|
|
|
"canonical": canonical,
|
|
|
|
|
},
|
|
|
|
|
state_key: room.roomId,
|
|
|
|
|
});
|