Skip to content

Commit 9aef319

Browse files
committed
Cleanup pre MSC3773 thread unread notif logic
1 parent 4f918f6 commit 9aef319

File tree

3 files changed

+4
-62
lines changed

3 files changed

+4
-62
lines changed

spec/unit/read-receipt.spec.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import MockHttpBackend from "matrix-mock-request";
1818

1919
import { MAIN_ROOM_TIMELINE, ReceiptType } from "../../src/@types/read_receipts";
2020
import { MatrixClient } from "../../src/client";
21-
import { Feature, ServerSupport } from "../../src/feature";
2221
import { EventType } from "../../src/matrix";
2322
import { synthesizeReceipt } from "../../src/models/read-receipt";
2423
import { encodeUri } from "../../src/utils";
@@ -70,10 +69,6 @@ const roomEvent = utils.mkEvent({
7069
},
7170
});
7271

73-
function mockServerSideSupport(client: MatrixClient, serverSideSupport: ServerSupport) {
74-
client.canSupport.set(Feature.ThreadUnreadNotifications, serverSideSupport);
75-
}
76-
7772
describe("Read receipt", () => {
7873
beforeEach(() => {
7974
httpBackend = new MockHttpBackend();
@@ -101,7 +96,6 @@ describe("Read receipt", () => {
10196
})
10297
.respond(200, {});
10398

104-
mockServerSideSupport(client, ServerSupport.Stable);
10599
client.sendReceipt(threadEvent, ReceiptType.Read, {});
106100

107101
await httpBackend.flushAllExpected();
@@ -123,7 +117,6 @@ describe("Read receipt", () => {
123117
})
124118
.respond(200, {});
125119

126-
mockServerSideSupport(client, ServerSupport.Stable);
127120
client.sendReadReceipt(threadEvent, ReceiptType.Read, true);
128121

129122
await httpBackend.flushAllExpected();
@@ -145,56 +138,11 @@ describe("Read receipt", () => {
145138
})
146139
.respond(200, {});
147140

148-
mockServerSideSupport(client, ServerSupport.Stable);
149141
client.sendReceipt(roomEvent, ReceiptType.Read, {});
150142

151143
await httpBackend.flushAllExpected();
152144
await flushPromises();
153145
});
154-
155-
it("sends a room read receipt when there's no server support", async () => {
156-
httpBackend
157-
.when(
158-
"POST",
159-
encodeUri("/rooms/$roomId/receipt/$receiptType/$eventId", {
160-
$roomId: ROOM_ID,
161-
$receiptType: ReceiptType.Read,
162-
$eventId: threadEvent.getId()!,
163-
}),
164-
)
165-
.check((request) => {
166-
expect(request.data.thread_id).toBeUndefined();
167-
})
168-
.respond(200, {});
169-
170-
mockServerSideSupport(client, ServerSupport.Unsupported);
171-
client.sendReceipt(threadEvent, ReceiptType.Read, {});
172-
173-
await httpBackend.flushAllExpected();
174-
await flushPromises();
175-
});
176-
177-
it("sends a valid room read receipt even when body omitted", async () => {
178-
httpBackend
179-
.when(
180-
"POST",
181-
encodeUri("/rooms/$roomId/receipt/$receiptType/$eventId", {
182-
$roomId: ROOM_ID,
183-
$receiptType: ReceiptType.Read,
184-
$eventId: threadEvent.getId()!,
185-
}),
186-
)
187-
.check((request) => {
188-
expect(request.data).toEqual({});
189-
})
190-
.respond(200, {});
191-
192-
mockServerSideSupport(client, ServerSupport.Unsupported);
193-
client.sendReceipt(threadEvent, ReceiptType.Read, undefined);
194-
195-
await httpBackend.flushAllExpected();
196-
await flushPromises();
197-
});
198146
});
199147

200148
describe("synthesizeReceipt", () => {

src/client.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4840,8 +4840,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
48404840
$eventId: event.getId()!,
48414841
});
48424842

4843-
const supportsThreadRR = this.canSupport.get(Feature.ThreadUnreadNotifications) !== ServerSupport.Unsupported;
4844-
if (supportsThreadRR && !unthreaded) {
4843+
if (!unthreaded) {
48454844
const isThread = !!event.threadRootId;
48464845
body = {
48474846
...body,
@@ -7045,9 +7044,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
70457044
const serverVersions = await this.serverVersionsPromise;
70467045
this.canSupport = await buildFeatureSupportMap(serverVersions);
70477046

7048-
// We can set flag values to use their stable or unstable version
7049-
const support = this.canSupport.get(Feature.ThreadUnreadNotifications);
7050-
UNREAD_THREAD_NOTIFICATIONS.setPreferUnstable(support === ServerSupport.Unstable);
7047+
UNREAD_THREAD_NOTIFICATIONS.setPreferUnstable(false);
70517048

70527049
return this.serverVersionsPromise;
70537050
}

src/models/room.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ import {
6464
import { IStateEventWithRoomId } from "../@types/search";
6565
import { RelationsContainer } from "./relations-container";
6666
import { ReadReceipt, synthesizeReceipt } from "./read-receipt";
67-
import { Feature, ServerSupport } from "../feature";
6867
import { Poll, PollEvent } from "./poll";
6968

7069
// These constants are used as sane defaults when the homeserver doesn't support
@@ -1299,10 +1298,8 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
12991298
*/
13001299
public getUnreadNotificationCount(type = NotificationCountType.Total): number {
13011300
let count = this.getRoomUnreadNotificationCount(type);
1302-
if (this.client.canSupport.get(Feature.ThreadUnreadNotifications) !== ServerSupport.Unsupported) {
1303-
for (const threadNotification of this.threadNotifications.values()) {
1304-
count += threadNotification[type] ?? 0;
1305-
}
1301+
for (const threadNotification of this.threadNotifications.values()) {
1302+
count += threadNotification[type] ?? 0;
13061303
}
13071304
return count;
13081305
}

0 commit comments

Comments
 (0)