Skip to content

Commit 9020bf4

Browse files
committed
Revert unnecessary updates
1 parent bbbfed9 commit 9020bf4

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

packages/host/app/components/matrix/room.gts

+9-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { TrackedObject, TrackedSet } from 'tracked-built-ins';
2929
import { v4 as uuidv4 } from 'uuid';
3030

3131
import { BoxelButton, LoadingIndicator } from '@cardstack/boxel-ui/components';
32-
import { eq, not, or } from '@cardstack/boxel-ui/helpers';
32+
import { and, eq, not, or } from '@cardstack/boxel-ui/helpers';
3333

3434
import {
3535
type getCard,
@@ -87,8 +87,14 @@ export default class Room extends Component<Signature> {
8787
{{#if (not this.doMatrixEventFlush.isRunning)}}
8888
<section
8989
class='room'
90-
data-room-settled={{this.doWhenRoomChanges.isIdle}}
91-
data-test-room-settled={{this.doWhenRoomChanges.isIdle}}
90+
data-room-settled={{(and
91+
this.doWhenRoomChanges.isIdle
92+
(not this.matrixService.isLoadingTimeline)
93+
)}}
94+
data-test-room-settled={{(and
95+
this.doWhenRoomChanges.isIdle
96+
(not this.matrixService.isLoadingTimeline)
97+
)}}
9298
data-test-room-name={{@roomResource.name}}
9399
data-test-room={{@roomId}}
94100
>

packages/host/app/services/matrix-service.ts

+5-21
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export default class MatrixService extends Service {
200200
this._currentRoomId = value;
201201
if (value) {
202202
this.loadAllTimelineEvents.perform(value);
203+
window.localStorage.setItem(CurrentRoomIdPersistenceKey, value);
203204
} else {
204205
window.localStorage.removeItem(CurrentRoomIdPersistenceKey);
205206
}
@@ -1226,8 +1227,9 @@ export default class MatrixService extends Service {
12261227
private loadAllTimelineEvents = restartableTask(async (roomId: string) => {
12271228
let roomData = this.ensureRoomData(roomId);
12281229
let room = this.client.getRoom(roomId);
1230+
let roomResource = this.roomResources.get(roomId);
12291231

1230-
if (!room) {
1232+
if (!room || !roomResource) {
12311233
throw new Error(`Cannot find room with id ${roomId}`);
12321234
}
12331235

@@ -1245,34 +1247,15 @@ export default class MatrixService extends Service {
12451247
}
12461248
}
12471249

1248-
let startTime = Date.now();
1249-
let checkCount = 0;
1250-
1250+
// Wait for all events to be loaded in roomResource
12511251
let timeline = room.getLiveTimeline();
12521252
let events = timeline.getEvents();
12531253
await new Promise<void>((resolve) => {
12541254
let checkEvents = () => {
1255-
checkCount++;
1256-
let elapsedTime = Date.now() - startTime;
12571255
let allEventsConsumed = events.every((event) =>
12581256
roomData.events.some((e) => e.event_id === event.getId()),
12591257
);
1260-
1261-
console.log(
1262-
`[Matrix Service] Waiting for events... (${elapsedTime}ms, attempt ${checkCount})`,
1263-
`\n - Events to consume: ${events.length}`,
1264-
`\n - Events consumed: ${
1265-
events.filter((event) =>
1266-
roomData.events.some((e) => e.event_id === event.getId()),
1267-
).length
1268-
}`,
1269-
`\n - All consumed: ${allEventsConsumed}`,
1270-
);
1271-
12721258
if (allEventsConsumed) {
1273-
console.log(
1274-
`[Matrix Service] All events consumed after ${elapsedTime}ms and ${checkCount} checks`,
1275-
);
12761259
resolve();
12771260
} else {
12781261
setTimeout(checkEvents, 100);
@@ -1281,6 +1264,7 @@ export default class MatrixService extends Service {
12811264

12821265
checkEvents();
12831266
});
1267+
await this.roomResources.get(roomId)?.loading;
12841268
} finally {
12851269
this.timelineLoadingState.set(roomId, false);
12861270
}

packages/host/tests/acceptance/ai-assistant-test.gts

+7-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ module('Acceptance | AI Assistant tests', function (hooks) {
183183
],
184184
});
185185
await click('[data-test-open-ai-assistant]');
186-
await waitFor('[data-test-message-field]');
186+
await waitFor(`[data-room-settled]`);
187187
const testCard = `${testRealmURL}Person/hassan`;
188188

189189
for (let i = 1; i <= 3; i++) {
@@ -261,7 +261,7 @@ module('Acceptance | AI Assistant tests', function (hooks) {
261261
],
262262
});
263263
await click('[data-test-open-ai-assistant]');
264-
264+
await waitFor(`[data-room-settled]`);
265265
assert
266266
.dom('[data-test-llm-select-selected]')
267267
.hasText(DEFAULT_LLM.split('/')[1]);
@@ -293,6 +293,7 @@ module('Acceptance | AI Assistant tests', function (hooks) {
293293
});
294294

295295
await click('[data-test-open-ai-assistant]');
296+
await waitFor(`[data-room-settled]`);
296297
await click('[data-test-submode-switcher] button');
297298
await click('[data-test-boxel-menu-item-text="Code"]');
298299
assert.dom('[data-test-llm-select-selected]').hasText('claude-3.5-sonnet');
@@ -326,6 +327,7 @@ module('Acceptance | AI Assistant tests', function (hooks) {
326327
'[data-test-cards-grid-item="http://test-realm/test/Person/fadhlan"]',
327328
);
328329
await click('[data-test-open-ai-assistant]');
330+
await waitFor(`[data-room-settled]`);
329331
assert.dom('[data-test-autoattached-file]').doesNotExist();
330332
assert.dom('[data-test-autoattached-card]').exists();
331333
await click('[data-test-submode-switcher] > [data-test-boxel-button]');
@@ -348,6 +350,7 @@ module('Acceptance | AI Assistant tests', function (hooks) {
348350
});
349351

350352
await click('[data-test-open-ai-assistant]');
353+
await waitFor(`[data-room-settled]`);
351354
assert.dom('[data-test-choose-file-btn]').hasText('Attach File');
352355

353356
await click('[data-test-choose-file-btn]');
@@ -412,6 +415,7 @@ module('Acceptance | AI Assistant tests', function (hooks) {
412415
],
413416
});
414417
await click('[data-test-open-ai-assistant]');
418+
await waitFor(`[data-room-settled]`);
415419
assert.dom('[data-test-choose-file-btn]').hasText('Attach File');
416420

417421
await click('[data-test-file="person.gts"]');
@@ -453,6 +457,7 @@ module('Acceptance | AI Assistant tests', function (hooks) {
453457
});
454458

455459
await click('[data-test-open-ai-assistant]');
460+
await waitFor(`[data-room-settled]`);
456461
await click('[data-test-past-sessions-button]');
457462

458463
assert.dom('[data-test-past-sessions]').exists();

0 commit comments

Comments
 (0)