Merge pull request #6764 from matrix-org/t3chguy/fix/18677

This commit is contained in:
Michael Telatynski 2021-09-08 23:00:01 +01:00 committed by GitHub
commit e17a5328d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 22 deletions

View file

@ -79,7 +79,10 @@ export default class RoomSettingsDialog extends React.Component<IProps> {
ROOM_SECURITY_TAB, ROOM_SECURITY_TAB,
_td("Security & Privacy"), _td("Security & Privacy"),
"mx_RoomSettingsDialog_securityIcon", "mx_RoomSettingsDialog_securityIcon",
<SecurityRoomSettingsTab roomId={this.props.roomId} />, <SecurityRoomSettingsTab
roomId={this.props.roomId}
closeSettingsFn={() => this.props.onFinished(true)}
/>,
)); ));
tabs.push(new Tab( tabs.push(new Tab(
ROOM_ROLES_TAB, ROOM_ROLES_TAB,

View file

@ -39,9 +39,12 @@ import { arrayHasDiff } from "../../../../../utils/arrays";
import SettingsFlag from '../../../elements/SettingsFlag'; import SettingsFlag from '../../../elements/SettingsFlag';
import createRoom, { IOpts } from '../../../../../createRoom'; import createRoom, { IOpts } from '../../../../../createRoom';
import CreateRoomDialog from '../../../dialogs/CreateRoomDialog'; import CreateRoomDialog from '../../../dialogs/CreateRoomDialog';
import dis from "../../../../../dispatcher/dispatcher";
import { ROOM_SECURITY_TAB } from "../../../dialogs/RoomSettingsDialog";
interface IProps { interface IProps {
roomId: string; roomId: string;
closeSettingsFn: () => void;
} }
interface IState { interface IState {
@ -220,9 +223,20 @@ export default class SecurityRoomSettingsTab extends React.Component<IProps, ISt
targetVersion, targetVersion,
description: _t("This upgrade will allow members of selected spaces " + description: _t("This upgrade will allow members of selected spaces " +
"access to this room without an invite."), "access to this room without an invite."),
onFinished: (resp) => { onFinished: async (resp) => {
if (!resp?.continue) return; if (!resp?.continue) return;
upgradeRoom(room, targetVersion, resp.invite); const roomId = await upgradeRoom(room, targetVersion, resp.invite, true, true, true);
this.props.closeSettingsFn();
// switch to the new room in the background
dis.dispatch({
action: "view_room",
room_id: roomId,
});
// open new settings on this tab
dis.dispatch({
action: "open_room_settings",
initial_tab_id: ROOM_SECURITY_TAB,
});
}, },
}); });
return; return;

View file

@ -22,6 +22,7 @@ import Modal from "../Modal";
import { _t } from "../languageHandler"; import { _t } from "../languageHandler";
import ErrorDialog from "../components/views/dialogs/ErrorDialog"; import ErrorDialog from "../components/views/dialogs/ErrorDialog";
import SpaceStore from "../stores/SpaceStore"; import SpaceStore from "../stores/SpaceStore";
import Spinner from "../components/views/elements/Spinner";
export async function upgradeRoom( export async function upgradeRoom(
room: Room, room: Room,
@ -29,8 +30,10 @@ export async function upgradeRoom(
inviteUsers = false, inviteUsers = false,
handleError = true, handleError = true,
updateSpaces = true, updateSpaces = true,
awaitRoom = false,
): Promise<string> { ): Promise<string> {
const cli = room.client; const cli = room.client;
const spinnerModal = Modal.createDialog(Spinner, null, "mx_Dialog_spinner");
let newRoomId: string; let newRoomId: string;
try { try {
@ -46,27 +49,36 @@ export async function upgradeRoom(
throw e; throw e;
} }
// We have to wait for the js-sdk to give us the room back so if (awaitRoom || inviteUsers) {
// we can more effectively abuse the MultiInviter behaviour await new Promise<void>(resolve => {
// which heavily relies on the Room object being available. // already have the room
if (inviteUsers) { if (room.client.getRoom(newRoomId)) {
const checkForUpgradeFn = async (newRoom: Room): Promise<void> => { resolve();
// The upgradePromise should be done by the time we await it here. return;
if (newRoom.roomId !== newRoomId) return;
const toInvite = [
...room.getMembersWithMembership("join"),
...room.getMembersWithMembership("invite"),
].map(m => m.userId).filter(m => m !== cli.getUserId());
if (toInvite.length > 0) {
// Errors are handled internally to this function
await inviteUsersToRoom(newRoomId, toInvite);
} }
cli.removeListener('Room', checkForUpgradeFn); // We have to wait for the js-sdk to give us the room back so
}; // we can more effectively abuse the MultiInviter behaviour
cli.on('Room', checkForUpgradeFn); // which heavily relies on the Room object being available.
const checkForRoomFn = (newRoom: Room) => {
if (newRoom.roomId !== newRoomId) return;
resolve();
cli.off("Room", checkForRoomFn);
};
cli.on("Room", checkForRoomFn);
});
}
if (inviteUsers) {
const toInvite = [
...room.getMembersWithMembership("join"),
...room.getMembersWithMembership("invite"),
].map(m => m.userId).filter(m => m !== cli.getUserId());
if (toInvite.length > 0) {
// Errors are handled internally to this function
await inviteUsersToRoom(newRoomId, toInvite);
}
} }
if (updateSpaces) { if (updateSpaces) {
@ -89,5 +101,6 @@ export async function upgradeRoom(
} }
} }
spinnerModal.close();
return newRoomId; return newRoomId;
} }