Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions spec/unit/read-receipt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import MockHttpBackend from "matrix-mock-request";

import { MAIN_ROOM_TIMELINE, ReceiptType } from "../../src/@types/read_receipts";
import { MatrixClient } from "../../src/client";
import { Feature, ServerSupport } from "../../src/feature";
import { EventType } from "../../src/matrix";
import { synthesizeReceipt } from "../../src/models/read-receipt";
import { encodeUri } from "../../src/utils";
Expand Down Expand Up @@ -70,10 +69,6 @@ const roomEvent = utils.mkEvent({
},
});

function mockServerSideSupport(client: MatrixClient, serverSideSupport: ServerSupport) {
client.canSupport.set(Feature.ThreadUnreadNotifications, serverSideSupport);
}

describe("Read receipt", () => {
beforeEach(() => {
httpBackend = new MockHttpBackend();
Expand Down Expand Up @@ -101,7 +96,6 @@ describe("Read receipt", () => {
})
.respond(200, {});

mockServerSideSupport(client, ServerSupport.Stable);
client.sendReceipt(threadEvent, ReceiptType.Read, {});

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

mockServerSideSupport(client, ServerSupport.Stable);
client.sendReadReceipt(threadEvent, ReceiptType.Read, true);

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

mockServerSideSupport(client, ServerSupport.Stable);
client.sendReceipt(roomEvent, ReceiptType.Read, {});

await httpBackend.flushAllExpected();
await flushPromises();
});

it("sends a room read receipt when there's no server support", async () => {
httpBackend
.when(
"POST",
encodeUri("/rooms/$roomId/receipt/$receiptType/$eventId", {
$roomId: ROOM_ID,
$receiptType: ReceiptType.Read,
$eventId: threadEvent.getId()!,
}),
)
.check((request) => {
expect(request.data.thread_id).toBeUndefined();
})
.respond(200, {});

mockServerSideSupport(client, ServerSupport.Unsupported);
client.sendReceipt(threadEvent, ReceiptType.Read, {});

await httpBackend.flushAllExpected();
await flushPromises();
});

it("sends a valid room read receipt even when body omitted", async () => {
httpBackend
.when(
"POST",
encodeUri("/rooms/$roomId/receipt/$receiptType/$eventId", {
$roomId: ROOM_ID,
$receiptType: ReceiptType.Read,
$eventId: threadEvent.getId()!,
}),
)
.check((request) => {
expect(request.data).toEqual({});
})
.respond(200, {});

mockServerSideSupport(client, ServerSupport.Unsupported);
client.sendReceipt(threadEvent, ReceiptType.Read, undefined);

await httpBackend.flushAllExpected();
await flushPromises();
});
});

describe("synthesizeReceipt", () => {
Expand Down
8 changes: 1 addition & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ import { ToDeviceBatch } from "./models/ToDeviceMessage";
import { IgnoredInvites } from "./models/invites-ignorer";
import { UIARequest, UIAResponse } from "./@types/uia";
import { LocalNotificationSettings } from "./@types/local_notifications";
import { UNREAD_THREAD_NOTIFICATIONS } from "./@types/sync";
import { buildFeatureSupportMap, Feature, ServerSupport } from "./feature";
import { CryptoBackend } from "./common-crypto/CryptoBackend";
import { RUST_SDK_STORE_PREFIX } from "./rust-crypto/constants";
Expand Down Expand Up @@ -4840,8 +4839,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
$eventId: event.getId()!,
});

const supportsThreadRR = this.canSupport.get(Feature.ThreadUnreadNotifications) !== ServerSupport.Unsupported;
if (supportsThreadRR && !unthreaded) {
if (!unthreaded) {
const isThread = !!event.threadRootId;
body = {
...body,
Expand Down Expand Up @@ -7045,10 +7043,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
const serverVersions = await this.serverVersionsPromise;
this.canSupport = await buildFeatureSupportMap(serverVersions);

// We can set flag values to use their stable or unstable version
const support = this.canSupport.get(Feature.ThreadUnreadNotifications);
UNREAD_THREAD_NOTIFICATIONS.setPreferUnstable(support === ServerSupport.Unstable);

return this.serverVersionsPromise;
}

Expand Down
7 changes: 2 additions & 5 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import {
import { IStateEventWithRoomId } from "../@types/search";
import { RelationsContainer } from "./relations-container";
import { ReadReceipt, synthesizeReceipt } from "./read-receipt";
import { Feature, ServerSupport } from "../feature";
import { Poll, PollEvent } from "./poll";

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