Make join button on space hierarchy action in the background (#7041)
This commit is contained in:
parent
43cbb947b6
commit
27e16362b6
7 changed files with 97 additions and 61 deletions
|
@ -25,6 +25,7 @@ import SpaceStore from "../stores/SpaceStore";
|
|||
import Spinner from "../components/views/elements/Spinner";
|
||||
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
|
||||
interface IProgress {
|
||||
roomUpgraded: boolean;
|
||||
|
@ -35,6 +36,23 @@ interface IProgress {
|
|||
updateSpacesTotal: number;
|
||||
}
|
||||
|
||||
export async function awaitRoomDownSync(cli: MatrixClient, roomId: string): Promise<Room> {
|
||||
const room = cli.getRoom(roomId);
|
||||
if (room) return room; // already have the room
|
||||
|
||||
return new Promise<Room>(resolve => {
|
||||
// We have to wait for the js-sdk to give us the room back so
|
||||
// we can more effectively abuse the MultiInviter behaviour
|
||||
// which heavily relies on the Room object being available.
|
||||
const checkForRoomFn = (room: Room) => {
|
||||
if (room.roomId !== roomId) return;
|
||||
resolve(room);
|
||||
cli.off("Room", checkForRoomFn);
|
||||
};
|
||||
cli.on("Room", checkForRoomFn);
|
||||
});
|
||||
}
|
||||
|
||||
export async function upgradeRoom(
|
||||
room: Room,
|
||||
targetVersion: string,
|
||||
|
@ -93,24 +111,7 @@ export async function upgradeRoom(
|
|||
progressCallback?.(progress);
|
||||
|
||||
if (awaitRoom || inviteUsers) {
|
||||
await new Promise<void>(resolve => {
|
||||
// already have the room
|
||||
if (room.client.getRoom(newRoomId)) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
// We have to wait for the js-sdk to give us the room back so
|
||||
// we can more effectively abuse the MultiInviter behaviour
|
||||
// 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);
|
||||
});
|
||||
|
||||
await awaitRoomDownSync(room.client, newRoomId);
|
||||
progress.roomSynced = true;
|
||||
progressCallback?.(progress);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue