From 7cb686ce8e6d883bda23429ff23f280edce4b4a3 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 18 Aug 2021 18:21:58 +0200 Subject: [PATCH] convert EventKey to ts --- .../timeline/{EventKey.js => EventKey.ts} | 28 ++++++++++--------- src/matrix/room/timeline/entries/BaseEntry.ts | 2 +- .../room/timeline/persistence/GapWriter.js | 2 +- .../room/timeline/persistence/SyncWriter.js | 2 +- .../storage/idb/stores/TimelineEventStore.ts | 7 +++++ 5 files changed, 25 insertions(+), 16 deletions(-) rename src/matrix/room/timeline/{EventKey.js => EventKey.ts} (75%) diff --git a/src/matrix/room/timeline/EventKey.js b/src/matrix/room/timeline/EventKey.ts similarity index 75% rename from src/matrix/room/timeline/EventKey.js rename to src/matrix/room/timeline/EventKey.ts index af01a7e5..eb8a7724 100644 --- a/src/matrix/room/timeline/EventKey.js +++ b/src/matrix/room/timeline/EventKey.ts @@ -15,20 +15,22 @@ limitations under the License. */ import {KeyLimits} from "../../storage/common"; +import {Direction} from "./Direction"; // key for events in the timelineEvents store export class EventKey { - constructor(fragmentId, eventIndex) { - this.fragmentId = fragmentId; - this.eventIndex = eventIndex; + constructor( + public readonly fragmentId: number, + public readonly eventIndex: number + ) { } - nextFragmentKey() { + nextFragmentKey(): EventKey { // could take MIN_EVENT_INDEX here if it can't be paged back return new EventKey(this.fragmentId + 1, KeyLimits.middleStorageKey); } - nextKeyForDirection(direction) { + nextKeyForDirection(direction: Direction): EventKey { if (direction.isForward) { return this.nextKey(); } else { @@ -36,35 +38,35 @@ export class EventKey { } } - previousKey() { + previousKey(): EventKey { return new EventKey(this.fragmentId, this.eventIndex - 1); } - nextKey() { + nextKey(): EventKey { return new EventKey(this.fragmentId, this.eventIndex + 1); } - static get maxKey() { + static get maxKey(): EventKey { return new EventKey(KeyLimits.maxStorageKey, KeyLimits.maxStorageKey); } - static get minKey() { + static get minKey(): EventKey { return new EventKey(KeyLimits.minStorageKey, KeyLimits.minStorageKey); } - static get defaultLiveKey() { + static get defaultLiveKey(): EventKey { return EventKey.defaultFragmentKey(KeyLimits.minStorageKey); } - static defaultFragmentKey(fragmentId) { + static defaultFragmentKey(fragmentId: number): EventKey { return new EventKey(fragmentId, KeyLimits.middleStorageKey); } - toString() { + toString(): string { return `[${this.fragmentId}/${this.eventIndex}]`; } - equals(other) { + equals(other: EventKey): boolean { return this.fragmentId === other?.fragmentId && this.eventIndex === other?.eventIndex; } } diff --git a/src/matrix/room/timeline/entries/BaseEntry.ts b/src/matrix/room/timeline/entries/BaseEntry.ts index 1ef6a863..23ec268c 100644 --- a/src/matrix/room/timeline/entries/BaseEntry.ts +++ b/src/matrix/room/timeline/entries/BaseEntry.ts @@ -15,7 +15,7 @@ limitations under the License. */ //entries can be sorted, first by fragment, then by entry index. -import {EventKey} from "../EventKey.js"; +import {EventKey} from "../EventKey"; export const PENDING_FRAGMENT_ID = Number.MAX_SAFE_INTEGER; interface FragmentIdComparer { diff --git a/src/matrix/room/timeline/persistence/GapWriter.js b/src/matrix/room/timeline/persistence/GapWriter.js index 2fc56a21..e133d713 100644 --- a/src/matrix/room/timeline/persistence/GapWriter.js +++ b/src/matrix/room/timeline/persistence/GapWriter.js @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {EventKey} from "../EventKey.js"; +import {EventKey} from "../EventKey"; import {EventEntry} from "../entries/EventEntry.js"; import {createEventEntry, directionalAppend} from "./common.js"; import {RoomMember, EVENT_TYPE as MEMBER_EVENT_TYPE} from "../../members/RoomMember.js"; diff --git a/src/matrix/room/timeline/persistence/SyncWriter.js b/src/matrix/room/timeline/persistence/SyncWriter.js index 54fd5a0b..1ee2ce7d 100644 --- a/src/matrix/room/timeline/persistence/SyncWriter.js +++ b/src/matrix/room/timeline/persistence/SyncWriter.js @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {EventKey} from "../EventKey.js"; +import {EventKey} from "../EventKey"; import {EventEntry} from "../entries/EventEntry.js"; import {FragmentBoundaryEntry} from "../entries/FragmentBoundaryEntry.js"; import {createEventEntry} from "./common.js"; diff --git a/src/matrix/storage/idb/stores/TimelineEventStore.ts b/src/matrix/storage/idb/stores/TimelineEventStore.ts index f659bdbd..6b1c854b 100644 --- a/src/matrix/storage/idb/stores/TimelineEventStore.ts +++ b/src/matrix/storage/idb/stores/TimelineEventStore.ts @@ -14,12 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ +<<<<<<< HEAD:src/matrix/storage/idb/stores/TimelineEventStore.ts import {EventKey} from "../../../room/timeline/EventKey.js"; import { StorageError } from "../../common"; import { encodeUint32 } from "../utils"; import {KeyLimits} from "../../common"; import {Store} from "../Store"; import {TimelineEvent, StateEvent} from "../../types"; +======= +import {EventKey} from "../../../room/timeline/EventKey"; +import { StorageError } from "../../common.js"; +import { encodeUint32 } from "../utils.js"; +import {KeyLimits} from "../../common.js"; +>>>>>>> b01c3283 (convert EventKey to ts):src/matrix/storage/idb/stores/TimelineEventStore.js interface Annotation { count: number;