You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-09 10:22:46 +03:00
Fix behaviour of isRelation with relation m.replace for state events (#2389)
* Add some short-circuits to skip async code * Fix behaviour of `isRelation` with relation `m.replace` for state events
This commit is contained in:
committed by
GitHub
parent
81d884f899
commit
e81d84502b
@@ -168,6 +168,8 @@ describe("Relations", function() {
|
|||||||
await relations.setTargetEvent(originalTopic);
|
await relations.setTargetEvent(originalTopic);
|
||||||
expect(originalTopic.replacingEvent()).toBe(null);
|
expect(originalTopic.replacingEvent()).toBe(null);
|
||||||
expect(originalTopic.getContent().topic).toBe("orig");
|
expect(originalTopic.getContent().topic).toBe("orig");
|
||||||
|
expect(badlyEditedTopic.isRelation()).toBe(false);
|
||||||
|
expect(badlyEditedTopic.isRelation("m.replace")).toBe(false);
|
||||||
|
|
||||||
await relations.addEvent(badlyEditedTopic);
|
await relations.addEvent(badlyEditedTopic);
|
||||||
expect(originalTopic.replacingEvent()).toBe(null);
|
expect(originalTopic.replacingEvent()).toBe(null);
|
||||||
|
@@ -1290,7 +1290,7 @@ export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHan
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether the event is a relation event, and of a given type if
|
* Get whether the event is a relation event, and of a given type if
|
||||||
* `relType` is passed in.
|
* `relType` is passed in. State events cannot be relation events
|
||||||
*
|
*
|
||||||
* @param {string?} relType if given, checks that the relation is of the
|
* @param {string?} relType if given, checks that the relation is of the
|
||||||
* given type
|
* given type
|
||||||
@@ -1300,8 +1300,11 @@ export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHan
|
|||||||
// Relation info is lifted out of the encrypted content when sent to
|
// Relation info is lifted out of the encrypted content when sent to
|
||||||
// encrypted rooms, so we have to check `getWireContent` for this.
|
// encrypted rooms, so we have to check `getWireContent` for this.
|
||||||
const relation = this.getWireContent()?.["m.relates_to"];
|
const relation = this.getWireContent()?.["m.relates_to"];
|
||||||
return relation && relation.rel_type && relation.event_id &&
|
if (this.isState() && relation?.rel_type === RelationType.Replace) {
|
||||||
((relType && relation.rel_type === relType) || !relType);
|
// State events cannot be m.replace relations
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return relation?.rel_type && relation.event_id && (relType ? relation.rel_type === relType : true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -103,7 +103,7 @@ export class Relations extends TypedEventEmitter<RelationsEvent, EventHandlerMap
|
|||||||
|
|
||||||
if (this.relationType === RelationType.Annotation) {
|
if (this.relationType === RelationType.Annotation) {
|
||||||
this.addAnnotationToAggregation(event);
|
this.addAnnotationToAggregation(event);
|
||||||
} else if (this.relationType === RelationType.Replace && this.targetEvent) {
|
} else if (this.relationType === RelationType.Replace && this.targetEvent && !this.targetEvent.isState()) {
|
||||||
const lastReplacement = await this.getLastReplacement();
|
const lastReplacement = await this.getLastReplacement();
|
||||||
this.targetEvent.makeReplaced(lastReplacement);
|
this.targetEvent.makeReplaced(lastReplacement);
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ export class Relations extends TypedEventEmitter<RelationsEvent, EventHandlerMap
|
|||||||
|
|
||||||
if (this.relationType === RelationType.Annotation) {
|
if (this.relationType === RelationType.Annotation) {
|
||||||
this.removeAnnotationFromAggregation(event);
|
this.removeAnnotationFromAggregation(event);
|
||||||
} else if (this.relationType === RelationType.Replace && this.targetEvent) {
|
} else if (this.relationType === RelationType.Replace && this.targetEvent && !this.targetEvent.isState()) {
|
||||||
const lastReplacement = await this.getLastReplacement();
|
const lastReplacement = await this.getLastReplacement();
|
||||||
this.targetEvent.makeReplaced(lastReplacement);
|
this.targetEvent.makeReplaced(lastReplacement);
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ export class Relations extends TypedEventEmitter<RelationsEvent, EventHandlerMap
|
|||||||
if (this.relationType === RelationType.Annotation) {
|
if (this.relationType === RelationType.Annotation) {
|
||||||
// Remove the redacted annotation from aggregation by key
|
// Remove the redacted annotation from aggregation by key
|
||||||
this.removeAnnotationFromAggregation(redactedEvent);
|
this.removeAnnotationFromAggregation(redactedEvent);
|
||||||
} else if (this.relationType === RelationType.Replace && this.targetEvent) {
|
} else if (this.relationType === RelationType.Replace && this.targetEvent && !this.targetEvent.isState()) {
|
||||||
const lastReplacement = await this.getLastReplacement();
|
const lastReplacement = await this.getLastReplacement();
|
||||||
this.targetEvent.makeReplaced(lastReplacement);
|
this.targetEvent.makeReplaced(lastReplacement);
|
||||||
}
|
}
|
||||||
@@ -364,7 +364,7 @@ export class Relations extends TypedEventEmitter<RelationsEvent, EventHandlerMap
|
|||||||
}
|
}
|
||||||
this.targetEvent = event;
|
this.targetEvent = event;
|
||||||
|
|
||||||
if (this.relationType === RelationType.Replace) {
|
if (this.relationType === RelationType.Replace && !this.targetEvent.isState()) {
|
||||||
const replacement = await this.getLastReplacement();
|
const replacement = await this.getLastReplacement();
|
||||||
// this is the initial update, so only call it if we already have something
|
// this is the initial update, so only call it if we already have something
|
||||||
// to not emit Event.replaced needlessly
|
// to not emit Event.replaced needlessly
|
||||||
|
Reference in New Issue
Block a user