rename SessionContainer to Client

This commit is contained in:
Bruno Windels 2021-12-22 17:09:52 +01:00
parent b5fe65d0cc
commit fe26f48c47
12 changed files with 91 additions and 91 deletions

View file

@ -23,13 +23,13 @@ import {ViewModel} from "./ViewModel.js";
export class RootViewModel extends ViewModel {
constructor(options) {
super(options);
this._createSessionContainer = options.createSessionContainer;
this._createClient = options.createClient;
this._error = null;
this._sessionPickerViewModel = null;
this._sessionLoadViewModel = null;
this._loginViewModel = null;
this._sessionViewModel = null;
this._pendingSessionContainer = null;
this._pendingClient = null;
}
async load() {
@ -53,16 +53,16 @@ export class RootViewModel extends ViewModel {
}
} else if (sessionId) {
if (!this._sessionViewModel || this._sessionViewModel.id !== sessionId) {
// see _showLogin for where _pendingSessionContainer comes from
if (this._pendingSessionContainer && this._pendingSessionContainer.sessionId === sessionId) {
const sessionContainer = this._pendingSessionContainer;
this._pendingSessionContainer = null;
this._showSession(sessionContainer);
// see _showLogin for where _pendingClient comes from
if (this._pendingClient && this._pendingClient.sessionId === sessionId) {
const client = this._pendingClient;
this._pendingClient = null;
this._showSession(client);
} else {
// this should never happen, but we want to be sure not to leak it
if (this._pendingSessionContainer) {
this._pendingSessionContainer.dispose();
this._pendingSessionContainer = null;
if (this._pendingClient) {
this._pendingClient.dispose();
this._pendingClient = null;
}
this._showSessionLoader(sessionId);
}
@ -106,8 +106,8 @@ export class RootViewModel extends ViewModel {
this._setSection(() => {
this._loginViewModel = new LoginViewModel(this.childOptions({
defaultHomeserver: this.platform.config["defaultHomeServer"],
createSessionContainer: this._createSessionContainer,
ready: sessionContainer => {
createClient: this._createClient,
ready: client => {
// we don't want to load the session container again,
// but we also want the change of screen to go through the navigation
// so we store the session container in a temporary variable that will be
@ -116,28 +116,28 @@ export class RootViewModel extends ViewModel {
// Also, we should not call _setSection before the navigation is in the correct state,
// as url creation (e.g. in RoomTileViewModel)
// won't be using the correct navigation base path.
this._pendingSessionContainer = sessionContainer;
this.navigation.push("session", sessionContainer.sessionId);
this._pendingClient = client;
this.navigation.push("session", client.sessionId);
},
loginToken
}));
});
}
_showSession(sessionContainer) {
_showSession(client) {
this._setSection(() => {
this._sessionViewModel = new SessionViewModel(this.childOptions({sessionContainer}));
this._sessionViewModel = new SessionViewModel(this.childOptions({client}));
this._sessionViewModel.start();
});
}
_showSessionLoader(sessionId) {
const sessionContainer = this._createSessionContainer();
sessionContainer.startWithExistingSession(sessionId);
const client = this._createClient();
client.startWithExistingSession(sessionId);
this._setSection(() => {
this._sessionLoadViewModel = new SessionLoadViewModel(this.childOptions({
sessionContainer,
ready: sessionContainer => this._showSession(sessionContainer)
client,
ready: client => this._showSession(client)
}));
this._sessionLoadViewModel.start();
});

View file

@ -15,15 +15,15 @@ limitations under the License.
*/
import {AccountSetupViewModel} from "./AccountSetupViewModel.js";
import {LoadStatus} from "../matrix/SessionContainer.js";
import {LoadStatus} from "../matrix/Client.js";
import {SyncStatus} from "../matrix/Sync.js";
import {ViewModel} from "./ViewModel.js";
export class SessionLoadViewModel extends ViewModel {
constructor(options) {
super(options);
const {sessionContainer, ready, homeserver, deleteSessionOnCancel} = options;
this._sessionContainer = sessionContainer;
const {client, ready, homeserver, deleteSessionOnCancel} = options;
this._client = client;
this._ready = ready;
this._homeserver = homeserver;
this._deleteSessionOnCancel = deleteSessionOnCancel;
@ -41,16 +41,16 @@ export class SessionLoadViewModel extends ViewModel {
try {
this._loading = true;
this.emitChange("loading");
this._waitHandle = this._sessionContainer.loadStatus.waitFor(s => {
this._waitHandle = this._client.loadStatus.waitFor(s => {
if (s === LoadStatus.AccountSetup) {
this._accountSetupViewModel = new AccountSetupViewModel(this._sessionContainer.accountSetup);
this._accountSetupViewModel = new AccountSetupViewModel(this._client.accountSetup);
} else {
this._accountSetupViewModel = undefined;
}
this.emitChange("loadLabel");
// wait for initial sync, but not catchup sync
const isCatchupSync = s === LoadStatus.FirstSync &&
this._sessionContainer.sync.status.get() === SyncStatus.CatchupSync;
this._client.sync.status.get() === SyncStatus.CatchupSync;
return isCatchupSync ||
s === LoadStatus.LoginFailed ||
s === LoadStatus.Error ||
@ -67,15 +67,15 @@ export class SessionLoadViewModel extends ViewModel {
// much like we will once you are in the app. Probably a good idea
// did it finish or get stuck at LoginFailed or Error?
const loadStatus = this._sessionContainer.loadStatus.get();
const loadError = this._sessionContainer.loadError;
const loadStatus = this._client.loadStatus.get();
const loadError = this._client.loadError;
if (loadStatus === LoadStatus.FirstSync || loadStatus === LoadStatus.Ready) {
const sessionContainer = this._sessionContainer;
const client = this._client;
// session container is ready,
// don't dispose it anymore when
// we get disposed
this._sessionContainer = null;
this._ready(sessionContainer);
this._client = null;
this._ready(client);
}
if (loadError) {
console.error("session load error", loadError);
@ -85,16 +85,16 @@ export class SessionLoadViewModel extends ViewModel {
console.error("error thrown during session load", err.stack);
} finally {
this._loading = false;
// loadLabel in case of sc.loadError also gets updated through this
// loadLabel in case of client.loadError also gets updated through this
this.emitChange("loading");
}
}
dispose() {
if (this._sessionContainer) {
this._sessionContainer.dispose();
this._sessionContainer = null;
if (this._client) {
this._client.dispose();
this._client = null;
}
if (this._waitHandle) {
// rejects with AbortError
@ -105,23 +105,23 @@ export class SessionLoadViewModel extends ViewModel {
// to show a spinner or not
get loading() {
const sc = this._sessionContainer;
if (sc && sc.loadStatus.get() === LoadStatus.AccountSetup) {
const client = this._client;
if (client && client.loadStatus.get() === LoadStatus.AccountSetup) {
return false;
}
return this._loading;
}
get loadLabel() {
const sc = this._sessionContainer;
const client = this._client;
const error = this._getError();
if (error || (sc && sc.loadStatus.get() === LoadStatus.Error)) {
if (error || (client && client.loadStatus.get() === LoadStatus.Error)) {
return `Something went wrong: ${error && error.message}.`;
}
// Statuses related to login are handled by respective login view models
if (sc) {
switch (sc.loadStatus.get()) {
if (client) {
switch (client.loadStatus.get()) {
case LoadStatus.QueryAccount:
return `Querying account encryption setup…`;
case LoadStatus.AccountSetup:
@ -133,7 +133,7 @@ export class SessionLoadViewModel extends ViewModel {
case LoadStatus.FirstSync:
return `Getting your conversations from the server…`;
default:
return this._sessionContainer.loadStatus.get();
return this._client.loadStatus.get();
}
}
@ -141,7 +141,7 @@ export class SessionLoadViewModel extends ViewModel {
}
_getError() {
return this._error || this._sessionContainer?.loadError;
return this._error || this._client?.loadError;
}
get hasError() {
@ -154,7 +154,7 @@ export class SessionLoadViewModel extends ViewModel {
}
async logout() {
await this._sessionContainer.logout();
await this._client.logout();
this.navigation.push("session", true);
}

View file

@ -15,18 +15,18 @@ limitations under the License.
*/
import {ViewModel} from "../ViewModel.js";
import {LoginFailure} from "../../matrix/SessionContainer.js";
import {LoginFailure} from "../../matrix/Client.js";
export class CompleteSSOLoginViewModel extends ViewModel {
constructor(options) {
super(options);
const {
loginToken,
sessionContainer,
client,
attemptLogin,
} = options;
this._loginToken = loginToken;
this._sessionContainer = sessionContainer;
this._client = client;
this._attemptLogin = attemptLogin;
this._errorMessage = "";
this.performSSOLoginCompletion();
@ -46,7 +46,7 @@ export class CompleteSSOLoginViewModel extends ViewModel {
const homeserver = await this.platform.settingsStorage.getString("sso_ongoing_login_homeserver");
let loginOptions;
try {
loginOptions = await this._sessionContainer.queryLogin(homeserver).result;
loginOptions = await this._client.queryLogin(homeserver).result;
}
catch (err) {
this._showError(err.message);

View file

@ -18,17 +18,17 @@ import {ViewModel} from "../ViewModel.js";
import {PasswordLoginViewModel} from "./PasswordLoginViewModel.js";
import {StartSSOLoginViewModel} from "./StartSSOLoginViewModel.js";
import {CompleteSSOLoginViewModel} from "./CompleteSSOLoginViewModel.js";
import {LoadStatus} from "../../matrix/SessionContainer.js";
import {LoadStatus} from "../../matrix/Client.js";
import {SessionLoadViewModel} from "../SessionLoadViewModel.js";
export class LoginViewModel extends ViewModel {
constructor(options) {
super(options);
const {ready, defaultHomeserver, createSessionContainer, loginToken} = options;
this._createSessionContainer = createSessionContainer;
const {ready, defaultHomeserver, createClient, loginToken} = options;
this._createClient = createClient;
this._ready = ready;
this._loginToken = loginToken;
this._sessionContainer = this._createSessionContainer();
this._client = this._createClient();
this._loginOptions = null;
this._passwordLoginViewModel = null;
this._startSSOLoginViewModel = null;
@ -66,7 +66,7 @@ export class LoginViewModel extends ViewModel {
this._completeSSOLoginViewModel = this.track(new CompleteSSOLoginViewModel(
this.childOptions(
{
sessionContainer: this._sessionContainer,
client: this._client,
attemptLogin: loginMethod => this.attemptLogin(loginMethod),
loginToken: this._loginToken
})));
@ -107,14 +107,14 @@ export class LoginViewModel extends ViewModel {
async attemptLogin(loginMethod) {
this._setBusy(true);
this._sessionContainer.startWithLogin(loginMethod, {inspectAccountSetup: true});
const loadStatus = this._sessionContainer.loadStatus;
this._client.startWithLogin(loginMethod, {inspectAccountSetup: true});
const loadStatus = this._client.loadStatus;
const handle = loadStatus.waitFor(status => status !== LoadStatus.Login);
await handle.promise;
this._setBusy(false);
const status = loadStatus.get();
if (status === LoadStatus.LoginFailed) {
return this._sessionContainer.loginFailure;
return this._client.loginFailure;
}
this._hideHomeserver = true;
this.emitChange("hideHomeserver");
@ -129,12 +129,12 @@ export class LoginViewModel extends ViewModel {
this._loadViewModel = this.track(
new SessionLoadViewModel(
this.childOptions({
ready: (sessionContainer) => {
ready: (client) => {
// make sure we don't delete the session in dispose when navigating away
this._sessionContainer = null;
this._ready(sessionContainer);
this._client = null;
this._ready(client);
},
sessionContainer: this._sessionContainer,
client: this._client,
homeserver: this._homeserver
})
)
@ -200,7 +200,7 @@ export class LoginViewModel extends ViewModel {
// cancel ongoing query operation, if any
this._abortQueryOperation = this.disposeTracked(this._abortQueryOperation);
try {
const queryOperation = this._sessionContainer.queryLogin(this._homeserver);
const queryOperation = this._client.queryLogin(this._homeserver);
this._abortQueryOperation = this.track(() => queryOperation.abort());
this.emitChange("isFetchingLoginOptions");
this._loginOptions = await queryOperation.result;
@ -230,10 +230,10 @@ export class LoginViewModel extends ViewModel {
dispose() {
super.dispose();
if (this._sessionContainer) {
if (this._client) {
// if we move away before we're done with initial sync
// delete the session
this._sessionContainer.deleteSession();
this._client.deleteSession();
}
}
}

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import {ViewModel} from "../ViewModel.js";
import {LoginFailure} from "../../matrix/SessionContainer.js";
import {LoginFailure} from "../../matrix/Client.js";
export class PasswordLoginViewModel extends ViewModel {
constructor(options) {

View file

@ -48,7 +48,7 @@ export class RoomViewModelObservable extends ObservableValue {
are called in that case.
*/
async initialize() {
const {session} = this._sessionViewModel._sessionContainer;
const {session} = this._sessionViewModel._client;
const statusObservable = await session.observeRoomStatus(this.id);
this.set(await this._statusToViewModel(statusObservable.get()));
this._statusSubscription = statusObservable.subscribe(async status => {

View file

@ -30,16 +30,16 @@ import {RightPanelViewModel} from "./rightpanel/RightPanelViewModel.js";
export class SessionViewModel extends ViewModel {
constructor(options) {
super(options);
const {sessionContainer} = options;
this._sessionContainer = this.track(sessionContainer);
const {client} = options;
this._client = this.track(client);
this._sessionStatusViewModel = this.track(new SessionStatusViewModel(this.childOptions({
sync: sessionContainer.sync,
reconnector: sessionContainer.reconnector,
session: sessionContainer.session,
sync: client.sync,
reconnector: client.reconnector,
session: client.session,
})));
this._leftPanelViewModel = this.track(new LeftPanelViewModel(this.childOptions({
invites: this._sessionContainer.session.invites,
rooms: this._sessionContainer.session.rooms
invites: this._client.session.invites,
rooms: this._client.session.rooms
})));
this._settingsViewModel = null;
this._roomViewModelObservable = null;
@ -88,7 +88,7 @@ export class SessionViewModel extends ViewModel {
}
get id() {
return this._sessionContainer.sessionId;
return this._client.sessionId;
}
start() {
@ -163,7 +163,7 @@ export class SessionViewModel extends ViewModel {
}
_createRoomViewModel(roomId) {
const room = this._sessionContainer.session.rooms.get(roomId);
const room = this._client.session.rooms.get(roomId);
if (room) {
const roomVM = new RoomViewModel(this.childOptions({room}));
roomVM.load();
@ -175,12 +175,12 @@ export class SessionViewModel extends ViewModel {
_createUnknownRoomViewModel(roomIdOrAlias) {
return new UnknownRoomViewModel(this.childOptions({
roomIdOrAlias,
session: this._sessionContainer.session,
session: this._client.session,
}));
}
async _createArchivedRoomViewModel(roomId) {
const room = await this._sessionContainer.session.loadArchivedRoom(roomId);
const room = await this._client.session.loadArchivedRoom(roomId);
if (room) {
const roomVM = new RoomViewModel(this.childOptions({room}));
roomVM.load();
@ -190,11 +190,11 @@ export class SessionViewModel extends ViewModel {
}
_createInviteViewModel(roomId) {
const invite = this._sessionContainer.session.invites.get(roomId);
const invite = this._client.session.invites.get(roomId);
if (invite) {
return new InviteViewModel(this.childOptions({
invite,
mediaRepository: this._sessionContainer.session.mediaRepository,
mediaRepository: this._client.session.mediaRepository,
}));
}
return null;
@ -230,7 +230,7 @@ export class SessionViewModel extends ViewModel {
}
if (settingsOpen) {
this._settingsViewModel = this.track(new SettingsViewModel(this.childOptions({
sessionContainer: this._sessionContainer,
client: this._client,
})));
this._settingsViewModel.load();
}
@ -254,7 +254,7 @@ export class SessionViewModel extends ViewModel {
_roomFromNavigation() {
const roomId = this.navigation.path.get("room")?.value;
const room = this._sessionContainer.session.rooms.get(roomId);
const room = this._client.session.rooms.get(roomId);
return room;
}

View file

@ -41,8 +41,8 @@ export class SettingsViewModel extends ViewModel {
constructor(options) {
super(options);
this._updateService = options.updateService;
const {sessionContainer} = options;
this._sessionContainer = sessionContainer;
const {client} = options;
this._client = client;
this._sessionBackupViewModel = this.track(new SessionBackupViewModel(this.childOptions({session: this._session})));
this._closeUrl = this.urlCreator.urlUntilSegment("session");
this._estimate = null;
@ -54,12 +54,12 @@ export class SettingsViewModel extends ViewModel {
}
get _session() {
return this._sessionContainer.session;
return this._client.session;
}
async logout() {
this._isLoggingOut = true;
await this._sessionContainer.logout();
await this._client.logout();
this.emitChange("isLoggingOut");
this.navigation.push("session", true);
}

View file

@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// types need to bootstrap a SessionContainer
export {SessionContainer, LoadStatus} from "./matrix/SessionContainer.js";
// types need to bootstrap a Client
export {Client, LoadStatus} from "./matrix/Client.js";
export {Session} from "./matrix/Session.js";
export {Sync} from "./matrix/Sync.js";
export {Room} from "./matrix/room/Room.js";

View file

@ -51,7 +51,7 @@ export const LoginFailure = createEnum(
"Unknown",
);
export class SessionContainer {
export class Client {
constructor({platform, olmPromise, workerPromise}) {
this._platform = platform;
this._sessionStartedByReconnector = false;

View file

@ -109,7 +109,7 @@ export class Session {
return this._sessionInfo.userId;
}
/** @internal call SessionContainer.logout instead */
/** @internal call Client.logout instead */
async logout(log = undefined) {
await this._hsApi.logout({log}).response();
}

View file

@ -16,7 +16,7 @@ limitations under the License.
*/
// import {RecordRequester, ReplayRequester} from "./matrix/net/request/replay";
import {SessionContainer} from "../../matrix/SessionContainer.js";
import {Client} from "../../matrix/Client.js";
import {RootViewModel} from "../../domain/RootViewModel.js";
import {createNavigation, createRouter} from "../../domain/navigation/index.js";
// Don't use a default export here, as we use multiple entries during legacy build,
@ -41,8 +41,8 @@ export async function main(platform) {
const workerPromise = platform.loadOlmWorker();
const vm = new RootViewModel({
createSessionContainer: () => {
return new SessionContainer({platform, olmPromise, workerPromise});
createClient: () => {
return new Client({platform, olmPromise, workerPromise});
},
platform,
// the only public interface of the router is to create urls,