You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
sonarcloud
This commit is contained in:
@ -932,6 +932,27 @@ describe("SlidingSyncSdk", () => {
|
|||||||
describe("ExtensionReceipts", () => {
|
describe("ExtensionReceipts", () => {
|
||||||
let ext: Extension;
|
let ext: Extension;
|
||||||
|
|
||||||
|
const generateReceiptResponse = (
|
||||||
|
userId: string, roomId: string, eventId: string, recType: string, ts: number,
|
||||||
|
) => {
|
||||||
|
return {
|
||||||
|
rooms: {
|
||||||
|
[roomId]: {
|
||||||
|
type: EventType.Receipt,
|
||||||
|
content: {
|
||||||
|
[eventId]: {
|
||||||
|
[recType]: {
|
||||||
|
[userId]: {
|
||||||
|
ts: ts,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await setupClient();
|
await setupClient();
|
||||||
const hasSynced = sdk!.sync();
|
const hasSynced = sdk!.sync();
|
||||||
@ -973,22 +994,9 @@ describe("SlidingSyncSdk", () => {
|
|||||||
const room = client!.getRoom(roomId)!;
|
const room = client!.getRoom(roomId)!;
|
||||||
expect(room).toBeDefined();
|
expect(room).toBeDefined();
|
||||||
expect(room.getReadReceiptForUserId(alice, true)).toBeNull();
|
expect(room.getReadReceiptForUserId(alice, true)).toBeNull();
|
||||||
ext.onResponse({
|
ext.onResponse(
|
||||||
rooms: {
|
generateReceiptResponse(alice, roomId, lastEvent.event_id, "m.read", 1234567),
|
||||||
[roomId]: {
|
);
|
||||||
type: EventType.Receipt,
|
|
||||||
content: {
|
|
||||||
[lastEvent.event_id]: {
|
|
||||||
"m.read": {
|
|
||||||
[alice]: {
|
|
||||||
ts: 1234567,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const receipt = room.getReadReceiptForUserId(alice);
|
const receipt = room.getReadReceiptForUserId(alice);
|
||||||
expect(receipt).toBeDefined();
|
expect(receipt).toBeDefined();
|
||||||
expect(receipt?.eventId).toEqual(lastEvent.event_id);
|
expect(receipt?.eventId).toEqual(lastEvent.event_id);
|
||||||
@ -1000,22 +1008,9 @@ describe("SlidingSyncSdk", () => {
|
|||||||
const roomId = "!room:id";
|
const roomId = "!room:id";
|
||||||
const alice = "@alice:alice";
|
const alice = "@alice:alice";
|
||||||
const eventId = "$something";
|
const eventId = "$something";
|
||||||
ext.onResponse({
|
ext.onResponse(
|
||||||
rooms: {
|
generateReceiptResponse(alice, roomId, eventId, "m.read", 1234567),
|
||||||
[roomId]: {
|
);
|
||||||
type: EventType.Receipt,
|
|
||||||
content: {
|
|
||||||
[eventId]: {
|
|
||||||
"m.read": {
|
|
||||||
[alice]: {
|
|
||||||
ts: 1234567,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
// we expect it not to crash
|
// we expect it not to crash
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -253,22 +253,15 @@ class ExtensionTyping implements Extension {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public onResponse(data: {rooms: Record<string, Event[]>}): void {
|
public onResponse(data: {rooms: Record<string, IMinimalEvent>}): void {
|
||||||
if (!data || !data.rooms) {
|
if (!data || !data.rooms) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const roomId in data.rooms) {
|
for (const roomId in data.rooms) {
|
||||||
const ephemeralEvents = mapEvents(this.client, roomId, [data.rooms[roomId]]);
|
processEphemeralEvents(
|
||||||
const room = this.client.getRoom(roomId);
|
this.client, roomId, [data.rooms[roomId]],
|
||||||
if (!room) {
|
);
|
||||||
logger.warn("got typing events for room but room doesn't exist on client:", roomId);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
room.addEphemeralEvents(ephemeralEvents);
|
|
||||||
ephemeralEvents.forEach((e) => {
|
|
||||||
this.client.emit(ClientEvent.Event, e);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -285,30 +278,23 @@ class ExtensionReceipts implements Extension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public onRequest(isInitial: boolean): object | undefined {
|
public onRequest(isInitial: boolean): object | undefined {
|
||||||
if (!isInitial) {
|
if (isInitial) {
|
||||||
return undefined;
|
return {
|
||||||
|
enabled: true,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return {
|
return undefined;
|
||||||
enabled: true,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public onResponse(data: {rooms: Record<string, Event>}): void {
|
public onResponse(data: {rooms: Record<string, IMinimalEvent>}): void {
|
||||||
if (!data || !data.rooms) {
|
if (!data || !data.rooms) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const roomId in data.rooms) {
|
for (const roomId in data.rooms) {
|
||||||
const ephemeralEvents = mapEvents(this.client, roomId, [data.rooms[roomId]]);
|
processEphemeralEvents(
|
||||||
const room = this.client.getRoom(roomId);
|
this.client, roomId, [data.rooms[roomId]],
|
||||||
if (!room) {
|
);
|
||||||
logger.warn("got receipts for room but room doesn't exist on client:", roomId);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
room.addEphemeralEvents(ephemeralEvents);
|
|
||||||
ephemeralEvents.forEach((e) => {
|
|
||||||
this.client.emit(ClientEvent.Event, e);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -970,3 +956,16 @@ function mapEvents(client: MatrixClient, roomId: string | undefined, events: obj
|
|||||||
return mapper(e);
|
return mapper(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processEphemeralEvents(client: MatrixClient, roomId: string, ephEvents: IMinimalEvent[]) {
|
||||||
|
const ephemeralEvents = mapEvents(client, roomId, ephEvents);
|
||||||
|
const room = client.getRoom(roomId);
|
||||||
|
if (!room) {
|
||||||
|
logger.warn("got ephemeral events for room but room doesn't exist on client:", roomId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
room.addEphemeralEvents(ephemeralEvents);
|
||||||
|
ephemeralEvents.forEach((e) => {
|
||||||
|
client.emit(ClientEvent.Event, e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user