Skip to content

Commit ebb034f

Browse files
committed
Check room membership before processing events in room resource
1 parent 868be56 commit ebb034f

30 files changed

+112
-89
lines changed

packages/host/app/lib/matrix-classes/room.ts

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ export default class Room {
4444
?.name;
4545
}
4646

47+
get memberIds(): string[] {
48+
let memberEvents = (this._roomState?.events
49+
.get('m.room.member')
50+
?.values() ?? []) as MatrixSDK.MatrixEvent[];
51+
let memberIds = [...memberEvents.map((ev) => ev.event.state_key)];
52+
return memberIds.filter((id) => id !== undefined) as string[];
53+
}
54+
4755
notifyRoomStateUpdated(rs: MatrixSDK.RoomState) {
4856
this._roomState = rs; // this is usually the same object, but some internal state has changed. This assignment kicks off reactivity.
4957
}

packages/host/app/resources/room.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,18 @@ export class RoomResource extends Resource<Args> {
111111
this.matrixRoom = roomId
112112
? await this.matrixService.getRoomData(roomId)
113113
: undefined; //look at the note in the EventSendingContext interface for why this is awaited
114-
if (this.matrixRoom) {
115-
await this.loadFromEvents(roomId);
114+
if (!this.matrixRoom) {
115+
return;
116+
}
117+
let memberIds = this.matrixRoom.memberIds;
118+
// If the AI bot is not in the room, don't process the events
119+
if (!memberIds) {
120+
return;
121+
}
122+
if (!memberIds.includes(this.matrixService.aiBotUserId)) {
123+
return;
116124
}
125+
await this.loadFromEvents(roomId);
117126
} catch (e) {
118127
throw new Error(`Error loading room ${e}`);
119128
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ module('Acceptance | AI Assistant tests', function (hooks) {
127127
setupServerSentEvents(hooks);
128128
setupOnSave(hooks);
129129
let { createAndJoinRoom, getRoomState } = setupMockMatrix(hooks, {
130-
loggedInAs: '@testuser:staging',
130+
loggedInAs: '@testuser:localhost',
131131
activeRealms: [baseRealm.url, testRealmURL],
132132
});
133133
setupBaseRealm(hooks);
134134

135135
hooks.beforeEach(async function () {
136-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
136+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
137137
setupUserSubscription(matrixRoomId);
138138

139139
class Pet extends CardDef {
@@ -366,7 +366,7 @@ module('Acceptance | AI Assistant tests', function (hooks) {
366366
await click('[data-test-open-ai-assistant]');
367367
assert.dom('[data-test-llm-select-selected]').hasText('claude-3.5-sonnet');
368368

369-
createAndJoinRoom('@testuser:staging', 'room-test-2');
369+
createAndJoinRoom('@testuser:localhost', 'room-test-2');
370370

371371
await click('[data-test-past-sessions-button]');
372372
await waitFor("[data-test-enter-room='mock_room_2']");

packages/host/tests/acceptance/basic-test.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ module('Acceptance | basic tests', function (hooks) {
2121
setupLocalIndexing(hooks);
2222
setupServerSentEvents(hooks);
2323
let { createAndJoinRoom } = setupMockMatrix(hooks, {
24-
loggedInAs: '@testuser:staging',
24+
loggedInAs: '@testuser:localhost',
2525
activeRealms: [testRealmURL],
2626
});
2727

2828
hooks.beforeEach(async function () {
29-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
29+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
3030
setupUserSubscription(matrixRoomId);
3131

3232
let loaderService = lookupLoaderService();

packages/host/tests/acceptance/code-submode-test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ module('Acceptance | code submode tests', function (_hooks) {
418418
setupLocalIndexing(hooks);
419419
setupServerSentEvents(hooks);
420420
let { setActiveRealms, createAndJoinRoom } = setupMockMatrix(hooks, {
421-
loggedInAs: '@testuser:staging',
421+
loggedInAs: '@testuser:localhost',
422422
});
423423

424424
async function openNewFileModal(menuSelection: string) {
@@ -428,7 +428,7 @@ module('Acceptance | code submode tests', function (_hooks) {
428428
}
429429

430430
hooks.beforeEach(async function () {
431-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
431+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
432432
setupUserSubscription(matrixRoomId);
433433

434434
let realmServerService = this.owner.lookup(
@@ -442,7 +442,7 @@ module('Acceptance | code submode tests', function (_hooks) {
442442
await setupAcceptanceTestRealm({
443443
realmURL: personalRealmURL,
444444
permissions: {
445-
'@testuser:staging': ['read', 'write', 'realm-owner'],
445+
'@testuser:localhost': ['read', 'write', 'realm-owner'],
446446
},
447447
contents: {
448448
'hello.txt': txtSource,
@@ -456,7 +456,7 @@ module('Acceptance | code submode tests', function (_hooks) {
456456
await setupAcceptanceTestRealm({
457457
realmURL: additionalRealmURL,
458458
permissions: {
459-
'@testuser:staging': ['read', 'write', 'realm-owner'],
459+
'@testuser:localhost': ['read', 'write', 'realm-owner'],
460460
},
461461
contents: {
462462
'hello.txt': txtSource,
@@ -528,12 +528,12 @@ module('Acceptance | code submode tests', function (_hooks) {
528528
setupLocalIndexing(hooks);
529529
setupServerSentEvents(hooks);
530530
let { setActiveRealms, createAndJoinRoom } = setupMockMatrix(hooks, {
531-
loggedInAs: '@testuser:staging',
531+
loggedInAs: '@testuser:localhost',
532532
activeRealms: [testRealmURL],
533533
});
534534

535535
hooks.beforeEach(async function () {
536-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
536+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
537537
setupUserSubscription(matrixRoomId);
538538

539539
monacoService = this.owner.lookup(

packages/host/tests/acceptance/code-submode/create-file-test.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ module('Acceptance | code submode | create-file tests', function (hooks) {
202202
setupServerSentEvents(hooks);
203203
setupOnSave(hooks);
204204
let { setRealmPermissions, createAndJoinRoom } = setupMockMatrix(hooks, {
205-
loggedInAs: '@testuser:staging',
205+
loggedInAs: '@testuser:localhost',
206206
activeRealms: [baseRealm.url, testRealmURL, testRealmURL2],
207207
});
208208

@@ -215,7 +215,7 @@ module('Acceptance | code submode | create-file tests', function (hooks) {
215215
contents: files,
216216
}));
217217

218-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
218+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
219219
setupUserSubscription(matrixRoomId);
220220

221221
lookupNetworkService().mount(

packages/host/tests/acceptance/code-submode/editor-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ module('Acceptance | code submode | editor tests', function (hooks) {
4545
setupServerSentEvents(hooks);
4646
setupOnSave(hooks);
4747
let { setRealmPermissions, createAndJoinRoom } = setupMockMatrix(hooks, {
48-
loggedInAs: '@testuser:staging',
48+
loggedInAs: '@testuser:localhost',
4949
activeRealms: [baseRealm.url, testRealmURL],
5050
});
5151

5252
hooks.beforeEach(async function () {
5353
setRealmPermissions({ [testRealmURL]: ['read', 'write'] });
5454

55-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
55+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
5656
setupUserSubscription(matrixRoomId);
5757

5858
monacoService = this.owner.lookup(

packages/host/tests/acceptance/code-submode/file-tree-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,14 @@ module('Acceptance | code submode | file-tree tests', function (hooks) {
192192
setupApplicationTest(hooks);
193193
setupLocalIndexing(hooks);
194194
let { setRealmPermissions, createAndJoinRoom } = setupMockMatrix(hooks, {
195-
loggedInAs: '@testuser:staging',
195+
loggedInAs: '@testuser:localhost',
196196
activeRealms: [testRealmURL],
197197
});
198198

199199
hooks.beforeEach(async function () {
200200
setRealmPermissions({ [testRealmURL]: ['read', 'write'] });
201201

202-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
202+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
203203
setupUserSubscription(matrixRoomId);
204204

205205
const numStubFiles = 100;

packages/host/tests/acceptance/code-submode/inspector-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ module('Acceptance | code submode | inspector tests', function (hooks) {
404404
setupServerSentEvents(hooks);
405405
setupOnSave(hooks);
406406
let { setRealmPermissions, createAndJoinRoom } = setupMockMatrix(hooks, {
407-
loggedInAs: '@testuser:staging',
407+
loggedInAs: '@testuser:localhost',
408408
activeRealms: [testRealmURL, testRealmURL2],
409409
});
410410

@@ -414,7 +414,7 @@ module('Acceptance | code submode | inspector tests', function (hooks) {
414414
[testRealmURL2]: ['read', 'write'],
415415
});
416416

417-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
417+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
418418
setupUserSubscription(matrixRoomId);
419419

420420
// this seeds the loader used during index which obtains url mappings

packages/host/tests/acceptance/code-submode/playground-test.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module('Acceptance | code-submode | playground panel', function (hooks) {
3434
setupServerSentEvents(hooks);
3535
let { setRealmPermissions, setActiveRealms, createAndJoinRoom } =
3636
setupMockMatrix(hooks, {
37-
loggedInAs: '@testuser:staging',
37+
loggedInAs: '@testuser:localhost',
3838
activeRealms: [testRealmURL],
3939
});
4040
setupOnSave(hooks);
@@ -125,7 +125,7 @@ export class BlogPost extends CardDef {
125125
}`;
126126

127127
hooks.beforeEach(async function () {
128-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
128+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
129129
setupUserSubscription(matrixRoomId);
130130

131131
({ realm } = await setupAcceptanceTestRealm({

packages/host/tests/acceptance/code-submode/recent-files-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ module('Acceptance | code submode | recent files tests', function (hooks) {
185185
setupApplicationTest(hooks);
186186
setupLocalIndexing(hooks);
187187
let { createAndJoinRoom } = setupMockMatrix(hooks, {
188-
loggedInAs: '@testuser:staging',
188+
loggedInAs: '@testuser:localhost',
189189
activeRealms: [baseRealm.url, testRealmURL],
190190
});
191191

192192
hooks.beforeEach(async function () {
193-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
193+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
194194
setupUserSubscription(matrixRoomId);
195195

196196
// this seeds the loader used during index which obtains url mappings

packages/host/tests/acceptance/code-submode/schema-editor-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ module('Acceptance | code submode | schema editor tests', function (hooks) {
229229
setupOnSave(hooks);
230230
setupServerSentEvents(hooks);
231231
let { createAndJoinRoom } = setupMockMatrix(hooks, {
232-
loggedInAs: '@testuser:staging',
232+
loggedInAs: '@testuser:localhost',
233233
activeRealms: [baseRealm.url, testRealmURL],
234234
});
235235

236236
hooks.beforeEach(async function () {
237-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
237+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
238238
setupUserSubscription(matrixRoomId);
239239

240240
// this seeds the loader used during index which obtains url mappings

packages/host/tests/acceptance/code-submode/spec-test.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ module('Acceptance | Spec preview', function (hooks) {
123123

124124
let { setRealmPermissions, setActiveRealms, createAndJoinRoom } =
125125
setupMockMatrix(hooks, {
126-
loggedInAs: '@testuser:staging',
126+
loggedInAs: '@testuser:localhost',
127127
activeRealms: [testRealmURL, testRealm2URL],
128128
});
129129

130130
hooks.beforeEach(async function () {
131-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
131+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
132132
setupUserSubscription(matrixRoomId);
133133

134134
// this seeds the loader used during index which obtains url mappings

packages/host/tests/acceptance/commands-test.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ module('Acceptance | Commands tests', function (hooks) {
6868
setupOnSave(hooks);
6969
let { simulateRemoteMessage, getRoomIds, getRoomEvents, createAndJoinRoom } =
7070
setupMockMatrix(hooks, {
71-
loggedInAs: '@testuser:staging',
71+
loggedInAs: '@testuser:localhost',
7272
activeRealms: [baseRealm.url, testRealmURL],
7373
});
7474

7575
setupBaseRealm(hooks);
7676

7777
hooks.beforeEach(async function () {
78-
matrixRoomId = await createAndJoinRoom('@testuser:staging', 'room-test');
78+
matrixRoomId = await createAndJoinRoom('@testuser:localhost', 'room-test');
7979
setupUserSubscription(matrixRoomId);
8080

8181
class Pet extends CardDef {

packages/host/tests/acceptance/interact-submode-test.gts

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ module('Acceptance | interact submode tests', function (hooks) {
5656
setupOnSave(hooks);
5757
let { setRealmPermissions, setActiveRealms, createAndJoinRoom } =
5858
setupMockMatrix(hooks, {
59-
loggedInAs: '@testuser:staging',
59+
loggedInAs: '@testuser:localhost',
6060
activeRealms: [testRealmURL, testRealm2URL, testRealm3URL],
6161
});
6262

6363
hooks.beforeEach(async function () {
64-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
64+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
6565
setupUserSubscription(matrixRoomId);
6666

6767
let loader = lookupLoaderService().loader;
@@ -1347,7 +1347,7 @@ module('Acceptance | interact submode tests', function (hooks) {
13471347
assert.notStrictEqual(token, null);
13481348

13491349
let claims = claimsFromRawToken(token!);
1350-
assert.deepEqual(claims.user, '@testuser:staging');
1350+
assert.deepEqual(claims.user, '@testuser:localhost');
13511351
assert.strictEqual(claims.realm, 'http://test-realm/test2/');
13521352
assert.deepEqual(claims.permissions, ['read', 'write']);
13531353
}

packages/host/tests/acceptance/operator-mode-acceptance-test.gts

+9-9
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ module('Acceptance | operator mode tests', function (hooks) {
5757
setupOnSave(hooks);
5858
let { setExpiresInSec, createAndJoinRoom, simulateRemoteMessage } =
5959
setupMockMatrix(hooks, {
60-
loggedInAs: '@testuser:staging',
60+
loggedInAs: '@testuser:localhost',
6161
activeRealms: [testRealmURL],
6262
});
6363

6464
hooks.beforeEach(async function () {
65-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
65+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
6666
setupUserSubscription(matrixRoomId);
6767

6868
setExpiresInSec(60 * 60);
@@ -877,7 +877,7 @@ module('Acceptance | operator mode tests', function (hooks) {
877877
type: 'user',
878878
id: 1,
879879
attributes: {
880-
matrixUserId: '@testuser:staging',
880+
matrixUserId: '@testuser:localhost',
881881
stripeCustomerId: 'stripe-id-1',
882882
creditsAvailableInPlanAllowance: 1000,
883883
creditsIncludedInPlanAllowance: 1000,
@@ -949,7 +949,7 @@ module('Acceptance | operator mode tests', function (hooks) {
949949
headers: {
950950
Authorization: createJWT(
951951
{
952-
user: '@testuser:staging',
952+
user: '@testuser:localhost',
953953
sessionRoom: matrixRoomId,
954954
},
955955
'1d',
@@ -980,14 +980,14 @@ module('Acceptance | operator mode tests', function (hooks) {
980980
assert.dom('[data-test-profile-popover]').doesNotExist();
981981
assert.dom('[data-test-settings-modal]').exists();
982982

983-
assert.dom('[data-test-profile-icon]').hasText('T'); // "T", from first letter of: @testuser:staging
983+
assert.dom('[data-test-profile-icon]').hasText('T'); // "T", from first letter of: @testuser:localhost
984984
assert.dom('[data-test-profile-display-name]').hasText(''); // No display name set yet
985985
assert
986986
.dom('[data-test-profile-icon]')
987987
.hasStyle({ backgroundColor: 'rgb(34, 221, 152)' });
988988
assert
989989
.dom('[data-test-profile-icon-handle]')
990-
.hasText('@testuser:staging');
990+
.hasText('@testuser:localhost');
991991

992992
await fillIn('[data-test-display-name-field]', '');
993993
assert
@@ -1091,7 +1091,7 @@ module('Acceptance | operator mode tests', function (hooks) {
10911091
.hasAttribute(
10921092
'href',
10931093
`https://extra-credits-payment-link-1250?client_reference_id=${encodeWebSafeBase64(
1094-
'@testuser:staging',
1094+
'@testuser:localhost',
10951095
)}`,
10961096
);
10971097
assert.dom('[data-test-pay-button="0"]').hasAttribute('target', '_blank');
@@ -1100,7 +1100,7 @@ module('Acceptance | operator mode tests', function (hooks) {
11001100
.hasAttribute(
11011101
'href',
11021102
`https://extra-credits-payment-link-15000?client_reference_id=${encodeWebSafeBase64(
1103-
'@testuser:staging',
1103+
'@testuser:localhost',
11041104
)}`,
11051105
);
11061106
assert.dom('[data-test-pay-button="1"]').hasAttribute('target', '_blank');
@@ -1109,7 +1109,7 @@ module('Acceptance | operator mode tests', function (hooks) {
11091109
.hasAttribute(
11101110
'href',
11111111
`https://extra-credits-payment-link-80000?client_reference_id=${encodeWebSafeBase64(
1112-
'@testuser:staging',
1112+
'@testuser:localhost',
11131113
)}`,
11141114
);
11151115
assert.dom('[data-test-pay-button="2"]').hasAttribute('target', '_blank');

packages/host/tests/acceptance/permissioned-realm-test.gts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ module('Acceptance | permissioned realm tests', function (hooks) {
1919
setupLocalIndexing(hooks);
2020
setupServerSentEvents(hooks);
2121
let { createAndJoinRoom } = setupMockMatrix(hooks, {
22-
loggedInAs: '@testuser:staging',
22+
loggedInAs: '@testuser:localhost',
2323
activeRealms: [testRealmURL],
2424
});
2525

2626
hooks.beforeEach(async function () {
27-
matrixRoomId = createAndJoinRoom('@testuser:staging', 'room-test');
27+
matrixRoomId = createAndJoinRoom('@testuser:localhost', 'room-test');
2828
setupUserSubscription(matrixRoomId);
2929

3030
let loader = lookupLoaderService().loader;

0 commit comments

Comments
 (0)