mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Accomodate in_reply_to relation shape
This commit is contained in:
parent
fdcafaf6d3
commit
800b4785d1
@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
import {createEnum} from "../../../utils/enum.js";
|
import {createEnum} from "../../../utils/enum.js";
|
||||||
import {AbortError} from "../../../utils/error.js";
|
import {AbortError} from "../../../utils/error.js";
|
||||||
import {REDACTION_TYPE} from "../common.js";
|
import {REDACTION_TYPE} from "../common.js";
|
||||||
import {getRelationFromContent} from "../timeline/relations.js";
|
import {getRelationFromContent, getRelationTarget, setRelationTarget} from "../timeline/relations.js";
|
||||||
|
|
||||||
export const SendStatus = createEnum(
|
export const SendStatus = createEnum(
|
||||||
"Waiting",
|
"Waiting",
|
||||||
@ -54,7 +54,7 @@ export class PendingEvent {
|
|||||||
const relation = getRelationFromContent(this.content);
|
const relation = getRelationFromContent(this.content);
|
||||||
if (relation) {
|
if (relation) {
|
||||||
// may be null when target is not sent yet, is intended
|
// may be null when target is not sent yet, is intended
|
||||||
return relation.event_id;
|
return getRelationTarget(relation);
|
||||||
} else {
|
} else {
|
||||||
return this._data.relatedEventId;
|
return this._data.relatedEventId;
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ export class PendingEvent {
|
|||||||
setRelatedEventId(eventId) {
|
setRelatedEventId(eventId) {
|
||||||
const relation = getRelationFromContent(this.content);
|
const relation = getRelationFromContent(this.content);
|
||||||
if (relation) {
|
if (relation) {
|
||||||
relation.event_id = eventId;
|
setRelationTarget(relation, eventId);
|
||||||
} else {
|
} else {
|
||||||
this._data.relatedEventId = eventId;
|
this._data.relatedEventId = eventId;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import {ConnectionError} from "../../error.js";
|
|||||||
import {PendingEvent, SendStatus} from "./PendingEvent.js";
|
import {PendingEvent, SendStatus} from "./PendingEvent.js";
|
||||||
import {makeTxnId, isTxnId} from "../../common.js";
|
import {makeTxnId, isTxnId} from "../../common.js";
|
||||||
import {REDACTION_TYPE} from "../common.js";
|
import {REDACTION_TYPE} from "../common.js";
|
||||||
import {getRelationFromContent, REACTION_TYPE, ANNOTATION_RELATION_TYPE} from "../timeline/relations.js";
|
import {getRelationFromContent, getRelationTarget, setRelationTarget, REACTION_TYPE, ANNOTATION_RELATION_TYPE} from "../timeline/relations.js";
|
||||||
|
|
||||||
export class SendQueue {
|
export class SendQueue {
|
||||||
constructor({roomId, storage, hsApi, pendingEvents}) {
|
constructor({roomId, storage, hsApi, pendingEvents}) {
|
||||||
@ -206,11 +206,13 @@ export class SendQueue {
|
|||||||
const relation = getRelationFromContent(content);
|
const relation = getRelationFromContent(content);
|
||||||
let relatedTxnId = null;
|
let relatedTxnId = null;
|
||||||
if (relation) {
|
if (relation) {
|
||||||
if (isTxnId(relation.event_id)) {
|
const relationTarget = getRelationTarget(relation);
|
||||||
relatedTxnId = relation.event_id;
|
if (isTxnId(relationTarget)) {
|
||||||
relation.event_id = null;
|
relatedTxnId = relationTarget;
|
||||||
|
setRelationTarget(relation, null);
|
||||||
}
|
}
|
||||||
if (relation.rel_type === ANNOTATION_RELATION_TYPE) {
|
if (relation.rel_type === ANNOTATION_RELATION_TYPE) {
|
||||||
|
// Here we know the shape of the relation, and can use event_id safely
|
||||||
const isAlreadyAnnotating = this._pendingEvents.array.some(pe => {
|
const isAlreadyAnnotating = this._pendingEvents.array.some(pe => {
|
||||||
const r = getRelationFromContent(pe.content);
|
const r = getRelationFromContent(pe.content);
|
||||||
return pe.eventType === eventType && r && r.key === relation.key &&
|
return pe.eventType === eventType && r && r.key === relation.key &&
|
||||||
|
@ -30,7 +30,8 @@ export class RelationWriter {
|
|||||||
const {relatedEventId} = sourceEntry;
|
const {relatedEventId} = sourceEntry;
|
||||||
if (relatedEventId) {
|
if (relatedEventId) {
|
||||||
const relation = getRelation(sourceEntry.event);
|
const relation = getRelation(sourceEntry.event);
|
||||||
if (relation) {
|
if (relation && relation.rel_type) {
|
||||||
|
// we don't consider replies (which aren't relations in the MSC2674 sense)
|
||||||
txn.timelineRelations.add(this._roomId, relation.event_id, relation.rel_type, sourceEntry.id);
|
txn.timelineRelations.add(this._roomId, relation.event_id, relation.rel_type, sourceEntry.id);
|
||||||
}
|
}
|
||||||
const target = await txn.timelineEvents.getByEventId(this._roomId, relatedEventId);
|
const target = await txn.timelineEvents.getByEventId(this._roomId, relatedEventId);
|
||||||
@ -120,7 +121,7 @@ export class RelationWriter {
|
|||||||
log.set("id", redactedEvent.event_id);
|
log.set("id", redactedEvent.event_id);
|
||||||
|
|
||||||
const relation = getRelation(redactedEvent);
|
const relation = getRelation(redactedEvent);
|
||||||
if (relation) {
|
if (relation && relation.rel_type) {
|
||||||
txn.timelineRelations.remove(this._roomId, relation.event_id, relation.rel_type, redactedEvent.event_id);
|
txn.timelineRelations.remove(this._roomId, relation.event_id, relation.rel_type, redactedEvent.event_id);
|
||||||
}
|
}
|
||||||
// check if we're the target of a relation and remove all relations then as well
|
// check if we're the target of a relation and remove all relations then as well
|
||||||
|
@ -29,13 +29,25 @@ export function createAnnotation(targetId, key) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRelationTarget(relation) {
|
||||||
|
return relation.event_id || relation["m.in_reply_to"]?.event_id
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setRelationTarget(relation, target) {
|
||||||
|
if (relation.event_id !== undefined) {
|
||||||
|
relation.event_id = target;
|
||||||
|
} else if (relation["m.in_reply_to"]) {
|
||||||
|
relation["m.in_reply_to"].event_id = target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function getRelatedEventId(event) {
|
export function getRelatedEventId(event) {
|
||||||
if (event.type === REDACTION_TYPE) {
|
if (event.type === REDACTION_TYPE) {
|
||||||
return event.redacts;
|
return event.redacts;
|
||||||
} else {
|
} else {
|
||||||
const relation = getRelation(event);
|
const relation = getRelation(event);
|
||||||
if (relation) {
|
if (relation) {
|
||||||
return relation.event_id;
|
return getRelationTarget(relation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user