diff --git a/src/Platform.js b/src/Platform.js new file mode 100644 index 00000000..c3ce381f --- /dev/null +++ b/src/Platform.js @@ -0,0 +1,5 @@ +// #ifdef PLATFORM_GNOME +// export {default} from "./ui/gnome/GnomePlatform.js"; +// #else +export {default} from "./ui/web/WebPlatform.js"; +// #endif diff --git a/src/matrix/room/timeline/EventKey.js b/src/matrix/room/timeline/EventKey.js index e05c38f4..7b8460d1 100644 --- a/src/matrix/room/timeline/EventKey.js +++ b/src/matrix/room/timeline/EventKey.js @@ -1,7 +1,4 @@ -const DEFAULT_LIVE_FRAGMENT_ID = 0; -const MIN_EVENT_INDEX = Number.MIN_SAFE_INTEGER + 1; -const MAX_EVENT_INDEX = Number.MAX_SAFE_INTEGER - 1; -const MID_EVENT_INDEX = 0; +import Platform from "../../../Platform.js"; // key for events in the timelineEvents store export default class EventKey { @@ -12,7 +9,7 @@ export default class EventKey { nextFragmentKey() { // could take MIN_EVENT_INDEX here if it can't be paged back - return new EventKey(this.fragmentId + 1, MID_EVENT_INDEX); + return new EventKey(this.fragmentId + 1, Platform.middleStorageKey); } nextKeyForDirection(direction) { @@ -32,15 +29,15 @@ export default class EventKey { } static get maxKey() { - return new EventKey(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER); + return new EventKey(Platform.maxStorageKey, Platform.maxStorageKey); } static get minKey() { - return new EventKey(Number.MIN_SAFE_INTEGER, Number.MIN_SAFE_INTEGER); + return new EventKey(Platform.minStorageKey, Platform.minStorageKey); } static get defaultLiveKey() { - return new EventKey(DEFAULT_LIVE_FRAGMENT_ID, MID_EVENT_INDEX); + return new EventKey(Platform.minStorageKey, Platform.middleStorageKey); } toString() { diff --git a/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js b/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js index 5eb772f3..4dc0ab61 100644 --- a/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js +++ b/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js @@ -1,6 +1,7 @@ import BaseEntry from "./BaseEntry.js"; import Direction from "../Direction.js"; import {isValidFragmentId} from "../common.js"; +import Platform from "../../../../Platform.js"; export default class FragmentBoundaryEntry extends BaseEntry { constructor(fragment, isFragmentStart, fragmentIdComparer) { @@ -36,9 +37,9 @@ export default class FragmentBoundaryEntry extends BaseEntry { get entryIndex() { if (this.started) { - return Number.MIN_SAFE_INTEGER; + return Platform.minStorageKey; } else { - return Number.MAX_SAFE_INTEGER; + return Platform.maxStorageKey; } } diff --git a/src/matrix/storage/idb/stores/TimelineEventStore.js b/src/matrix/storage/idb/stores/TimelineEventStore.js index 7c333245..e53f6e70 100644 --- a/src/matrix/storage/idb/stores/TimelineEventStore.js +++ b/src/matrix/storage/idb/stores/TimelineEventStore.js @@ -1,4 +1,5 @@ import EventKey from "../../../room/timeline/EventKey.js"; +import Platform from "../../../../Platform.js"; class Range { constructor(only, lower, upper, lowerOpen, upperOpen) { @@ -19,7 +20,7 @@ class Range { if (this._lower && !this._upper) { return IDBKeyRange.bound( [roomId, this._lower.fragmentId, this._lower.eventIndex], - [roomId, this._lower.fragmentId, EventKey.maxKey.eventIndex], + [roomId, this._lower.fragmentId, Platform.maxStorageKey], this._lowerOpen, false ); @@ -28,7 +29,7 @@ class Range { // also bound as we don't want to move into another roomId if (!this._lower && this._upper) { return IDBKeyRange.bound( - [roomId, this._upper.fragmentId, EventKey.minKey.eventIndex], + [roomId, this._upper.fragmentId, Platform.minStorageKey], [roomId, this._upper.fragmentId, this._upper.eventIndex], false, this._upperOpen diff --git a/src/matrix/storage/idb/stores/TimelineFragmentStore.js b/src/matrix/storage/idb/stores/TimelineFragmentStore.js index 86bd243f..1e08bbec 100644 --- a/src/matrix/storage/idb/stores/TimelineFragmentStore.js +++ b/src/matrix/storage/idb/stores/TimelineFragmentStore.js @@ -1,3 +1,5 @@ +import Platform from "../../../../Platform.js"; + export default class RoomFragmentStore { constructor(store) { this._store = store; @@ -5,8 +7,8 @@ export default class RoomFragmentStore { _allRange(roomId) { return IDBKeyRange.bound( - [roomId, Number.MIN_SAFE_INTEGER], - [roomId, Number.MAX_SAFE_INTEGER] + [roomId, Platform.minStorageKey], + [roomId, Platform.maxStorageKey] ); } diff --git a/src/ui/web/WebPlatform.js b/src/ui/web/WebPlatform.js new file mode 100644 index 00000000..cfc43fe4 --- /dev/null +++ b/src/ui/web/WebPlatform.js @@ -0,0 +1,16 @@ +export default { + get minStorageKey() { + // for indexeddb, we use unsigned 32 bit integers as keys + return 0; + }, + + get middleStorageKey() { + // for indexeddb, we use unsigned 32 bit integers as keys + return 0x7FFFFFFF; + }, + + get maxStorageKey() { + // for indexeddb, we use unsigned 32 bit integers as keys + return 0xFFFFFFFF; + }, +}