mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
rename SessionsStore to SessionInfoStorage
This commit is contained in:
parent
8c56ac3e4f
commit
80f7caadbe
@ -40,7 +40,7 @@ rooms should report how many messages they have queued up, and each time they se
|
||||
- put in own file
|
||||
- add waitFor (won't this leak if the promise never resolves?)
|
||||
- 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
|
||||
- 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
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Session from "../matrix/session.js";
|
||||
import Sync from "../matrix/sync.js";
|
||||
import Session from "../matrix/Session.js";
|
||||
import Sync from "../matrix/Sync.js";
|
||||
import SessionViewModel from "./session/SessionViewModel.js";
|
||||
import LoginViewModel from "./LoginViewModel.js";
|
||||
import SessionPickerViewModel from "./SessionPickerViewModel.js";
|
||||
@ -10,10 +10,10 @@ export function createNewSessionId() {
|
||||
}
|
||||
|
||||
export default class BrawlViewModel extends EventEmitter {
|
||||
constructor({storageFactory, sessionStore, createHsApi, clock}) {
|
||||
constructor({storageFactory, sessionInfoStorage, createHsApi, clock}) {
|
||||
super();
|
||||
this._storageFactory = storageFactory;
|
||||
this._sessionStore = sessionStore;
|
||||
this._sessionInfoStorage = sessionInfoStorage;
|
||||
this._createHsApi = createHsApi;
|
||||
this._clock = clock;
|
||||
|
||||
@ -26,7 +26,7 @@ export default class BrawlViewModel extends EventEmitter {
|
||||
}
|
||||
|
||||
async load() {
|
||||
if (await this._sessionStore.hasAnySession()) {
|
||||
if (await this._sessionInfoStorage.hasAnySession()) {
|
||||
this._showPicker();
|
||||
} else {
|
||||
this._showLogin();
|
||||
@ -36,7 +36,7 @@ export default class BrawlViewModel extends EventEmitter {
|
||||
async _showPicker() {
|
||||
this._setSection(() => {
|
||||
this._sessionPickerViewModel = new SessionPickerViewModel({
|
||||
sessionStore: this._sessionStore,
|
||||
sessionInfoStorage: this._sessionInfoStorage,
|
||||
storageFactory: this._storageFactory,
|
||||
sessionCallback: sessionInfo => this._onSessionPicked(sessionInfo)
|
||||
});
|
||||
@ -116,7 +116,7 @@ export default class BrawlViewModel extends EventEmitter {
|
||||
accessToken: loginData.access_token,
|
||||
lastUsed: this._clock.now()
|
||||
};
|
||||
await this._sessionStore.add(sessionInfo);
|
||||
await this._sessionInfoStorage.add(sessionInfo);
|
||||
this._loadSession(sessionInfo);
|
||||
} else {
|
||||
this._showPicker();
|
||||
@ -126,7 +126,7 @@ export default class BrawlViewModel extends EventEmitter {
|
||||
_onSessionPicked(sessionInfo) {
|
||||
if (sessionInfo) {
|
||||
this._loadSession(sessionInfo);
|
||||
this._sessionStore.updateLastUsed(sessionInfo.id, this._clock.now());
|
||||
this._sessionInfoStorage.updateLastUsed(sessionInfo.id, this._clock.now());
|
||||
} else {
|
||||
this._showLogin();
|
||||
}
|
||||
|
@ -99,15 +99,15 @@ class SessionItemViewModel extends EventEmitter {
|
||||
}
|
||||
|
||||
export default class SessionPickerViewModel {
|
||||
constructor({storageFactory, sessionStore, sessionCallback}) {
|
||||
constructor({storageFactory, sessionInfoStorage, sessionCallback}) {
|
||||
this._storageFactory = storageFactory;
|
||||
this._sessionStore = sessionStore;
|
||||
this._sessionInfoStorage = sessionInfoStorage;
|
||||
this._sessionCallback = sessionCallback;
|
||||
this._sessions = new SortedArray((s1, s2) => s1.id.localeCompare(s2.id));
|
||||
}
|
||||
|
||||
async load() {
|
||||
const sessions = await this._sessionStore.getAll();
|
||||
const sessions = await this._sessionInfoStorage.getAll();
|
||||
this._sessions.setManyUnsorted(sessions.map(s => new SessionItemViewModel(s, this)));
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ export default class SessionPickerViewModel {
|
||||
}
|
||||
|
||||
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 data = {sessionInfo, stores};
|
||||
return data;
|
||||
@ -131,13 +131,13 @@ export default class SessionPickerViewModel {
|
||||
sessionInfo.comment = `Imported on ${new Date().toLocaleString()} from id ${sessionInfo.id}.`;
|
||||
sessionInfo.id = createNewSessionId();
|
||||
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));
|
||||
}
|
||||
|
||||
async delete(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);
|
||||
this._sessions.remove(idx);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import HomeServerApi from "./matrix/net/HomeServerApi.js";
|
||||
import fetchRequest from "./matrix/net/fetch.js";
|
||||
import {Reconnector} from "./matrix/net/connection/Reconnector.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 BrawlView from "./ui/web/BrawlView.js";
|
||||
import DOMClock from "./ui/web/dom/Clock.js";
|
||||
@ -27,7 +27,7 @@ export default async function main(container) {
|
||||
const vm = new BrawlViewModel({
|
||||
storageFactory: new StorageFactory(),
|
||||
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(),
|
||||
});
|
||||
await vm.load();
|
||||
|
@ -1,4 +1,4 @@
|
||||
export default class SessionsStore {
|
||||
export default class SessionInfoStorage {
|
||||
constructor(name) {
|
||||
this._name = name;
|
||||
}
|
Loading…
Reference in New Issue
Block a user