Skip to content

Commit 515db7a

Browse files
author
Kerry Archibald
committed
Revert "allow alt event types in relations model"
This reverts commit e578d84.
1 parent e578d84 commit 515db7a

File tree

2 files changed

+2
-100
lines changed

2 files changed

+2
-100
lines changed

spec/unit/relations.spec.ts

-94
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,13 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { M_POLL_START } from "matrix-events-sdk";
18-
1917
import { EventTimelineSet } from "../../src/models/event-timeline-set";
2018
import { MatrixEvent, MatrixEventEvent } from "../../src/models/event";
2119
import { Room } from "../../src/models/room";
2220
import { Relations } from "../../src/models/relations";
2321
import { TestClient } from "../TestClient";
24-
import { RelationType } from "../../src";
25-
import { logger } from "../../src/logger";
2622

2723
describe("Relations", function () {
28-
afterEach(() => {
29-
jest.spyOn(logger, "error").mockRestore();
30-
});
31-
3224
it("should deduplicate annotations", function () {
3325
const room = new Room("room123", null!, null!);
3426
const relations = new Relations("m.annotation", "m.reaction", room);
@@ -83,92 +75,6 @@ describe("Relations", function () {
8375
}
8476
});
8577

86-
describe("addEvent()", () => {
87-
const relationType = RelationType.Reference;
88-
const eventType = M_POLL_START.stable!;
89-
const altEventTypes = [M_POLL_START.unstable!];
90-
const room = new Room("room123", null!, null!);
91-
92-
it("should not add events without a relation", async () => {
93-
// dont pollute console
94-
const logSpy = jest.spyOn(logger, "error").mockImplementation(() => {});
95-
const relations = new Relations(relationType, eventType, room);
96-
const emitSpy = jest.spyOn(relations, "emit");
97-
const event = new MatrixEvent({ type: eventType });
98-
99-
await relations.addEvent(event);
100-
expect(logSpy).toHaveBeenCalledWith("Event must have relation info");
101-
// event not added
102-
expect(relations.getRelations().length).toBe(0);
103-
expect(emitSpy).not.toHaveBeenCalled();
104-
});
105-
106-
it("should not add events of incorrect event type", async () => {
107-
// dont pollute console
108-
const logSpy = jest.spyOn(logger, "error").mockImplementation(() => {});
109-
const relations = new Relations(relationType, eventType, room);
110-
const emitSpy = jest.spyOn(relations, "emit");
111-
const event = new MatrixEvent({
112-
type: "different-event-type",
113-
content: {
114-
"m.relates_to": {
115-
event_id: "$2s4yYpEkVQrPglSCSqB_m6E8vDhWsg0yFNyOJdVIb_o",
116-
rel_type: relationType,
117-
},
118-
},
119-
});
120-
121-
await relations.addEvent(event);
122-
123-
expect(logSpy).toHaveBeenCalledWith(`Event relation info doesn't match this container`);
124-
// event not added
125-
expect(relations.getRelations().length).toBe(0);
126-
expect(emitSpy).not.toHaveBeenCalled();
127-
});
128-
129-
it("adds events that match alt event types", async () => {
130-
const relations = new Relations(relationType, eventType, room, altEventTypes);
131-
const emitSpy = jest.spyOn(relations, "emit");
132-
const event = new MatrixEvent({
133-
type: M_POLL_START.unstable!,
134-
content: {
135-
"m.relates_to": {
136-
event_id: "$2s4yYpEkVQrPglSCSqB_m6E8vDhWsg0yFNyOJdVIb_o",
137-
rel_type: relationType,
138-
},
139-
},
140-
});
141-
142-
await relations.addEvent(event);
143-
144-
// event added
145-
expect(relations.getRelations()).toEqual([event]);
146-
expect(emitSpy).toHaveBeenCalled();
147-
});
148-
149-
it("should not add events of incorrect relation type", async () => {
150-
const logSpy = jest.spyOn(logger, "error").mockImplementation(() => {});
151-
const relations = new Relations(relationType, eventType, room);
152-
const event = new MatrixEvent({
153-
type: eventType,
154-
content: {
155-
"m.relates_to": {
156-
event_id: "$2s4yYpEkVQrPglSCSqB_m6E8vDhWsg0yFNyOJdVIb_o",
157-
rel_type: "m.annotation",
158-
},
159-
},
160-
});
161-
162-
await relations.addEvent(event);
163-
const emitSpy = jest.spyOn(relations, "emit");
164-
165-
expect(logSpy).toHaveBeenCalledWith(`Event relation info doesn't match this container`);
166-
// event not added
167-
expect(relations.getRelations().length).toBe(0);
168-
expect(emitSpy).not.toHaveBeenCalled();
169-
});
170-
});
171-
17278
it("should emit created regardless of ordering", async function () {
17379
const targetEvent = new MatrixEvent({
17480
sender: "@bob:example.com",

src/models/relations.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ export type EventHandlerMap = {
3333
[RelationsEvent.Redaction]: (event: MatrixEvent) => void;
3434
};
3535

36-
const matchesEventType = (eventType: string, targetEventType: string, altTargetEventTypes: string[] = []): boolean =>
37-
[targetEventType, ...altTargetEventTypes].includes(eventType);
38-
3936
/**
4037
* A container for relation events that supports easy access to common ways of
4138
* aggregating such events. Each instance holds events that of a single relation
@@ -63,7 +60,6 @@ export class Relations extends TypedEventEmitter<RelationsEvent, EventHandlerMap
6360
public readonly relationType: RelationType | string,
6461
public readonly eventType: string,
6562
client: MatrixClient | Room,
66-
public readonly altEventTypes?: string[],
6763
) {
6864
super();
6965
this.client = client instanceof Room ? client.client : client;
@@ -88,7 +84,7 @@ export class Relations extends TypedEventEmitter<RelationsEvent, EventHandlerMap
8884
const relationType = relation.rel_type;
8985
const eventType = event.getType();
9086

91-
if (this.relationType !== relationType || !matchesEventType(eventType, this.eventType, this.altEventTypes)) {
87+
if (this.relationType !== relationType || this.eventType !== eventType) {
9288
logger.error("Event relation info doesn't match this container");
9389
return;
9490
}
@@ -135,7 +131,7 @@ export class Relations extends TypedEventEmitter<RelationsEvent, EventHandlerMap
135131
const relationType = relation.rel_type;
136132
const eventType = event.getType();
137133

138-
if (this.relationType !== relationType || !matchesEventType(eventType, this.eventType, this.altEventTypes)) {
134+
if (this.relationType !== relationType || this.eventType !== eventType) {
139135
logger.error("Event relation info doesn't match this container");
140136
return;
141137
}

0 commit comments

Comments
 (0)