extend createRoom for creating rooms in a space
This commit is contained in:
parent
c10512fd56
commit
1a7a0e619d
3 changed files with 42 additions and 2 deletions
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
|
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
import { Room } from "matrix-js-sdk/src/models/room";
|
import { Room } from "matrix-js-sdk/src/models/room";
|
||||||
|
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||||
|
|
||||||
import { MatrixClientPeg } from './MatrixClientPeg';
|
import { MatrixClientPeg } from './MatrixClientPeg';
|
||||||
import Modal from './Modal';
|
import Modal from './Modal';
|
||||||
|
@ -31,6 +32,8 @@ import GroupStore from "./stores/GroupStore";
|
||||||
import CountlyAnalytics from "./CountlyAnalytics";
|
import CountlyAnalytics from "./CountlyAnalytics";
|
||||||
import { isJoinedOrNearlyJoined } from "./utils/membership";
|
import { isJoinedOrNearlyJoined } from "./utils/membership";
|
||||||
import { VIRTUAL_ROOM_EVENT_TYPE } from "./CallHandler";
|
import { VIRTUAL_ROOM_EVENT_TYPE } from "./CallHandler";
|
||||||
|
import SpaceStore from "./stores/SpaceStore";
|
||||||
|
import { makeSpaceParentEvent } from "./utils/space";
|
||||||
|
|
||||||
// we define a number of interfaces which take their names from the js-sdk
|
// we define a number of interfaces which take their names from the js-sdk
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
|
@ -84,6 +87,7 @@ export interface IOpts {
|
||||||
inlineErrors?: boolean;
|
inlineErrors?: boolean;
|
||||||
andView?: boolean;
|
andView?: boolean;
|
||||||
associatedWithCommunity?: string;
|
associatedWithCommunity?: string;
|
||||||
|
parentSpace?: Room;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,6 +179,16 @@ export default function createRoom(opts: IOpts): Promise<string | null> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts.parentSpace) {
|
||||||
|
opts.createOpts.initial_state.push(makeSpaceParentEvent(opts.parentSpace, true));
|
||||||
|
opts.createOpts.initial_state.push({
|
||||||
|
type: EventType.RoomHistoryVisibility,
|
||||||
|
content: {
|
||||||
|
"history_visibility": opts.createOpts.preset === Preset.PublicChat ? "world_readable" : "invited",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let modal;
|
let modal;
|
||||||
if (opts.spinner) modal = Modal.createDialog(Loader, null, 'mx_Dialog_spinner');
|
if (opts.spinner) modal = Modal.createDialog(Loader, null, 'mx_Dialog_spinner');
|
||||||
|
|
||||||
|
@ -189,6 +203,9 @@ export default function createRoom(opts: IOpts): Promise<string | null> {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
if (opts.parentSpace) {
|
||||||
|
return SpaceStore.instance.addRoomToSpace(opts.parentSpace, roomId, [client.getDomain()], true);
|
||||||
|
}
|
||||||
if (opts.associatedWithCommunity) {
|
if (opts.associatedWithCommunity) {
|
||||||
return GroupStore.addRoomToGroup(opts.associatedWithCommunity, roomId, false);
|
return GroupStore.addRoomToGroup(opts.associatedWithCommunity, roomId, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,11 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {MatrixClientPeg} from "../../MatrixClientPeg";
|
|
||||||
import isIp from "is-ip";
|
import isIp from "is-ip";
|
||||||
import * as utils from 'matrix-js-sdk/src/utils';
|
import * as utils from "matrix-js-sdk/src/utils";
|
||||||
|
import {Room} from "matrix-js-sdk/src/models/room";
|
||||||
|
|
||||||
|
import {MatrixClientPeg} from "../../MatrixClientPeg";
|
||||||
import SpecPermalinkConstructor, {baseUrl as matrixtoBaseUrl} from "./SpecPermalinkConstructor";
|
import SpecPermalinkConstructor, {baseUrl as matrixtoBaseUrl} from "./SpecPermalinkConstructor";
|
||||||
import PermalinkConstructor, {PermalinkParts} from "./PermalinkConstructor";
|
import PermalinkConstructor, {PermalinkParts} from "./PermalinkConstructor";
|
||||||
import ElementPermalinkConstructor from "./ElementPermalinkConstructor";
|
import ElementPermalinkConstructor from "./ElementPermalinkConstructor";
|
||||||
|
@ -121,6 +123,10 @@ export class RoomPermalinkCreator {
|
||||||
this._started = false;
|
this._started = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get serverCandidates() {
|
||||||
|
return this._serverCandidates;
|
||||||
|
}
|
||||||
|
|
||||||
isStarted() {
|
isStarted() {
|
||||||
return this._started;
|
return this._started;
|
||||||
}
|
}
|
||||||
|
@ -451,3 +457,9 @@ function isHostnameIpAddress(hostname) {
|
||||||
|
|
||||||
return isIp(hostname);
|
return isIp(hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const calculateRoomVia = (room: Room) => {
|
||||||
|
const permalinkCreator = new RoomPermalinkCreator(room);
|
||||||
|
permalinkCreator.load();
|
||||||
|
return permalinkCreator.serverCandidates;
|
||||||
|
};
|
||||||
|
|
|
@ -18,6 +18,8 @@ import {Room} from "matrix-js-sdk/src/models/room";
|
||||||
import {MatrixClient} from "matrix-js-sdk/src/client";
|
import {MatrixClient} from "matrix-js-sdk/src/client";
|
||||||
import {EventType} from "matrix-js-sdk/src/@types/event";
|
import {EventType} from "matrix-js-sdk/src/@types/event";
|
||||||
|
|
||||||
|
import {calculateRoomVia} from "../utils/permalinks/Permalinks";
|
||||||
|
|
||||||
export const shouldShowSpaceSettings = (cli: MatrixClient, space: Room) => {
|
export const shouldShowSpaceSettings = (cli: MatrixClient, space: Room) => {
|
||||||
const userId = cli.getUserId();
|
const userId = cli.getUserId();
|
||||||
return space.getMyMembership() === "join"
|
return space.getMyMembership() === "join"
|
||||||
|
@ -26,3 +28,12 @@ export const shouldShowSpaceSettings = (cli: MatrixClient, space: Room) => {
|
||||||
|| space.currentState.maySendStateEvent(EventType.RoomTopic, userId)
|
|| space.currentState.maySendStateEvent(EventType.RoomTopic, userId)
|
||||||
|| space.currentState.maySendStateEvent(EventType.RoomJoinRules, userId));
|
|| space.currentState.maySendStateEvent(EventType.RoomJoinRules, userId));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const makeSpaceParentEvent = (room: Room, canonical = false) => ({
|
||||||
|
type: EventType.SpaceParent,
|
||||||
|
content: {
|
||||||
|
"via": calculateRoomVia(room),
|
||||||
|
"canonical": canonical,
|
||||||
|
},
|
||||||
|
state_key: room.roomId,
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue