Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 886959f

Browse files
committed
port rate limiting code over to space creation wizard's add existing rooms
1 parent acce9a4 commit 886959f

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/components/structures/SpaceRoomView.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import {useStateToggle} from "../../hooks/useStateToggle";
5252
import SpaceStore from "../../stores/SpaceStore";
5353
import FacePile from "../views/elements/FacePile";
5454
import {AddExistingToSpace} from "../views/dialogs/AddExistingToSpaceDialog";
55-
import {allSettled} from "../../utils/promise";
55+
import {sleep} from "../../utils/promise";
5656
import {calculateRoomVia} from "../../utils/permalinks/Permalinks";
5757

5858
interface IProps {
@@ -389,15 +389,24 @@ const SpaceAddExistingRooms = ({ space, onFinished }) => {
389389
let buttonLabel = _t("Skip for now");
390390
if (selectedToAdd.size > 0) {
391391
onClick = async () => {
392-
// TODO rate limiting
393392
setBusy(true);
394-
try {
395-
await allSettled(Array.from(selectedToAdd).map((room) =>
396-
SpaceStore.instance.addRoomToSpace(space, room.roomId, calculateRoomVia(room))));
397-
onFinished(true);
398-
} catch (e) {
399-
console.error("Failed to add rooms to space", e);
400-
setError(_t("Failed to add rooms to space"));
393+
394+
for (const room of selectedToAdd) {
395+
const via = calculateRoomVia(room);
396+
try {
397+
await SpaceStore.instance.addRoomToSpace(space, room.roomId, via).catch(async e => {
398+
if (e.errcode === "M_LIMIT_EXCEEDED") {
399+
await sleep(e.data.retry_after_ms);
400+
return SpaceStore.instance.addRoomToSpace(space, room.roomId, via); // retry
401+
}
402+
403+
throw e;
404+
});
405+
} catch (e) {
406+
console.error("Failed to add rooms to space", e);
407+
setError(_t("Failed to add rooms to space"));
408+
break;
409+
}
401410
}
402411
setBusy(false);
403412
};

0 commit comments

Comments
 (0)