mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 00:51:17 -08:00
5 files changed
+34
-20
No files matched your search
@@ -22,26 +22,28 @@ export function useDeviceDisplayName(mx: MatrixClient | undefined) {
|
||||
const updatedRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!mx || updatedRef.current) return;
|
||||
if (!mx || updatedRef.current) return undefined;
|
||||
|
||||
let cleanup: (() => void) | undefined;
|
||||
|
||||
const state = mx.getSyncState();
|
||||
if (state && SYNC_READY.has(state)) {
|
||||
updatedRef.current = true;
|
||||
updateDeviceName(mx).catch(() => {});
|
||||
return;
|
||||
} else {
|
||||
const onSync = (syncState: SyncState) => {
|
||||
if (SYNC_READY.has(syncState)) {
|
||||
mx.removeListener(ClientEvent.Sync, onSync);
|
||||
updatedRef.current = true;
|
||||
updateDeviceName(mx).catch(() => {});
|
||||
}
|
||||
};
|
||||
mx.on(ClientEvent.Sync, onSync);
|
||||
cleanup = () => {
|
||||
mx.removeListener(ClientEvent.Sync, onSync);
|
||||
};
|
||||
}
|
||||
|
||||
const onSync = (syncState: SyncState) => {
|
||||
if (SYNC_READY.has(syncState)) {
|
||||
mx.removeListener(ClientEvent.Sync, onSync);
|
||||
updatedRef.current = true;
|
||||
updateDeviceName(mx).catch(() => {});
|
||||
}
|
||||
};
|
||||
mx.on(ClientEvent.Sync, onSync);
|
||||
|
||||
return () => {
|
||||
mx.removeListener(ClientEvent.Sync, onSync);
|
||||
};
|
||||
return cleanup;
|
||||
}, [mx]);
|
||||
}
|
||||
@@ -172,6 +172,7 @@ export async function getRoomMessages(
|
||||
): Promise<RoomMessage[]> {
|
||||
const messages: RoomMessage[] = [];
|
||||
let from: string | undefined;
|
||||
/* eslint-disable no-await-in-loop */
|
||||
do {
|
||||
const params = new URLSearchParams({ dir: 'b', limit: '100' });
|
||||
if (from) params.set('from', from);
|
||||
@@ -198,6 +199,7 @@ export async function getRoomMessages(
|
||||
});
|
||||
from = data.end;
|
||||
} while (from);
|
||||
/* eslint-enable no-await-in-loop */
|
||||
messages.reverse();
|
||||
return messages;
|
||||
}
|
||||
@@ -119,20 +119,24 @@ test.describe('live timeline', () => {
|
||||
});
|
||||
await app.openRoom(`${tag} Room`);
|
||||
|
||||
for (let i = 1; i <= BURST_SIZE; i += 1) {
|
||||
await sendText(hsBaseUrl, remote.accessToken, room, `${tag}-b${i}`, i);
|
||||
}
|
||||
await Promise.all(
|
||||
Array.from({ length: BURST_SIZE }, (_, i) =>
|
||||
sendText(hsBaseUrl, remote.accessToken, room, `${tag}-b${i + 1}`, i + 1)
|
||||
)
|
||||
);
|
||||
|
||||
const expected = (await getRoomMessages(hsBaseUrl, user.accessToken, room))
|
||||
.filter((m) => m.body.startsWith(`${tag}-b`))
|
||||
.map((m) => m.body);
|
||||
expect(expected).toEqual(Array.from({ length: BURST_SIZE }, (_, i) => `${tag}-b${i + 1}`));
|
||||
|
||||
/* eslint-disable no-await-in-loop */
|
||||
for (const body of expected) {
|
||||
await expect(page.getByText(body, { exact: true })).toHaveCount(1, {
|
||||
timeout: 120_000,
|
||||
});
|
||||
}
|
||||
/* eslint-enable no-await-in-loop */
|
||||
|
||||
const domOrder = await page.getByText(new RegExp(`^${tag}-b\\d+$`)).allTextContents();
|
||||
expect(domOrder).toEqual(expected);
|
||||
|
||||
@@ -67,9 +67,7 @@ async function sendHistory(
|
||||
prefix: string,
|
||||
bodies: string[]
|
||||
): Promise<void> {
|
||||
for (let i = 0; i < bodies.length; i += 1) {
|
||||
await sendMessage(baseUrl, token, roomId, `${prefix}-${bodies[i]}`);
|
||||
}
|
||||
await Promise.all(bodies.map((body) => sendMessage(baseUrl, token, roomId, `${prefix}-${body}`)));
|
||||
}
|
||||
|
||||
async function wheelToTopUntilVisible(page: Page, text: string): Promise<void> {
|
||||
@@ -170,22 +168,26 @@ test.describe('sliding sync timeline', () => {
|
||||
timeout: 120_000,
|
||||
});
|
||||
|
||||
/* eslint-disable no-await-in-loop */
|
||||
for (let i = 0; i < SEND_DELAYS_MS.length; i += 1) {
|
||||
if (SEND_DELAYS_MS[i]! > 0) await page.waitForTimeout(SEND_DELAYS_MS[i]!);
|
||||
await sendMessage(hsBaseUrl, user.accessToken, room, `${tag}-live-${i + 1}`);
|
||||
}
|
||||
/* eslint-enable no-await-in-loop */
|
||||
|
||||
await app.openRoom(`${tag} Home`);
|
||||
await expect(page.getByText(`${tag}-seed`, { exact: true })).toBeVisible({
|
||||
timeout: 120_000,
|
||||
});
|
||||
|
||||
/* eslint-disable no-await-in-loop */
|
||||
for (let i = 0; i < SEND_DELAYS_MS.length; i += 1) {
|
||||
await expect(page.getByText(`${tag}-live-${i + 1}`, { exact: true })).toHaveCount(1, {
|
||||
timeout: 120_000,
|
||||
});
|
||||
await expect(page.getByText(`${tag}-live-${i + 1}`, { exact: true })).toBeVisible();
|
||||
}
|
||||
/* eslint-enable no-await-in-loop */
|
||||
|
||||
const domOrder = await page.getByText(new RegExp(`^${tag}-live-\\d+$`)).allTextContents();
|
||||
expect(domOrder).toEqual(SEND_DELAYS_MS.map((_, i) => `${tag}-live-${i + 1}`));
|
||||
|
||||
@@ -86,19 +86,23 @@ test.describe('timeline recovery', () => {
|
||||
await context.setOffline(true);
|
||||
|
||||
const burstCount = 6;
|
||||
/* eslint-disable no-await-in-loop */
|
||||
for (let i = 0; i < burstCount; i += 1) {
|
||||
txnCounter += 1;
|
||||
await sendText(hsBaseUrl, bob.accessToken, room, `${tag}-burst-${i + 1}`, txnCounter);
|
||||
}
|
||||
/* eslint-enable no-await-in-loop */
|
||||
|
||||
await context.setOffline(false);
|
||||
|
||||
/* eslint-disable no-await-in-loop */
|
||||
for (let i = 0; i < burstCount; i += 1) {
|
||||
await expect(page.getByText(`${tag}-burst-${i + 1}`, { exact: true })).toHaveCount(1, {
|
||||
timeout: 180_000,
|
||||
});
|
||||
await expect(page.getByText(`${tag}-burst-${i + 1}`, { exact: true })).toBeVisible();
|
||||
}
|
||||
/* eslint-enable no-await-in-loop */
|
||||
|
||||
const canonical = (await getRoomMessages(hsBaseUrl, alice.accessToken, room))
|
||||
.map((m) => m.body)
|
||||
|
||||
Reference in new issue
Block a user