Implement offline support for context entries

This commit is contained in:
RMidhunSuresh 2022-01-11 20:58:27 +05:30
parent a59bf7c002
commit acafae7d3a
4 changed files with 45 additions and 24 deletions

View file

@ -101,6 +101,7 @@ export class Timeline {
pe => this._mapPendingEventToEntry(pe),
(pee, params) => {
// is sending but redacted, who do we detect that here to remove the relation?
this._loadContextEntriesWhereNeeded([pee]);
pee.notifyUpdate(params);
},
pee => this._applyAndEmitLocalRelationChange(pee, target => target.removeLocalRelation(pee))
@ -124,6 +125,7 @@ export class Timeline {
pendingEvent: pe, member: this._ownMember,
clock: this._clock, redactingEntry
});
this._loadContextEntriesWhereNeeded([pee]);
this._applyAndEmitLocalRelationChange(pee, target => target.addRelation(pee));
return pee;
}

View file

@ -27,6 +27,8 @@ export class BaseEventEntry extends BaseEntry {
super(fragmentIdComparer);
this._pendingRedactions = null;
this._pendingAnnotations = null;
this._contextEntry = null;
this._contextForEntries = null;
}
get isReply() {
@ -52,6 +54,26 @@ export class BaseEventEntry extends BaseEntry {
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.
Used in two situations:

View file

@ -24,8 +24,6 @@ export class EventEntry extends BaseEventEntry {
this._eventEntry = eventEntry;
this._decryptionError = null;
this._decryptionResult = null;
this._contextEntry = null;
this._contextForEntries = null;
}
clone() {
@ -45,20 +43,8 @@ export class EventEntry extends BaseEventEntry {
this._contextEntry = other.contextEntry;
}
setContextEntry(entry) {
this._contextEntry = entry;
entry._setAsContextOf(this);
}
_setAsContextOf(entry) {
if (!this._contextForEntries) {
this._contextForEntries = [];
}
this._contextForEntries.push(entry);
}
get contextForEntries() {
return this._contextForEntries;
setRelatedEntry(entry) {
this._relatedEntry = entry;
}
get event() {
@ -142,18 +128,13 @@ export class EventEntry extends BaseEventEntry {
return getRelatedEventId(this.event);
}
// similar to relatedEventID but only for replies
get contextEventId() {
if (this.isReply) {
return this.relatedEventId;
get threadEventId() {
if (this.isThread) {
return this.relation?.event_id;
}
return null;
}
get contextEntry() {
return this._contextEntry;
}
get isRedacted() {
return super.isRedacted || isRedacted(this._eventEntry.event);
}
@ -176,6 +157,15 @@ export class EventEntry extends BaseEventEntry {
const originalRelation = originalContent && getRelationFromContent(originalContent);
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";

View file

@ -100,4 +100,11 @@ export class PendingEventEntry extends BaseEventEntry {
get redactingEntry() {
return this._redactingEntry;
}
get contextEventId() {
if (this.isReply) {
return this._pendingEvent.relatedEventId ?? this._pendingEvent.relatedTxnId;
}
return null;
}
}