You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-30 02:21:17 +03:00
Use server side relations for voice broadcasts (#9534)
This commit is contained in:
@ -28,13 +28,15 @@ import { Relations } from "matrix-js-sdk/src/models/relations";
|
||||
import { RelationsContainer } from "matrix-js-sdk/src/models/relations-container";
|
||||
|
||||
import { RelationsHelper, RelationsHelperEvent } from "../../src/events/RelationsHelper";
|
||||
import { mkEvent, mkStubRoom, stubClient } from "../test-utils";
|
||||
import { mkEvent, mkRelationsContainer, mkStubRoom, stubClient } from "../test-utils";
|
||||
|
||||
describe("RelationsHelper", () => {
|
||||
const roomId = "!room:example.com";
|
||||
let userId: string;
|
||||
let event: MatrixEvent;
|
||||
let relatedEvent1: MatrixEvent;
|
||||
let relatedEvent2: MatrixEvent;
|
||||
let relatedEvent3: MatrixEvent;
|
||||
let room: Room;
|
||||
let client: MatrixClient;
|
||||
let relationsHelper: RelationsHelper;
|
||||
@ -46,47 +48,81 @@ describe("RelationsHelper", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
client = stubClient();
|
||||
userId = client.getUserId() || "";
|
||||
mocked(client.relations).mockClear();
|
||||
room = mkStubRoom(roomId, "test room", client);
|
||||
mocked(client.getRoom).mockImplementation((getRoomId: string) => {
|
||||
mocked(client.getRoom).mockImplementation((getRoomId?: string) => {
|
||||
if (getRoomId === roomId) {
|
||||
return room;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
event = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomMessage,
|
||||
room: roomId,
|
||||
user: client.getUserId(),
|
||||
user: userId,
|
||||
content: {},
|
||||
});
|
||||
relatedEvent1 = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomMessage,
|
||||
room: roomId,
|
||||
user: client.getUserId(),
|
||||
content: {},
|
||||
user: userId,
|
||||
content: { relatedEvent: 1 },
|
||||
});
|
||||
relatedEvent2 = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomMessage,
|
||||
room: roomId,
|
||||
user: client.getUserId(),
|
||||
content: {},
|
||||
user: userId,
|
||||
content: { relatedEvent: 2 },
|
||||
});
|
||||
relatedEvent3 = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomMessage,
|
||||
room: roomId,
|
||||
user: userId,
|
||||
content: { relatedEvent: 3 },
|
||||
});
|
||||
onAdd = jest.fn();
|
||||
relationsContainer = mkRelationsContainer();
|
||||
// TODO Michael W: create test utils, remove casts
|
||||
relationsContainer = {
|
||||
getChildEventsForEvent: jest.fn(),
|
||||
} as unknown as RelationsContainer;
|
||||
relations = {
|
||||
getRelations: jest.fn(),
|
||||
on: jest.fn().mockImplementation((type, l) => relationsOnAdd = l),
|
||||
off: jest.fn(),
|
||||
} as unknown as Relations;
|
||||
timelineSet = {
|
||||
relations: relationsContainer,
|
||||
} as unknown as EventTimelineSet;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
relationsHelper?.destroy();
|
||||
});
|
||||
|
||||
describe("when there is an event without ID", () => {
|
||||
it("should raise an error", () => {
|
||||
jest.spyOn(event, "getId").mockReturnValue(undefined);
|
||||
|
||||
expect(() => {
|
||||
new RelationsHelper(event, RelationType.Reference, EventType.RoomMessage, client);
|
||||
}).toThrowError("unable to create RelationsHelper: missing event ID");
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there is an event without room ID", () => {
|
||||
it("should raise an error", () => {
|
||||
jest.spyOn(event, "getRoomId").mockReturnValue(undefined);
|
||||
|
||||
expect(() => {
|
||||
new RelationsHelper(event, RelationType.Reference, EventType.RoomMessage, client);
|
||||
}).toThrowError("unable to create RelationsHelper: missing room ID");
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there is an event without relations", () => {
|
||||
beforeEach(() => {
|
||||
relationsHelper = new RelationsHelper(event, RelationType.Reference, EventType.RoomMessage, client);
|
||||
@ -118,6 +154,34 @@ describe("RelationsHelper", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there is an event with two pages server side relations", () => {
|
||||
beforeEach(() => {
|
||||
mocked(client.relations)
|
||||
.mockResolvedValueOnce({
|
||||
events: [relatedEvent1, relatedEvent2],
|
||||
nextBatch: "next",
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
events: [relatedEvent3],
|
||||
nextBatch: null,
|
||||
});
|
||||
relationsHelper = new RelationsHelper(event, RelationType.Reference, EventType.RoomMessage, client);
|
||||
relationsHelper.on(RelationsHelperEvent.Add, onAdd);
|
||||
});
|
||||
|
||||
describe("emitFetchCurrent", () => {
|
||||
beforeEach(async () => {
|
||||
await relationsHelper.emitFetchCurrent();
|
||||
});
|
||||
|
||||
it("should emit the server side events", () => {
|
||||
expect(onAdd).toHaveBeenCalledWith(relatedEvent1);
|
||||
expect(onAdd).toHaveBeenCalledWith(relatedEvent2);
|
||||
expect(onAdd).toHaveBeenCalledWith(relatedEvent3);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there is an event with relations", () => {
|
||||
beforeEach(() => {
|
||||
mocked(room.getUnfilteredTimelineSet).mockReturnValue(timelineSet);
|
||||
|
Reference in New Issue
Block a user