mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
define storage keys to be 32bit for idb / web platform
as a preparation to serialize the eventIndex and fragmentId as a 8 character string, part of a concatenated string PK, as lumia doesn't support array keys.
This commit is contained in:
parent
ca4361248f
commit
106146660c
5
src/Platform.js
Normal file
5
src/Platform.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// #ifdef PLATFORM_GNOME
|
||||||
|
// export {default} from "./ui/gnome/GnomePlatform.js";
|
||||||
|
// #else
|
||||||
|
export {default} from "./ui/web/WebPlatform.js";
|
||||||
|
// #endif
|
@ -1,7 +1,4 @@
|
|||||||
const DEFAULT_LIVE_FRAGMENT_ID = 0;
|
import Platform from "../../../Platform.js";
|
||||||
const MIN_EVENT_INDEX = Number.MIN_SAFE_INTEGER + 1;
|
|
||||||
const MAX_EVENT_INDEX = Number.MAX_SAFE_INTEGER - 1;
|
|
||||||
const MID_EVENT_INDEX = 0;
|
|
||||||
|
|
||||||
// key for events in the timelineEvents store
|
// key for events in the timelineEvents store
|
||||||
export default class EventKey {
|
export default class EventKey {
|
||||||
@ -12,7 +9,7 @@ export default class EventKey {
|
|||||||
|
|
||||||
nextFragmentKey() {
|
nextFragmentKey() {
|
||||||
// could take MIN_EVENT_INDEX here if it can't be paged back
|
// 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) {
|
nextKeyForDirection(direction) {
|
||||||
@ -32,15 +29,15 @@ export default class EventKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static get maxKey() {
|
static get maxKey() {
|
||||||
return new EventKey(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
|
return new EventKey(Platform.maxStorageKey, Platform.maxStorageKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
static get minKey() {
|
static get minKey() {
|
||||||
return new EventKey(Number.MIN_SAFE_INTEGER, Number.MIN_SAFE_INTEGER);
|
return new EventKey(Platform.minStorageKey, Platform.minStorageKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
static get defaultLiveKey() {
|
static get defaultLiveKey() {
|
||||||
return new EventKey(DEFAULT_LIVE_FRAGMENT_ID, MID_EVENT_INDEX);
|
return new EventKey(Platform.minStorageKey, Platform.middleStorageKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import BaseEntry from "./BaseEntry.js";
|
import BaseEntry from "./BaseEntry.js";
|
||||||
import Direction from "../Direction.js";
|
import Direction from "../Direction.js";
|
||||||
import {isValidFragmentId} from "../common.js";
|
import {isValidFragmentId} from "../common.js";
|
||||||
|
import Platform from "../../../../Platform.js";
|
||||||
|
|
||||||
export default class FragmentBoundaryEntry extends BaseEntry {
|
export default class FragmentBoundaryEntry extends BaseEntry {
|
||||||
constructor(fragment, isFragmentStart, fragmentIdComparer) {
|
constructor(fragment, isFragmentStart, fragmentIdComparer) {
|
||||||
@ -36,9 +37,9 @@ export default class FragmentBoundaryEntry extends BaseEntry {
|
|||||||
|
|
||||||
get entryIndex() {
|
get entryIndex() {
|
||||||
if (this.started) {
|
if (this.started) {
|
||||||
return Number.MIN_SAFE_INTEGER;
|
return Platform.minStorageKey;
|
||||||
} else {
|
} else {
|
||||||
return Number.MAX_SAFE_INTEGER;
|
return Platform.maxStorageKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import EventKey from "../../../room/timeline/EventKey.js";
|
import EventKey from "../../../room/timeline/EventKey.js";
|
||||||
|
import Platform from "../../../../Platform.js";
|
||||||
|
|
||||||
class Range {
|
class Range {
|
||||||
constructor(only, lower, upper, lowerOpen, upperOpen) {
|
constructor(only, lower, upper, lowerOpen, upperOpen) {
|
||||||
@ -19,7 +20,7 @@ class Range {
|
|||||||
if (this._lower && !this._upper) {
|
if (this._lower && !this._upper) {
|
||||||
return IDBKeyRange.bound(
|
return IDBKeyRange.bound(
|
||||||
[roomId, this._lower.fragmentId, this._lower.eventIndex],
|
[roomId, this._lower.fragmentId, this._lower.eventIndex],
|
||||||
[roomId, this._lower.fragmentId, EventKey.maxKey.eventIndex],
|
[roomId, this._lower.fragmentId, Platform.maxStorageKey],
|
||||||
this._lowerOpen,
|
this._lowerOpen,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -28,7 +29,7 @@ class Range {
|
|||||||
// also bound as we don't want to move into another roomId
|
// also bound as we don't want to move into another roomId
|
||||||
if (!this._lower && this._upper) {
|
if (!this._lower && this._upper) {
|
||||||
return IDBKeyRange.bound(
|
return IDBKeyRange.bound(
|
||||||
[roomId, this._upper.fragmentId, EventKey.minKey.eventIndex],
|
[roomId, this._upper.fragmentId, Platform.minStorageKey],
|
||||||
[roomId, this._upper.fragmentId, this._upper.eventIndex],
|
[roomId, this._upper.fragmentId, this._upper.eventIndex],
|
||||||
false,
|
false,
|
||||||
this._upperOpen
|
this._upperOpen
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import Platform from "../../../../Platform.js";
|
||||||
|
|
||||||
export default class RoomFragmentStore {
|
export default class RoomFragmentStore {
|
||||||
constructor(store) {
|
constructor(store) {
|
||||||
this._store = store;
|
this._store = store;
|
||||||
@ -5,8 +7,8 @@ export default class RoomFragmentStore {
|
|||||||
|
|
||||||
_allRange(roomId) {
|
_allRange(roomId) {
|
||||||
return IDBKeyRange.bound(
|
return IDBKeyRange.bound(
|
||||||
[roomId, Number.MIN_SAFE_INTEGER],
|
[roomId, Platform.minStorageKey],
|
||||||
[roomId, Number.MAX_SAFE_INTEGER]
|
[roomId, Platform.maxStorageKey]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
src/ui/web/WebPlatform.js
Normal file
16
src/ui/web/WebPlatform.js
Normal file
@ -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;
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user