forked from mystiq/hydrogen-web
rename Gap/SyncPersistence to Writer, in line with TimelineReader
This commit is contained in:
parent
784588440c
commit
fa4efe0132
4 changed files with 11 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
||||||
import EventEmitter from "../../EventEmitter.js";
|
import EventEmitter from "../../EventEmitter.js";
|
||||||
import RoomSummary from "./summary.js";
|
import RoomSummary from "./summary.js";
|
||||||
import SyncPersister from "./timeline/persistence/SyncPersister.js";
|
import SyncWriter from "./timeline/persistence/SyncWriter.js";
|
||||||
import Timeline from "./timeline/Timeline.js";
|
import Timeline from "./timeline/Timeline.js";
|
||||||
import FragmentIdComparer from "./timeline/FragmentIdComparer.js";
|
import FragmentIdComparer from "./timeline/FragmentIdComparer.js";
|
||||||
|
|
||||||
|
@ -12,14 +12,14 @@ export default class Room extends EventEmitter {
|
||||||
this._hsApi = hsApi;
|
this._hsApi = hsApi;
|
||||||
this._summary = new RoomSummary(roomId);
|
this._summary = new RoomSummary(roomId);
|
||||||
this._fragmentIdComparer = new FragmentIdComparer([]);
|
this._fragmentIdComparer = new FragmentIdComparer([]);
|
||||||
this._syncPersister = new SyncPersister({roomId, storage, fragmentIdComparer: this._fragmentIdComparer});
|
this._syncWriter = new SyncWriter({roomId, storage, fragmentIdComparer: this._fragmentIdComparer});
|
||||||
this._emitCollectionChange = emitCollectionChange;
|
this._emitCollectionChange = emitCollectionChange;
|
||||||
this._timeline = null;
|
this._timeline = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
persistSync(roomResponse, membership, txn) {
|
persistSync(roomResponse, membership, txn) {
|
||||||
const summaryChanged = this._summary.applySync(roomResponse, membership, txn);
|
const summaryChanged = this._summary.applySync(roomResponse, membership, txn);
|
||||||
const newTimelineEntries = this._syncPersister.persistSync(roomResponse, txn);
|
const newTimelineEntries = this._syncWriter.writeSync(roomResponse, txn);
|
||||||
return {summaryChanged, newTimelineEntries};
|
return {summaryChanged, newTimelineEntries};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ export default class Room extends EventEmitter {
|
||||||
|
|
||||||
load(summary, txn) {
|
load(summary, txn) {
|
||||||
this._summary.load(summary);
|
this._summary.load(summary);
|
||||||
return this._syncPersister.load(txn);
|
return this._syncWriter.load(txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { ObservableArray } from "../../../observable/index.js";
|
import { ObservableArray } from "../../../observable/index.js";
|
||||||
import sortedIndex from "../../../utils/sortedIndex.js";
|
import sortedIndex from "../../../utils/sortedIndex.js";
|
||||||
import GapPersister from "./persistence/GapPersister.js";
|
import GapWriter from "./persistence/GapWriter.js";
|
||||||
import TimelineReader from "./persistence/TimelineReader.js";
|
import TimelineReader from "./persistence/TimelineReader.js";
|
||||||
|
|
||||||
export default class Timeline {
|
export default class Timeline {
|
||||||
|
@ -41,12 +41,12 @@ export default class Timeline {
|
||||||
limit: amount
|
limit: amount
|
||||||
});
|
});
|
||||||
|
|
||||||
const gapPersister = new GapPersister({
|
const gapWriter = new GapWriter({
|
||||||
roomId: this._roomId,
|
roomId: this._roomId,
|
||||||
storage: this._storage,
|
storage: this._storage,
|
||||||
fragmentIdComparer: this._fragmentIdComparer
|
fragmentIdComparer: this._fragmentIdComparer
|
||||||
});
|
});
|
||||||
const newEntries = await gapPersister.persistFragmentFill(fragmentEntry, response);
|
const newEntries = await gapWriter.writerFragmentFill(fragmentEntry, response);
|
||||||
// find where to replace existing gap with newEntries by doing binary search
|
// find where to replace existing gap with newEntries by doing binary search
|
||||||
const gapIdx = sortedIndex(this._entriesList.array, fragmentEntry, (fragmentEntry, entry) => {
|
const gapIdx = sortedIndex(this._entriesList.array, fragmentEntry, (fragmentEntry, entry) => {
|
||||||
return fragmentEntry.compare(entry);
|
return fragmentEntry.compare(entry);
|
||||||
|
|
|
@ -2,7 +2,7 @@ import EventKey from "../EventKey.js";
|
||||||
import EventEntry from "../entries/EventEntry.js";
|
import EventEntry from "../entries/EventEntry.js";
|
||||||
import {createEventEntry, directionalAppend} from "./common.js";
|
import {createEventEntry, directionalAppend} from "./common.js";
|
||||||
|
|
||||||
export default class GapPersister {
|
export default class GapWriter {
|
||||||
constructor({roomId, storage, fragmentIdComparer}) {
|
constructor({roomId, storage, fragmentIdComparer}) {
|
||||||
this._roomId = roomId;
|
this._roomId = roomId;
|
||||||
this._storage = storage;
|
this._storage = storage;
|
||||||
|
@ -71,7 +71,7 @@ export default class GapPersister {
|
||||||
txn.timelineFragments.set(fragmentEntry.fragment);
|
txn.timelineFragments.set(fragmentEntry.fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
async persistFragmentFill(fragmentEntry, response) {
|
async writeFragmentFill(fragmentEntry, response) {
|
||||||
const {fragmentId, direction} = fragmentEntry;
|
const {fragmentId, direction} = fragmentEntry;
|
||||||
// assuming that chunk is in chronological order when backwards too?
|
// assuming that chunk is in chronological order when backwards too?
|
||||||
const {chunk, start, end} = response;
|
const {chunk, start, end} = response;
|
|
@ -3,7 +3,7 @@ import EventEntry from "../entries/EventEntry.js";
|
||||||
import FragmentBoundaryEntry from "../entries/FragmentBoundaryEntry.js";
|
import FragmentBoundaryEntry from "../entries/FragmentBoundaryEntry.js";
|
||||||
import {createEventEntry} from "./common.js";
|
import {createEventEntry} from "./common.js";
|
||||||
|
|
||||||
export default class SyncPersister {
|
export default class SyncWriter {
|
||||||
constructor({roomId, storage, fragmentIdComparer}) {
|
constructor({roomId, storage, fragmentIdComparer}) {
|
||||||
this._roomId = roomId;
|
this._roomId = roomId;
|
||||||
this._storage = storage;
|
this._storage = storage;
|
||||||
|
@ -65,7 +65,7 @@ export default class SyncPersister {
|
||||||
return {oldFragment, newFragment};
|
return {oldFragment, newFragment};
|
||||||
}
|
}
|
||||||
|
|
||||||
async persistSync(roomResponse, txn) {
|
async writeSync(roomResponse, txn) {
|
||||||
const entries = [];
|
const entries = [];
|
||||||
if (!this._lastLiveKey) {
|
if (!this._lastLiveKey) {
|
||||||
// means we haven't synced this room yet (just joined or did initial sync)
|
// means we haven't synced this room yet (just joined or did initial sync)
|
Loading…
Reference in a new issue