forked from mystiq/hydrogen-web
Implement offline support for context entries
This commit is contained in:
parent
a59bf7c002
commit
acafae7d3a
4 changed files with 45 additions and 24 deletions
|
@ -101,6 +101,7 @@ export class Timeline {
|
||||||
pe => this._mapPendingEventToEntry(pe),
|
pe => this._mapPendingEventToEntry(pe),
|
||||||
(pee, params) => {
|
(pee, params) => {
|
||||||
// is sending but redacted, who do we detect that here to remove the relation?
|
// is sending but redacted, who do we detect that here to remove the relation?
|
||||||
|
this._loadContextEntriesWhereNeeded([pee]);
|
||||||
pee.notifyUpdate(params);
|
pee.notifyUpdate(params);
|
||||||
},
|
},
|
||||||
pee => this._applyAndEmitLocalRelationChange(pee, target => target.removeLocalRelation(pee))
|
pee => this._applyAndEmitLocalRelationChange(pee, target => target.removeLocalRelation(pee))
|
||||||
|
@ -124,6 +125,7 @@ export class Timeline {
|
||||||
pendingEvent: pe, member: this._ownMember,
|
pendingEvent: pe, member: this._ownMember,
|
||||||
clock: this._clock, redactingEntry
|
clock: this._clock, redactingEntry
|
||||||
});
|
});
|
||||||
|
this._loadContextEntriesWhereNeeded([pee]);
|
||||||
this._applyAndEmitLocalRelationChange(pee, target => target.addRelation(pee));
|
this._applyAndEmitLocalRelationChange(pee, target => target.addRelation(pee));
|
||||||
return pee;
|
return pee;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ export class BaseEventEntry extends BaseEntry {
|
||||||
super(fragmentIdComparer);
|
super(fragmentIdComparer);
|
||||||
this._pendingRedactions = null;
|
this._pendingRedactions = null;
|
||||||
this._pendingAnnotations = null;
|
this._pendingAnnotations = null;
|
||||||
|
this._contextEntry = null;
|
||||||
|
this._contextForEntries = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isReply() {
|
get isReply() {
|
||||||
|
@ -52,6 +54,26 @@ export class BaseEventEntry extends BaseEntry {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setContextEntry(entry) {
|
||||||
|
this._contextEntry = entry;
|
||||||
|
entry._setAsContextOf(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
_setAsContextOf(entry) {
|
||||||
|
if (!this._contextForEntries) {
|
||||||
|
this._contextForEntries = [];
|
||||||
|
}
|
||||||
|
this._contextForEntries.push(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
get contextForEntries() {
|
||||||
|
return this._contextForEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
get contextEntry() {
|
||||||
|
return this._contextEntry;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Aggregates relation or redaction of remote relation.
|
Aggregates relation or redaction of remote relation.
|
||||||
Used in two situations:
|
Used in two situations:
|
||||||
|
|
|
@ -24,8 +24,6 @@ export class EventEntry extends BaseEventEntry {
|
||||||
this._eventEntry = eventEntry;
|
this._eventEntry = eventEntry;
|
||||||
this._decryptionError = null;
|
this._decryptionError = null;
|
||||||
this._decryptionResult = null;
|
this._decryptionResult = null;
|
||||||
this._contextEntry = null;
|
|
||||||
this._contextForEntries = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clone() {
|
clone() {
|
||||||
|
@ -45,20 +43,8 @@ export class EventEntry extends BaseEventEntry {
|
||||||
this._contextEntry = other.contextEntry;
|
this._contextEntry = other.contextEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
setContextEntry(entry) {
|
setRelatedEntry(entry) {
|
||||||
this._contextEntry = entry;
|
this._relatedEntry = entry;
|
||||||
entry._setAsContextOf(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
_setAsContextOf(entry) {
|
|
||||||
if (!this._contextForEntries) {
|
|
||||||
this._contextForEntries = [];
|
|
||||||
}
|
|
||||||
this._contextForEntries.push(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
get contextForEntries() {
|
|
||||||
return this._contextForEntries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get event() {
|
get event() {
|
||||||
|
@ -142,18 +128,13 @@ export class EventEntry extends BaseEventEntry {
|
||||||
return getRelatedEventId(this.event);
|
return getRelatedEventId(this.event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// similar to relatedEventID but only for replies
|
get threadEventId() {
|
||||||
get contextEventId() {
|
if (this.isThread) {
|
||||||
if (this.isReply) {
|
return this.relation?.event_id;
|
||||||
return this.relatedEventId;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get contextEntry() {
|
|
||||||
return this._contextEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
get isRedacted() {
|
get isRedacted() {
|
||||||
return super.isRedacted || isRedacted(this._eventEntry.event);
|
return super.isRedacted || isRedacted(this._eventEntry.event);
|
||||||
}
|
}
|
||||||
|
@ -176,6 +157,15 @@ export class EventEntry extends BaseEventEntry {
|
||||||
const originalRelation = originalContent && getRelationFromContent(originalContent);
|
const originalRelation = originalContent && getRelationFromContent(originalContent);
|
||||||
return originalRelation || getRelationFromContent(this.content);
|
return originalRelation || getRelationFromContent(this.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// similar to relatedEventID but only for replies
|
||||||
|
get contextEventId() {
|
||||||
|
if (this.isReply) {
|
||||||
|
return this.relatedEventId;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
import {withTextBody, withContent, createEvent} from "../../../../mocks/event.js";
|
import {withTextBody, withContent, createEvent} from "../../../../mocks/event.js";
|
||||||
|
|
|
@ -100,4 +100,11 @@ export class PendingEventEntry extends BaseEventEntry {
|
||||||
get redactingEntry() {
|
get redactingEntry() {
|
||||||
return this._redactingEntry;
|
return this._redactingEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get contextEventId() {
|
||||||
|
if (this.isReply) {
|
||||||
|
return this._pendingEvent.relatedEventId ?? this._pendingEvent.relatedTxnId;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue