rename SessionsStore to SessionInfoStorage

This commit is contained in:
Bruno Windels 2020-04-19 19:13:38 +02:00
parent 8c56ac3e4f
commit 80f7caadbe
7 changed files with 18 additions and 18 deletions

View File

@ -40,7 +40,7 @@ rooms should report how many messages they have queued up, and each time they se
- put in own file - put in own file
- add waitFor (won't this leak if the promise never resolves?) - add waitFor (won't this leak if the promise never resolves?)
- decide whether we want to inherit (no?) - decide whether we want to inherit (no?)
- cleanup Reconnector with recent changes, move generic code, make imports work - DONE: cleanup Reconnector with recent changes, move generic code, make imports work
- add SyncStatus as ObservableValue of enum in Sync - add SyncStatus as ObservableValue of enum in Sync
- show load progress in LoginView/SessionPickView and do away with loading screen - show load progress in LoginView/SessionPickView and do away with loading screen
- change main.js to pass in a creation function of a SessionContainer instead of everything it is replacing - change main.js to pass in a creation function of a SessionContainer instead of everything it is replacing

View File

@ -1,5 +1,5 @@
import Session from "../matrix/session.js"; import Session from "../matrix/Session.js";
import Sync from "../matrix/sync.js"; import Sync from "../matrix/Sync.js";
import SessionViewModel from "./session/SessionViewModel.js"; import SessionViewModel from "./session/SessionViewModel.js";
import LoginViewModel from "./LoginViewModel.js"; import LoginViewModel from "./LoginViewModel.js";
import SessionPickerViewModel from "./SessionPickerViewModel.js"; import SessionPickerViewModel from "./SessionPickerViewModel.js";
@ -10,10 +10,10 @@ export function createNewSessionId() {
} }
export default class BrawlViewModel extends EventEmitter { export default class BrawlViewModel extends EventEmitter {
constructor({storageFactory, sessionStore, createHsApi, clock}) { constructor({storageFactory, sessionInfoStorage, createHsApi, clock}) {
super(); super();
this._storageFactory = storageFactory; this._storageFactory = storageFactory;
this._sessionStore = sessionStore; this._sessionInfoStorage = sessionInfoStorage;
this._createHsApi = createHsApi; this._createHsApi = createHsApi;
this._clock = clock; this._clock = clock;
@ -26,7 +26,7 @@ export default class BrawlViewModel extends EventEmitter {
} }
async load() { async load() {
if (await this._sessionStore.hasAnySession()) { if (await this._sessionInfoStorage.hasAnySession()) {
this._showPicker(); this._showPicker();
} else { } else {
this._showLogin(); this._showLogin();
@ -36,7 +36,7 @@ export default class BrawlViewModel extends EventEmitter {
async _showPicker() { async _showPicker() {
this._setSection(() => { this._setSection(() => {
this._sessionPickerViewModel = new SessionPickerViewModel({ this._sessionPickerViewModel = new SessionPickerViewModel({
sessionStore: this._sessionStore, sessionInfoStorage: this._sessionInfoStorage,
storageFactory: this._storageFactory, storageFactory: this._storageFactory,
sessionCallback: sessionInfo => this._onSessionPicked(sessionInfo) sessionCallback: sessionInfo => this._onSessionPicked(sessionInfo)
}); });
@ -116,7 +116,7 @@ export default class BrawlViewModel extends EventEmitter {
accessToken: loginData.access_token, accessToken: loginData.access_token,
lastUsed: this._clock.now() lastUsed: this._clock.now()
}; };
await this._sessionStore.add(sessionInfo); await this._sessionInfoStorage.add(sessionInfo);
this._loadSession(sessionInfo); this._loadSession(sessionInfo);
} else { } else {
this._showPicker(); this._showPicker();
@ -126,7 +126,7 @@ export default class BrawlViewModel extends EventEmitter {
_onSessionPicked(sessionInfo) { _onSessionPicked(sessionInfo) {
if (sessionInfo) { if (sessionInfo) {
this._loadSession(sessionInfo); this._loadSession(sessionInfo);
this._sessionStore.updateLastUsed(sessionInfo.id, this._clock.now()); this._sessionInfoStorage.updateLastUsed(sessionInfo.id, this._clock.now());
} else { } else {
this._showLogin(); this._showLogin();
} }

View File

@ -99,15 +99,15 @@ class SessionItemViewModel extends EventEmitter {
} }
export default class SessionPickerViewModel { export default class SessionPickerViewModel {
constructor({storageFactory, sessionStore, sessionCallback}) { constructor({storageFactory, sessionInfoStorage, sessionCallback}) {
this._storageFactory = storageFactory; this._storageFactory = storageFactory;
this._sessionStore = sessionStore; this._sessionInfoStorage = sessionInfoStorage;
this._sessionCallback = sessionCallback; this._sessionCallback = sessionCallback;
this._sessions = new SortedArray((s1, s2) => s1.id.localeCompare(s2.id)); this._sessions = new SortedArray((s1, s2) => s1.id.localeCompare(s2.id));
} }
async load() { async load() {
const sessions = await this._sessionStore.getAll(); const sessions = await this._sessionInfoStorage.getAll();
this._sessions.setManyUnsorted(sessions.map(s => new SessionItemViewModel(s, this))); this._sessions.setManyUnsorted(sessions.map(s => new SessionItemViewModel(s, this)));
} }
@ -119,7 +119,7 @@ export default class SessionPickerViewModel {
} }
async _exportData(id) { async _exportData(id) {
const sessionInfo = await this._sessionStore.get(id); const sessionInfo = await this._sessionInfoStorage.get(id);
const stores = await this._storageFactory.export(id); const stores = await this._storageFactory.export(id);
const data = {sessionInfo, stores}; const data = {sessionInfo, stores};
return data; return data;
@ -131,13 +131,13 @@ export default class SessionPickerViewModel {
sessionInfo.comment = `Imported on ${new Date().toLocaleString()} from id ${sessionInfo.id}.`; sessionInfo.comment = `Imported on ${new Date().toLocaleString()} from id ${sessionInfo.id}.`;
sessionInfo.id = createNewSessionId(); sessionInfo.id = createNewSessionId();
await this._storageFactory.import(sessionInfo.id, data.stores); await this._storageFactory.import(sessionInfo.id, data.stores);
await this._sessionStore.add(sessionInfo); await this._sessionInfoStorage.add(sessionInfo);
this._sessions.set(new SessionItemViewModel(sessionInfo, this)); this._sessions.set(new SessionItemViewModel(sessionInfo, this));
} }
async delete(id) { async delete(id) {
const idx = this._sessions.array.findIndex(s => s.id === id); const idx = this._sessions.array.findIndex(s => s.id === id);
await this._sessionStore.delete(id); await this._sessionInfoStorage.delete(id);
await this._storageFactory.delete(id); await this._storageFactory.delete(id);
this._sessions.remove(idx); this._sessions.remove(idx);
} }

View File

@ -3,7 +3,7 @@ import HomeServerApi from "./matrix/net/HomeServerApi.js";
import fetchRequest from "./matrix/net/fetch.js"; import fetchRequest from "./matrix/net/fetch.js";
import {Reconnector} from "./matrix/net/connection/Reconnector.js"; import {Reconnector} from "./matrix/net/connection/Reconnector.js";
import StorageFactory from "./matrix/storage/idb/create.js"; import StorageFactory from "./matrix/storage/idb/create.js";
import SessionsStore from "./matrix/sessions-store/localstorage/SessionsStore.js"; import SessionInfoStorage from "./matrix/sessioninfo/localstorage/SessionInfoStorage.js";
import BrawlViewModel from "./domain/BrawlViewModel.js"; import BrawlViewModel from "./domain/BrawlViewModel.js";
import BrawlView from "./ui/web/BrawlView.js"; import BrawlView from "./ui/web/BrawlView.js";
import DOMClock from "./ui/web/dom/Clock.js"; import DOMClock from "./ui/web/dom/Clock.js";
@ -27,7 +27,7 @@ export default async function main(container) {
const vm = new BrawlViewModel({ const vm = new BrawlViewModel({
storageFactory: new StorageFactory(), storageFactory: new StorageFactory(),
createHsApi: (homeServer, accessToken, reconnector) => new HomeServerApi({homeServer, accessToken, request, reconnector}), createHsApi: (homeServer, accessToken, reconnector) => new HomeServerApi({homeServer, accessToken, request, reconnector}),
sessionStore: new SessionsStore("brawl_sessions_v1"), sessionInfoStorage: new SessionInfoStorage("brawl_sessions_v1"),
clock: new DOMClock(), clock: new DOMClock(),
}); });
await vm.load(); await vm.load();

View File

@ -1,4 +1,4 @@
export default class SessionsStore { export default class SessionInfoStorage {
constructor(name) { constructor(name) {
this._name = name; this._name = name;
} }