Add progress bar to restricted room upgrade dialog
This commit is contained in:
parent
5264b1db9d
commit
2483f1dc90
5 changed files with 188 additions and 70 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -17,6 +17,22 @@ limitations under the License.
|
||||||
.mx_RoomUpgradeWarningDialog {
|
.mx_RoomUpgradeWarningDialog {
|
||||||
max-width: 38vw;
|
max-width: 38vw;
|
||||||
width: 38vw;
|
width: 38vw;
|
||||||
|
|
||||||
|
.mx_RoomUpgradeWarningDialog_progress {
|
||||||
|
.mx_ProgressBar {
|
||||||
|
height: 8px;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
@mixin ProgressBarBorderRadius 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mx_RoomUpgradeWarningDialog_progressText {
|
||||||
|
margin-top: 8px;
|
||||||
|
font-size: $font-15px;
|
||||||
|
line-height: $font-24px;
|
||||||
|
color: $primary-content;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.mx_RoomUpgradeWarningDialog .mx_SettingsFlag {
|
.mx_RoomUpgradeWarningDialog .mx_SettingsFlag {
|
||||||
|
|
|
@ -28,15 +28,25 @@ import { IDialogProps } from "./IDialogProps";
|
||||||
import BugReportDialog from './BugReportDialog';
|
import BugReportDialog from './BugReportDialog';
|
||||||
import BaseDialog from "./BaseDialog";
|
import BaseDialog from "./BaseDialog";
|
||||||
import DialogButtons from "../elements/DialogButtons";
|
import DialogButtons from "../elements/DialogButtons";
|
||||||
|
import ProgressBar from "../elements/ProgressBar";
|
||||||
|
|
||||||
|
export interface IFinishedOpts {
|
||||||
|
continue: boolean;
|
||||||
|
invite: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
interface IProps extends IDialogProps {
|
interface IProps extends IDialogProps {
|
||||||
roomId: string;
|
roomId: string;
|
||||||
targetVersion: string;
|
targetVersion: string;
|
||||||
description?: ReactNode;
|
description?: ReactNode;
|
||||||
|
doUpgrade?(opts: IFinishedOpts, fn: (progressText: string, progress: number, total: number) => void): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
inviteUsersToNewRoom: boolean;
|
inviteUsersToNewRoom: boolean;
|
||||||
|
progressText?: string;
|
||||||
|
progress?: number;
|
||||||
|
total?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@replaceableComponent("views.dialogs.RoomUpgradeWarningDialog")
|
@replaceableComponent("views.dialogs.RoomUpgradeWarningDialog")
|
||||||
|
@ -50,15 +60,30 @@ export default class RoomUpgradeWarningDialog extends React.Component<IProps, IS
|
||||||
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
||||||
const joinRules = room?.currentState.getStateEvents(EventType.RoomJoinRules, "");
|
const joinRules = room?.currentState.getStateEvents(EventType.RoomJoinRules, "");
|
||||||
this.isPrivate = joinRules?.getContent()['join_rule'] !== JoinRule.Public ?? true;
|
this.isPrivate = joinRules?.getContent()['join_rule'] !== JoinRule.Public ?? true;
|
||||||
this.currentVersion = room?.getVersion() || "1";
|
this.currentVersion = room?.getVersion();
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
inviteUsersToNewRoom: true,
|
inviteUsersToNewRoom: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private onProgressCallback = (progressText: string, progress: number, total: number): void => {
|
||||||
|
this.setState({ progressText, progress, total });
|
||||||
|
};
|
||||||
|
|
||||||
private onContinue = () => {
|
private onContinue = () => {
|
||||||
this.props.onFinished({ continue: true, invite: this.isPrivate && this.state.inviteUsersToNewRoom });
|
const opts = {
|
||||||
|
continue: true,
|
||||||
|
invite: this.isPrivate && this.state.inviteUsersToNewRoom,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.props.doUpgrade) {
|
||||||
|
this.props.doUpgrade(opts, this.onProgressCallback).then(() => {
|
||||||
|
this.props.onFinished(opts);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.props.onFinished(opts);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private onCancel = () => {
|
private onCancel = () => {
|
||||||
|
@ -118,6 +143,23 @@ export default class RoomUpgradeWarningDialog extends React.Component<IProps, IS
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let footer: JSX.Element;
|
||||||
|
if (this.state.progressText) {
|
||||||
|
footer = <span className="mx_RoomUpgradeWarningDialog_progress">
|
||||||
|
<ProgressBar value={this.state.progress} max={this.state.total} />
|
||||||
|
<div className="mx_RoomUpgradeWarningDialog_progressText">
|
||||||
|
{ this.state.progressText }
|
||||||
|
</div>
|
||||||
|
</span>;
|
||||||
|
} else {
|
||||||
|
footer = <DialogButtons
|
||||||
|
primaryButton={_t("Upgrade")}
|
||||||
|
onPrimaryButtonClick={this.onContinue}
|
||||||
|
cancelButton={_t("Cancel")}
|
||||||
|
onCancel={this.onCancel}
|
||||||
|
/>;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseDialog
|
<BaseDialog
|
||||||
className='mx_RoomUpgradeWarningDialog'
|
className='mx_RoomUpgradeWarningDialog'
|
||||||
|
@ -154,12 +196,7 @@ export default class RoomUpgradeWarningDialog extends React.Component<IProps, IS
|
||||||
</p>
|
</p>
|
||||||
{ inviteToggle }
|
{ inviteToggle }
|
||||||
</div>
|
</div>
|
||||||
<DialogButtons
|
{ footer }
|
||||||
primaryButton={_t("Upgrade")}
|
|
||||||
onPrimaryButtonClick={this.onContinue}
|
|
||||||
cancelButton={_t("Cancel")}
|
|
||||||
onCancel={this.onCancel}
|
|
||||||
/>
|
|
||||||
</BaseDialog>
|
</BaseDialog>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,7 @@ import SpaceStore from "../../../stores/SpaceStore";
|
||||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||||
import Modal from "../../../Modal";
|
import Modal from "../../../Modal";
|
||||||
import ManageRestrictedJoinRuleDialog from "../dialogs/ManageRestrictedJoinRuleDialog";
|
import ManageRestrictedJoinRuleDialog from "../dialogs/ManageRestrictedJoinRuleDialog";
|
||||||
import RoomUpgradeWarningDialog from "../dialogs/RoomUpgradeWarningDialog";
|
import RoomUpgradeWarningDialog, { IFinishedOpts } from "../dialogs/RoomUpgradeWarningDialog";
|
||||||
import QuestionDialog from "../dialogs/QuestionDialog";
|
|
||||||
import { upgradeRoom } from "../../../utils/RoomUpgrade";
|
import { upgradeRoom } from "../../../utils/RoomUpgrade";
|
||||||
import { arrayHasDiff } from "../../../utils/arrays";
|
import { arrayHasDiff } from "../../../utils/arrays";
|
||||||
import { useLocalEcho } from "../../../hooks/useLocalEcho";
|
import { useLocalEcho } from "../../../hooks/useLocalEcho";
|
||||||
|
@ -210,47 +209,70 @@ const JoinRuleSettings = ({ room, promptUpgrade, onError, beforeChange, closeSet
|
||||||
// Block this action on a room upgrade otherwise it'd make their room unjoinable
|
// Block this action on a room upgrade otherwise it'd make their room unjoinable
|
||||||
const targetVersion = preferredRestrictionVersion;
|
const targetVersion = preferredRestrictionVersion;
|
||||||
|
|
||||||
const modal = Modal.createTrackedDialog('Restricted join rule upgrade', '', RoomUpgradeWarningDialog, {
|
let warning: JSX.Element;
|
||||||
roomId: room.roomId,
|
|
||||||
targetVersion,
|
|
||||||
description: _t("This upgrade will allow members of selected spaces " +
|
|
||||||
"access to this room without an invite."),
|
|
||||||
});
|
|
||||||
|
|
||||||
const [resp] = await modal.finished;
|
|
||||||
if (!resp?.continue) return;
|
|
||||||
|
|
||||||
const userId = cli.getUserId();
|
const userId = cli.getUserId();
|
||||||
const unableToUpdateSomeParents = Array.from(SpaceStore.instance.getKnownParents(room.roomId))
|
const unableToUpdateSomeParents = Array.from(SpaceStore.instance.getKnownParents(room.roomId))
|
||||||
.some(roomId => !cli.getRoom(roomId)?.currentState.maySendStateEvent(EventType.SpaceChild, userId));
|
.some(roomId => !cli.getRoom(roomId)?.currentState.maySendStateEvent(EventType.SpaceChild, userId));
|
||||||
if (unableToUpdateSomeParents) {
|
if (unableToUpdateSomeParents) {
|
||||||
const modal = Modal.createTrackedDialog<[boolean]>('Parent relink warning', '', QuestionDialog, {
|
warning = <b>
|
||||||
title: _t("Before you upgrade"),
|
{ _t("This room is in some spaces you’re not an admin of. " +
|
||||||
description: (
|
"In those spaces, the old room will still be shown, " +
|
||||||
<div>{ _t("This room is in some spaces you’re not an admin of. " +
|
"but people will be prompted to join the new one.") }
|
||||||
"In those spaces, the old room will still be shown, " +
|
</b>;
|
||||||
"but people will be prompted to join the new one.") }</div>
|
|
||||||
),
|
|
||||||
hasCancelButton: true,
|
|
||||||
button: _t("Upgrade anyway"),
|
|
||||||
danger: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const [shouldUpgrade] = await modal.finished;
|
|
||||||
if (!shouldUpgrade) return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const roomId = await upgradeRoom(room, targetVersion, resp.invite, true, true, true);
|
Modal.createTrackedDialog('Restricted join rule upgrade', '', RoomUpgradeWarningDialog, {
|
||||||
closeSettingsFn();
|
roomId: room.roomId,
|
||||||
// switch to the new room in the background
|
targetVersion,
|
||||||
dis.dispatch({
|
description: <>
|
||||||
action: "view_room",
|
{ _t("This upgrade will allow members of selected spaces " +
|
||||||
room_id: roomId,
|
"access to this room without an invite.") }
|
||||||
});
|
{ warning }
|
||||||
// open new settings on this tab
|
</>,
|
||||||
dis.dispatch({
|
doUpgrade: async (
|
||||||
action: "open_room_settings",
|
opts: IFinishedOpts,
|
||||||
initial_tab_id: ROOM_SECURITY_TAB,
|
fn: (progressText: string, progress: number, total: number) => void,
|
||||||
|
): Promise<void> => {
|
||||||
|
const roomId = await upgradeRoom(
|
||||||
|
room,
|
||||||
|
targetVersion,
|
||||||
|
opts.invite,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
progress => {
|
||||||
|
const total = 2 + progress.updateSpacesTotal + progress.inviteUsersTotal;
|
||||||
|
if (!progress.roomUpgraded) {
|
||||||
|
fn(_t("Upgrading room"), 0, total);
|
||||||
|
} else if (!progress.roomSynced) {
|
||||||
|
fn(_t("Loading new room"), 1, total);
|
||||||
|
} else if (progress.inviteUsersProgress < progress.inviteUsersTotal) {
|
||||||
|
fn(_t("Sending invites... (%(progress)s out of %(count)s)", {
|
||||||
|
progress: progress.inviteUsersProgress,
|
||||||
|
count: progress.inviteUsersTotal,
|
||||||
|
}), 2 + progress.inviteUsersProgress, total);
|
||||||
|
} else if (progress.updateSpacesProgress < progress.updateSpacesTotal) {
|
||||||
|
fn(_t("Updating spaces... (%(progress)s out of %(count)s)", {
|
||||||
|
progress: progress.updateSpacesProgress,
|
||||||
|
count: progress.updateSpacesTotal,
|
||||||
|
}), 2 + progress.inviteUsersProgress + progress.updateSpacesProgress, total);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
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;
|
||||||
|
|
|
@ -1166,10 +1166,14 @@
|
||||||
"Anyone in <spaceName/> can find and join. You can select other spaces too.": "Anyone in <spaceName/> can find and join. You can select other spaces too.",
|
"Anyone in <spaceName/> can find and join. You can select other spaces too.": "Anyone in <spaceName/> can find and join. You can select other spaces too.",
|
||||||
"Anyone in a space can find and join. You can select multiple spaces.": "Anyone in a space can find and join. You can select multiple spaces.",
|
"Anyone in a space can find and join. You can select multiple spaces.": "Anyone in a space can find and join. You can select multiple spaces.",
|
||||||
"Space members": "Space members",
|
"Space members": "Space members",
|
||||||
"This upgrade will allow members of selected spaces access to this room without an invite.": "This upgrade will allow members of selected spaces access to this room without an invite.",
|
|
||||||
"Before you upgrade": "Before you upgrade",
|
|
||||||
"This room is in some spaces you’re not an admin of. In those spaces, the old room will still be shown, but people will be prompted to join the new one.": "This room is in some spaces you’re not an admin of. In those spaces, the old room will still be shown, but people will be prompted to join the new one.",
|
"This room is in some spaces you’re not an admin of. In those spaces, the old room will still be shown, but people will be prompted to join the new one.": "This room is in some spaces you’re not an admin of. In those spaces, the old room will still be shown, but people will be prompted to join the new one.",
|
||||||
"Upgrade anyway": "Upgrade anyway",
|
"This upgrade will allow members of selected spaces access to this room without an invite.": "This upgrade will allow members of selected spaces access to this room without an invite.",
|
||||||
|
"Upgrading room": "Upgrading room",
|
||||||
|
"Loading new room": "Loading new room",
|
||||||
|
"Sending invites... (%(progress)s out of %(count)s)|other": "Sending invites... (%(progress)s out of %(count)s)",
|
||||||
|
"Sending invites... (%(progress)s out of %(count)s)|one": "Sending invite...",
|
||||||
|
"Updating spaces... (%(progress)s out of %(count)s)|other": "Updating spaces... (%(progress)s out of %(count)s)",
|
||||||
|
"Updating spaces... (%(progress)s out of %(count)s)|one": "Updating space...",
|
||||||
"Message layout": "Message layout",
|
"Message layout": "Message layout",
|
||||||
"IRC": "IRC",
|
"IRC": "IRC",
|
||||||
"Modern": "Modern",
|
"Modern": "Modern",
|
||||||
|
|
|
@ -18,12 +18,21 @@ import { Room } from "matrix-js-sdk/src/models/room";
|
||||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||||
|
|
||||||
import { inviteUsersToRoom } from "../RoomInvite";
|
import { inviteUsersToRoom } from "../RoomInvite";
|
||||||
import Modal from "../Modal";
|
import Modal, { IHandle } 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";
|
import Spinner from "../components/views/elements/Spinner";
|
||||||
|
|
||||||
|
interface IProgress {
|
||||||
|
roomUpgraded: boolean;
|
||||||
|
roomSynced?: boolean;
|
||||||
|
inviteUsersProgress?: number;
|
||||||
|
inviteUsersTotal: number;
|
||||||
|
updateSpacesProgress?: number;
|
||||||
|
updateSpacesTotal: number;
|
||||||
|
}
|
||||||
|
|
||||||
export async function upgradeRoom(
|
export async function upgradeRoom(
|
||||||
room: Room,
|
room: Room,
|
||||||
targetVersion: string,
|
targetVersion: string,
|
||||||
|
@ -31,9 +40,38 @@ export async function upgradeRoom(
|
||||||
handleError = true,
|
handleError = true,
|
||||||
updateSpaces = true,
|
updateSpaces = true,
|
||||||
awaitRoom = false,
|
awaitRoom = false,
|
||||||
|
progressCallback?: (progress: IProgress) => void,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const cli = room.client;
|
const cli = room.client;
|
||||||
const spinnerModal = Modal.createDialog(Spinner, null, "mx_Dialog_spinner");
|
let spinnerModal: IHandle<any>;
|
||||||
|
if (!progressCallback) {
|
||||||
|
spinnerModal = Modal.createDialog(Spinner, null, "mx_Dialog_spinner");
|
||||||
|
}
|
||||||
|
|
||||||
|
let toInvite: string[];
|
||||||
|
if (inviteUsers) {
|
||||||
|
toInvite = [
|
||||||
|
...room.getMembersWithMembership("join"),
|
||||||
|
...room.getMembersWithMembership("invite"),
|
||||||
|
].map(m => m.userId).filter(m => m !== cli.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
let parentsToRelink: Room[];
|
||||||
|
if (updateSpaces) {
|
||||||
|
parentsToRelink = Array.from(SpaceStore.instance.getKnownParents(room.roomId))
|
||||||
|
.map(roomId => cli.getRoom(roomId))
|
||||||
|
.filter(parent => parent?.currentState.maySendStateEvent(EventType.SpaceChild, cli.getUserId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
const progress: IProgress = {
|
||||||
|
roomUpgraded: false,
|
||||||
|
roomSynced: (awaitRoom || inviteUsers) ? false : undefined,
|
||||||
|
inviteUsersProgress: inviteUsers ? 0 : undefined,
|
||||||
|
inviteUsersTotal: toInvite.length,
|
||||||
|
updateSpacesProgress: updateSpaces ? 0 : undefined,
|
||||||
|
updateSpacesTotal: parentsToRelink.length,
|
||||||
|
};
|
||||||
|
progressCallback?.(progress);
|
||||||
|
|
||||||
let newRoomId: string;
|
let newRoomId: string;
|
||||||
try {
|
try {
|
||||||
|
@ -49,6 +87,9 @@ export async function upgradeRoom(
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progress.roomUpgraded = true;
|
||||||
|
progressCallback?.(progress);
|
||||||
|
|
||||||
if (awaitRoom || inviteUsers) {
|
if (awaitRoom || inviteUsers) {
|
||||||
await new Promise<void>(resolve => {
|
await new Promise<void>(resolve => {
|
||||||
// already have the room
|
// already have the room
|
||||||
|
@ -67,33 +108,31 @@ export async function upgradeRoom(
|
||||||
};
|
};
|
||||||
cli.on("Room", checkForRoomFn);
|
cli.on("Room", checkForRoomFn);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
progress.roomSynced = true;
|
||||||
|
progressCallback?.(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inviteUsers) {
|
if (toInvite.length > 0) {
|
||||||
const toInvite = [
|
// Errors are handled internally to this function
|
||||||
...room.getMembersWithMembership("join"),
|
await inviteUsersToRoom(newRoomId, toInvite, () => {
|
||||||
...room.getMembersWithMembership("invite"),
|
progress.inviteUsersProgress++;
|
||||||
].map(m => m.userId).filter(m => m !== cli.getUserId());
|
progressCallback?.(progress);
|
||||||
|
});
|
||||||
if (toInvite.length > 0) {
|
|
||||||
// Errors are handled internally to this function
|
|
||||||
await inviteUsersToRoom(newRoomId, toInvite);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateSpaces) {
|
if (parentsToRelink.length > 0) {
|
||||||
const parents = SpaceStore.instance.getKnownParents(room.roomId);
|
|
||||||
try {
|
try {
|
||||||
for (const parentId of parents) {
|
for (const parent of parentsToRelink) {
|
||||||
const parent = cli.getRoom(parentId);
|
|
||||||
if (!parent?.currentState.maySendStateEvent(EventType.SpaceChild, cli.getUserId())) continue;
|
|
||||||
|
|
||||||
const currentEv = parent.currentState.getStateEvents(EventType.SpaceChild, room.roomId);
|
const currentEv = parent.currentState.getStateEvents(EventType.SpaceChild, room.roomId);
|
||||||
await cli.sendStateEvent(parentId, EventType.SpaceChild, {
|
await cli.sendStateEvent(parent.roomId, EventType.SpaceChild, {
|
||||||
...(currentEv?.getContent() || {}), // copy existing attributes like suggested
|
...(currentEv?.getContent() || {}), // copy existing attributes like suggested
|
||||||
via: [cli.getDomain()],
|
via: [cli.getDomain()],
|
||||||
}, newRoomId);
|
}, newRoomId);
|
||||||
await cli.sendStateEvent(parentId, EventType.SpaceChild, {}, room.roomId);
|
await cli.sendStateEvent(parent.roomId, EventType.SpaceChild, {}, room.roomId);
|
||||||
|
|
||||||
|
progress.updateSpacesProgress++;
|
||||||
|
progressCallback?.(progress);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// These errors are not critical to the room upgrade itself
|
// These errors are not critical to the room upgrade itself
|
||||||
|
@ -101,6 +140,6 @@ export async function upgradeRoom(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spinnerModal.close();
|
spinnerModal?.close();
|
||||||
return newRoomId;
|
return newRoomId;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue