Skip to content

Commit fbb39af

Browse files
committed
Make changes as requested by reviewers, cleaning up the code a bit
1 parent 2a3fc53 commit fbb39af

File tree

3 files changed

+98
-160
lines changed

3 files changed

+98
-160
lines changed

spec/integ/matrix-client-event-timeline.spec.ts

Lines changed: 22 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -144,44 +144,6 @@ const THREAD_REPLY = utils.mkEvent({
144144

145145
THREAD_ROOT.unsigned["m.relations"]["io.element.thread"].latest_event = THREAD_REPLY;
146146

147-
const STABLE_THREAD_ROOT = utils.mkEvent({
148-
room: roomId,
149-
user: userId,
150-
type: "m.room.message",
151-
content: {
152-
"body": "thread root",
153-
"msgtype": "m.text",
154-
},
155-
unsigned: {
156-
"m.relations": {
157-
"m.thread": {
158-
//"latest_event": undefined,
159-
"count": 1,
160-
"current_user_participated": true,
161-
},
162-
},
163-
},
164-
event: false,
165-
});
166-
167-
const STABLE_THREAD_REPLY = utils.mkEvent({
168-
room: roomId,
169-
user: userId,
170-
type: "m.room.message",
171-
content: {
172-
"body": "thread reply",
173-
"msgtype": "m.text",
174-
"m.relates_to": {
175-
// We can't use the const here because we change server support mode for test
176-
rel_type: "m.thread",
177-
event_id: THREAD_ROOT.event_id,
178-
},
179-
},
180-
event: false,
181-
});
182-
183-
STABLE_THREAD_ROOT.unsigned["m.relations"]["m.thread"].latest_event = STABLE_THREAD_REPLY;
184-
185147
const SYNC_THREAD_ROOT = withoutRoomId(THREAD_ROOT);
186148
const SYNC_THREAD_REPLY = withoutRoomId(THREAD_REPLY);
187149
SYNC_THREAD_ROOT.unsigned = {
@@ -980,33 +942,40 @@ describe("MatrixClient event timelines", function() {
980942
}
981943

982944
describe("with server compatibility", function() {
945+
beforeEach(() => {
946+
// @ts-ignore
947+
client.clientOpts.experimentalThreadSupport = true;
948+
Thread.setServerSideSupport(FeatureSupport.Experimental);
949+
Thread.setServerSideListSupport(FeatureSupport.Stable);
950+
});
951+
983952
async function testPagination(timelineSet: EventTimelineSet, direction: Direction) {
984953
const RANDOM_TOKEN = "7280349c7bee430f91defe2a38a0a08c";
985954
function respondToThreads() {
986955
httpBackend.when("GET", encodeUri("/_matrix/client/r0/rooms/$roomId/threads", {
987956
$roomId: roomId,
988957
})).respond(200, {
989-
chunk: [STABLE_THREAD_ROOT],
958+
chunk: [THREAD_ROOT],
990959
state: [],
991960
next_batch: RANDOM_TOKEN,
992961
});
993962
}
994963
function respondToContext() {
995964
httpBackend.when("GET", encodeUri("/_matrix/client/r0/rooms/$roomId/context/$eventId", {
996965
$roomId: roomId,
997-
$eventId: STABLE_THREAD_ROOT.event_id!,
966+
$eventId: THREAD_ROOT.event_id!,
998967
})).respond(200, {
999968
end: "",
1000969
start: "",
1001970
state: [],
1002971
events_before: [],
1003972
events_after: [],
1004-
event: STABLE_THREAD_ROOT,
973+
event: THREAD_ROOT,
1005974
});
1006975
}
1007976

1008977
respondToContext();
1009-
await flushHttp(client.getEventTimeline(timelineSet, STABLE_THREAD_ROOT.event_id!));
978+
await flushHttp(client.getEventTimeline(timelineSet, THREAD_ROOT.event_id!));
1010979
respondToThreads();
1011980
const timeline = await flushHttp(client.getLatestTimeline(timelineSet));
1012981
expect(timeline).not.toBeNull();
@@ -1016,17 +985,11 @@ describe("MatrixClient event timelines", function() {
1016985
backwards: direction === Direction.Backward,
1017986
}));
1018987
expect(success).toBeTruthy();
1019-
expect(timeline!.getEvents().length).toEqual(1);
1020-
expect(timeline!.getEvents()[0].event).toEqual(STABLE_THREAD_ROOT);
988+
expect(timeline!.getEvents().map(it => it.event)).toEqual([THREAD_ROOT]);
1021989
expect(timeline!.getPaginationToken(direction)).toEqual(RANDOM_TOKEN);
1022990
}
1023991

1024992
it("should allow you to paginate all threads backwards", async function() {
1025-
// @ts-ignore
1026-
client.clientOpts.experimentalThreadSupport = true;
1027-
Thread.setServerSideSupport(FeatureSupport.Experimental);
1028-
Thread.setServerSideListSupport(FeatureSupport.Stable);
1029-
1030993
const room = client.getRoom(roomId);
1031994
const timelineSets = await (room?.createThreadsTimelineSets());
1032995
expect(timelineSets).not.toBeNull();
@@ -1036,11 +999,6 @@ describe("MatrixClient event timelines", function() {
1036999
});
10371000

10381001
it("should allow you to paginate all threads forwards", async function() {
1039-
// @ts-ignore
1040-
client.clientOpts.experimentalThreadSupport = true;
1041-
Thread.setServerSideSupport(FeatureSupport.Experimental);
1042-
Thread.setServerSideListSupport(FeatureSupport.Stable);
1043-
10441002
const room = client.getRoom(roomId);
10451003
const timelineSets = await (room?.createThreadsTimelineSets());
10461004
expect(timelineSets).not.toBeNull();
@@ -1051,17 +1009,12 @@ describe("MatrixClient event timelines", function() {
10511009
});
10521010

10531011
it("should allow fetching all threads", async function() {
1054-
// @ts-ignore
1055-
client.clientOpts.experimentalThreadSupport = true;
1056-
Thread.setServerSideSupport(FeatureSupport.Experimental);
1057-
Thread.setServerSideListSupport(FeatureSupport.Stable);
1058-
10591012
const RANDOM_TOKEN = "7280349c7bee430f91defe2a38a0a08c";
10601013
function respondToThreads() {
10611014
httpBackend.when("GET", encodeUri("/_matrix/client/r0/rooms/$roomId/threads", {
10621015
$roomId: roomId,
10631016
})).respond(200, {
1064-
chunk: [STABLE_THREAD_ROOT],
1017+
chunk: [THREAD_ROOT],
10651018
state: [],
10661019
next_batch: RANDOM_TOKEN,
10671020
});
@@ -1077,6 +1030,13 @@ describe("MatrixClient event timelines", function() {
10771030
});
10781031

10791032
describe("without server compatibility", function() {
1033+
beforeEach(() => {
1034+
// @ts-ignore
1035+
client.clientOpts.experimentalThreadSupport = true;
1036+
Thread.setServerSideSupport(FeatureSupport.Experimental);
1037+
Thread.setServerSideListSupport(FeatureSupport.None);
1038+
});
1039+
10801040
async function testPagination(timelineSet: EventTimelineSet, direction: Direction) {
10811041
const RANDOM_TOKEN = "7280349c7bee430f91defe2a38a0a08c";
10821042
function respondToMessagesRequest() {
@@ -1120,17 +1080,11 @@ describe("MatrixClient event timelines", function() {
11201080
}));
11211081

11221082
expect(success).toBeTruthy();
1123-
expect(timeline!.getEvents().length).toEqual(1);
1124-
expect(timeline!.getEvents()[0].event).toEqual(THREAD_ROOT);
1083+
expect(timeline!.getEvents().map(it => it.event)).toEqual([THREAD_ROOT]);
11251084
expect(timeline!.getPaginationToken(direction)).toEqual(`${direction}${RANDOM_TOKEN}2`);
11261085
}
11271086

11281087
it("should allow you to paginate all threads", async function() {
1129-
// @ts-ignore
1130-
client.clientOpts.experimentalThreadSupport = true;
1131-
Thread.setServerSideSupport(FeatureSupport.Experimental);
1132-
Thread.setServerSideListSupport(FeatureSupport.None);
1133-
11341088
function respondToFilter() {
11351089
httpBackend.when("POST", "/filter").respond(200, { filter_id: "fid" });
11361090
}
@@ -1156,19 +1110,14 @@ describe("MatrixClient event timelines", function() {
11561110
});
11571111

11581112
it("should allow fetching all threads", async function() {
1159-
// @ts-ignore
1160-
client.clientOpts.experimentalThreadSupport = true;
1161-
Thread.setServerSideSupport(FeatureSupport.Experimental);
1162-
Thread.setServerSideListSupport(FeatureSupport.None);
1163-
11641113
const room = client.getRoom(roomId);
11651114

11661115
const RANDOM_TOKEN = "7280349c7bee430f91defe2a38a0a08c";
11671116
function respondToMessagesRequest() {
11681117
httpBackend.when("GET", encodeUri("/_matrix/client/r0/rooms/$roomId/messages", {
11691118
$roomId: roomId,
11701119
})).respond(200, {
1171-
chunk: [STABLE_THREAD_ROOT],
1120+
chunk: [THREAD_ROOT],
11721121
state: [],
11731122
start: `${Direction.Forward}${RANDOM_TOKEN}2`,
11741123
end: `${Direction.Backward}${RANDOM_TOKEN}2`,

src/client.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5357,7 +5357,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
53575357
" parameter to true when creating MatrixClient to enable it.");
53585358
}
53595359

5360-
if (!timelineSet.room) {
5360+
if (!timelineSet?.room) {
53615361
throw new Error("getEventTimeline only supports room timelines");
53625362
}
53635363

@@ -5477,7 +5477,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
54775477
}
54785478

54795479
let res: IMessagesResponse;
5480-
const roomId = timelineSet.room?.roomId;
5480+
const roomId = timelineSet.room.roomId;
54815481
if (timelineSet.isThreadTimeline) {
54825482
res = await this.createThreadListMessagesRequest(
54835483
roomId,
@@ -5731,7 +5731,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
57315731
if (backwards && res.end == res.start) {
57325732
eventTimeline.setPaginationToken(null, dir);
57335733
}
5734-
return res.end != res.start;
5734+
return res.end !== res.start;
57355735
}).finally(() => {
57365736
eventTimeline.paginationRequests[dir] = null;
57375737
});
@@ -6866,8 +6866,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
68666866
list: determineFeatureSupport(listStable, listUnstable),
68676867
};
68686868
} catch (e) {
6869-
// Assume server support and stability aren't available: null/no data return.
6870-
// XXX: This should just return an object with `false` booleans instead.
68716869
return {
68726870
threads: FeatureSupport.None,
68736871
list: FeatureSupport.None,

0 commit comments

Comments
 (0)