Fix rate limit when reordering in space lobby (#2254)

* move can drop lobby item logic to hook

* add comment

* resolve rate limit when reordering space children
This commit is contained in:
Ajay Bura 2025-05-26 14:21:27 +05:30 committed by GitHub
parent 83057ebbd4
commit a23279e633
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 270 additions and 187 deletions

View file

@ -28,9 +28,11 @@ import { allRoomsAtom } from '../../state/room-list/roomList';
import { mDirectAtom } from '../../state/mDirectList';
import { useMatrixClient } from '../../hooks/useMatrixClient';
import { getViaServers } from '../../plugins/via-servers';
import { rateLimitedActions } from '../../utils/matrix';
import { useAlive } from '../../hooks/useAlive';
function SpaceAddExistingContent({ roomId, spaces: onlySpaces }) {
const mountStore = useStore(roomId);
const alive = useAlive();
const [debounce] = useState(new Debounce());
const [process, setProcess] = useState(null);
const [allRoomIds, setAllRoomIds] = useState([]);
@ -68,14 +70,14 @@ function SpaceAddExistingContent({ roomId, spaces: onlySpaces }) {
const handleAdd = async () => {
setProcess(`Adding ${selected.length} items...`);
const promises = selected.map((rId) => {
await rateLimitedActions(selected, async (rId) => {
const room = mx.getRoom(rId);
const via = getViaServers(room);
if (via.length === 0) {
via.push(getIdServer(rId));
}
return mx.sendStateEvent(
await mx.sendStateEvent(
roomId,
'm.space.child',
{
@ -87,9 +89,7 @@ function SpaceAddExistingContent({ roomId, spaces: onlySpaces }) {
);
});
mountStore.setItem(true);
await Promise.allSettled(promises);
if (mountStore.getItem() !== true) return;
if (!alive()) return;
const roomIds = onlySpaces ? [...spaces] : [...rooms, ...directs];
const allIds = roomIds.filter(