mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 19:45:05 +01:00
Change method name
This commit is contained in:
parent
a2ab36480f
commit
f76217dcce
@ -85,7 +85,7 @@ export class Timeline {
|
|||||||
const readerRequest = this._disposables.track(this._timelineReader.readFromEnd(20, txn, log));
|
const readerRequest = this._disposables.track(this._timelineReader.readFromEnd(20, txn, log));
|
||||||
try {
|
try {
|
||||||
const entries = await readerRequest.complete();
|
const entries = await readerRequest.complete();
|
||||||
this._loadRelatedEvents(entries);
|
this._loadContextEntriesWhereNeeded(entries);
|
||||||
this._setupEntries(entries);
|
this._setupEntries(entries);
|
||||||
} finally {
|
} finally {
|
||||||
this._disposables.disposeTracked(readerRequest);
|
this._disposables.disposeTracked(readerRequest);
|
||||||
@ -224,7 +224,7 @@ export class Timeline {
|
|||||||
replaceEntries(entries) {
|
replaceEntries(entries) {
|
||||||
this._addLocalRelationsToNewRemoteEntries(entries);
|
this._addLocalRelationsToNewRemoteEntries(entries);
|
||||||
this._updateEntriesNotInTimeline(entries);
|
this._updateEntriesNotInTimeline(entries);
|
||||||
this._loadRelatedEvents(entries);
|
this._loadContextEntriesWhereNeeded(entries);
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
try {
|
try {
|
||||||
this._remoteEntries.getAndUpdate(entry, Timeline._entryUpdater);
|
this._remoteEntries.getAndUpdate(entry, Timeline._entryUpdater);
|
||||||
@ -253,7 +253,7 @@ export class Timeline {
|
|||||||
this._updateEntriesNotInTimeline(newEntries);
|
this._updateEntriesNotInTimeline(newEntries);
|
||||||
this._moveEntryToRemoteEntries(newEntries);
|
this._moveEntryToRemoteEntries(newEntries);
|
||||||
this._remoteEntries.setManySorted(newEntries);
|
this._remoteEntries.setManySorted(newEntries);
|
||||||
this._loadRelatedEvents(newEntries);
|
this._loadContextEntriesWhereNeeded(newEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -308,7 +308,15 @@ export class Timeline {
|
|||||||
this._findAndUpdateEntryById(txnId, eventId, () => true);
|
this._findAndUpdateEntryById(txnId, eventId, () => true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _loadRelatedEvents(entries) {
|
/**
|
||||||
|
* For each entry in entries, this method associates a context-entry (if needed) to it.
|
||||||
|
* The context-entry is fetched using the following strategies (in the same order as given):
|
||||||
|
* - timeline
|
||||||
|
* - storage
|
||||||
|
* - homeserver
|
||||||
|
* @param {EventEntry[]} entries
|
||||||
|
*/
|
||||||
|
async _loadContextEntriesWhereNeeded(entries) {
|
||||||
const entriesNeedingContext = entries.filter(e => !!e.contextEventId);
|
const entriesNeedingContext = entries.filter(e => !!e.contextEventId);
|
||||||
for (const entry of entriesNeedingContext) {
|
for (const entry of entriesNeedingContext) {
|
||||||
const id = entry.contextEventId;
|
const id = entry.contextEventId;
|
||||||
@ -730,7 +738,7 @@ export function tests() {
|
|||||||
const entryB = new EventEntry({ event });
|
const entryB = new EventEntry({ event });
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
timeline._remoteEntries.setManyUnsorted([entryA, entryB]);
|
timeline._remoteEntries.setManyUnsorted([entryA, entryB]);
|
||||||
await timeline._loadRelatedEvents([entryA, entryB]);
|
await timeline._loadContextEntriesWhereNeeded([entryA, entryB]);
|
||||||
assert.deepEqual(entryB.contextEntry, entryA);
|
assert.deepEqual(entryB.contextEntry, entryA);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -750,7 +758,7 @@ export function tests() {
|
|||||||
const entryB = new EventEntry({ event });
|
const entryB = new EventEntry({ event });
|
||||||
timeline._getEventFromStorage = () => entryA
|
timeline._getEventFromStorage = () => entryA
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
await timeline._loadRelatedEvents([entryB]);
|
await timeline._loadContextEntriesWhereNeeded([entryB]);
|
||||||
assert.deepEqual(entryB.contextEntry, entryA);
|
assert.deepEqual(entryB.contextEntry, entryA);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -770,7 +778,7 @@ export function tests() {
|
|||||||
const entryB = new EventEntry({ event });
|
const entryB = new EventEntry({ event });
|
||||||
timeline._getEventFromHomeserver = () => entryA
|
timeline._getEventFromHomeserver = () => entryA
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
await timeline._loadRelatedEvents([entryB]);
|
await timeline._loadContextEntriesWhereNeeded([entryB]);
|
||||||
assert.deepEqual(entryB.contextEntry, entryA);
|
assert.deepEqual(entryB.contextEntry, entryA);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -791,7 +799,7 @@ export function tests() {
|
|||||||
const entryC = new EventEntry({ event: withContent(content, createEvent("m.room.message", "event_id_3", bob)) });
|
const entryC = new EventEntry({ event: withContent(content, createEvent("m.room.message", "event_id_3", bob)) });
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
timeline._remoteEntries.setManyUnsorted([entryA, entryB, entryC]);
|
timeline._remoteEntries.setManyUnsorted([entryA, entryB, entryC]);
|
||||||
await timeline._loadRelatedEvents([entryA, entryB, entryC]);
|
await timeline._loadContextEntriesWhereNeeded([entryA, entryB, entryC]);
|
||||||
assert.deepEqual(entryA.contextForEntries, [entryB, entryC]);
|
assert.deepEqual(entryA.contextForEntries, [entryB, entryC]);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -811,7 +819,7 @@ export function tests() {
|
|||||||
const entryB = new EventEntry({ event });
|
const entryB = new EventEntry({ event });
|
||||||
timeline._getEventFromStorage = () => entryA
|
timeline._getEventFromStorage = () => entryA
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
await timeline._loadRelatedEvents([entryB]);
|
await timeline._loadContextEntriesWhereNeeded([entryB]);
|
||||||
const redactingEntry = new EventEntry({ event: withRedacts(entryA.id, "foo", createEvent("m.room.redaction", "event_id_3", alice)) });
|
const redactingEntry = new EventEntry({ event: withRedacts(entryA.id, "foo", createEvent("m.room.redaction", "event_id_3", alice)) });
|
||||||
timeline.addEntries([redactingEntry]);
|
timeline.addEntries([redactingEntry]);
|
||||||
const contextEntry = timeline._contextEntriesNotInTimeline.get(entryA.id);
|
const contextEntry = timeline._contextEntriesNotInTimeline.get(entryA.id);
|
||||||
@ -867,7 +875,7 @@ export function tests() {
|
|||||||
timeline._getEventFromHomeserver = () => entryA
|
timeline._getEventFromHomeserver = () => entryA
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
timeline.addEntries([entryB]);
|
timeline.addEntries([entryB]);
|
||||||
await timeline._loadRelatedEvents([entryB]);
|
await timeline._loadContextEntriesWhereNeeded([entryB]);
|
||||||
assert.strictEqual(timeline._contextEntriesNotInTimeline.has(entryA.id), true);
|
assert.strictEqual(timeline._contextEntriesNotInTimeline.has(entryA.id), true);
|
||||||
timeline.addEntries([entryA]);
|
timeline.addEntries([entryA]);
|
||||||
assert.strictEqual(timeline._contextEntriesNotInTimeline.has(entryA.id), false);
|
assert.strictEqual(timeline._contextEntriesNotInTimeline.has(entryA.id), false);
|
||||||
|
Loading…
Reference in New Issue
Block a user