Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Relations to not be per-EventTimelineSet #2412

Merged
merged 14 commits into from
Jun 7, 2022
Merged
12 changes: 5 additions & 7 deletions spec/unit/event-timeline-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ describe('EventTimelineSet', () => {

const itShouldReturnTheRelatedEvents = () => {
it('should return the related events', () => {
eventTimelineSet.aggregateRelations(messageEvent);
const relations = eventTimelineSet.getRelationsForEvent(
eventTimelineSet.relations.aggregate(messageEvent);
const relations = eventTimelineSet.relations.getRelationsForEvent(
messageEvent.getId(),
"m.in_reply_to",
EventType.RoomMessage,
Expand All @@ -54,9 +54,7 @@ describe('EventTimelineSet', () => {
beforeEach(() => {
client = utils.mock(MatrixClient, 'MatrixClient');
room = new Room(roomId, client, userA);
eventTimelineSet = new EventTimelineSet(room, {
unstableClientRelationAggregation: true,
});
eventTimelineSet = new EventTimelineSet(room);
eventTimeline = new EventTimeline(eventTimelineSet);
messageEvent = utils.mkMessage({
room: roomId,
Expand Down Expand Up @@ -118,8 +116,8 @@ describe('EventTimelineSet', () => {
});

it('should not return the related events', () => {
eventTimelineSet.aggregateRelations(messageEvent);
const relations = eventTimelineSet.getRelationsForEvent(
eventTimelineSet.relations.aggregate(messageEvent);
const relations = eventTimelineSet.relations.getRelationsForEvent(
messageEvent.getId(),
"m.in_reply_to",
EventType.RoomMessage,
Expand Down
22 changes: 12 additions & 10 deletions spec/unit/relations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,14 @@ describe("Relations", function() {
},
});

// Stub the room

const room = new Room("room123", null, null);

// Add the target event first, then the relation event
{
const room = new Room("room123", null, null);
const relationsCreated = new Promise(resolve => {
targetEvent.once(MatrixEventEvent.RelationsCreated, resolve);
});

const timelineSet = new EventTimelineSet(room, {
unstableClientRelationAggregation: true,
});
const timelineSet = new EventTimelineSet(room);
timelineSet.addLiveEvent(targetEvent);
timelineSet.addLiveEvent(relationEvent);

Expand All @@ -117,20 +112,27 @@ describe("Relations", function() {

// Add the relation event first, then the target event
{
const room = new Room("room123", null, null);
const relationsCreated = new Promise(resolve => {
targetEvent.once(MatrixEventEvent.RelationsCreated, resolve);
});

const timelineSet = new EventTimelineSet(room, {
unstableClientRelationAggregation: true,
});
const timelineSet = new EventTimelineSet(room);
timelineSet.addLiveEvent(relationEvent);
timelineSet.addLiveEvent(targetEvent);

await relationsCreated;
}
});

it("should re-use Relations between all timeline sets in a room", async () => {
const room = new Room("room123", null, null);
const timelineSet1 = new EventTimelineSet(room);
const timelineSet2 = new EventTimelineSet(room);
expect(room.relations).toBe(timelineSet1.relations);
expect(room.relations).toBe(timelineSet2.relations);
});

it("should ignore m.replace for state events", async () => {
const userId = "@bob:example.com";
const room = new Room("room123", null, userId);
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,7 @@ describe("Room", function() {
const thread = threadRoot.getThread();
expect(thread.rootEvent).toBe(threadRoot);

const rootRelations = thread.timelineSet.getRelationsForEvent(
const rootRelations = thread.timelineSet.relations.getRelationsForEvent(
threadRoot.getId(),
RelationType.Annotation,
EventType.Reaction,
Expand All @@ -2284,7 +2284,7 @@ describe("Room", function() {
expect(rootRelations[0][1].size).toEqual(1);
expect(rootRelations[0][1].has(rootReaction)).toBeTruthy();

const responseRelations = thread.timelineSet.getRelationsForEvent(
const responseRelations = thread.timelineSet.relations.getRelationsForEvent(
threadResponse.getId(),
RelationType.Annotation,
EventType.Reaction,
Expand Down
9 changes: 0 additions & 9 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,6 @@ export interface ICreateClientOpts {
*/
sessionStore?: SessionStore;

/**
* Set to true to enable client-side aggregation of event relations
* via `EventTimelineSet#getRelationsForEvent`.
* This feature is currently unstable and the API may change without notice.
*/
unstableClientRelationAggregation?: boolean;

verificationMethods?: Array<VerificationMethod>;

/**
Expand Down Expand Up @@ -905,7 +898,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
public clientRunning = false;
public timelineSupport = false;
public urlPreviewCache: { [key: string]: Promise<IPreviewUrlResponse> } = {};
public unstableClientRelationAggregation = false;
public identityServer: IIdentityServerProvider;
public sessionStore: SessionStore; // XXX: Intended private, used in code.
public http: MatrixHttpApi; // XXX: Intended private, used in code.
Expand Down Expand Up @@ -1037,7 +1029,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
}

this.timelineSupport = Boolean(opts.timelineSupport);
this.unstableClientRelationAggregation = !!opts.unstableClientRelationAggregation;

this.cryptoStore = opts.cryptoStore;
this.sessionStore = opts.sessionStore;
Expand Down
Loading