Merge pull request #918 from vector-im/madlittlemods/677-rename-urlrouter-usage-to-urlrouter

Rename `urlRouter` usage to `urlRouter` instead of `urlCreator`
This commit is contained in:
Bruno Windels 2022-11-10 17:26:40 +00:00 committed by GitHub
commit 59533a3ba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 35 additions and 36 deletions

View File

@ -85,7 +85,7 @@ async function main() {
room, room,
ownUserId: session.userId, ownUserId: session.userId,
platform, platform,
urlCreator: urlRouter, urlRouter: urlRouter,
navigation, navigation,
}); });
await vm.load(); await vm.load();

View File

@ -30,7 +30,7 @@ if (loginOptions.sso) {
// store the homeserver for when we get redirected back after the sso flow // store the homeserver for when we get redirected back after the sso flow
platform.settingsStorage.setString("sso_homeserver", loginOptions.homeserver); platform.settingsStorage.setString("sso_homeserver", loginOptions.homeserver);
// create the redirect url // create the redirect url
const callbackUrl = urlCreator.createSSOCallbackURL(); // will just return the document url without any fragment const callbackUrl = urlRouter.createSSOCallbackURL(); // will just return the document url without any fragment
const redirectUrl = sso.createRedirectUrl(callbackUrl, provider); const redirectUrl = sso.createRedirectUrl(callbackUrl, provider);
// and open it // and open it
platform.openURL(redirectUrl); platform.openURL(redirectUrl);

View File

@ -43,7 +43,7 @@ export class LogoutViewModel extends ViewModel<SegmentType, Options> {
} }
get cancelUrl(): string | undefined { get cancelUrl(): string | undefined {
return this.urlCreator.urlForSegment("session", true); return this.urlRouter.urlForSegment("session", true);
} }
async logout(): Promise<void> { async logout(): Promise<void> {

View File

@ -83,14 +83,14 @@ export class RootViewModel extends ViewModel {
} }
} }
} else if (loginToken) { } else if (loginToken) {
this.urlCreator.normalizeUrl(); this.urlRouter.normalizeUrl();
if (this.activeSection !== "login") { if (this.activeSection !== "login") {
this._showLogin(loginToken); this._showLogin(loginToken);
} }
} }
else { else {
try { try {
if (!(shouldRestoreLastUrl && this.urlCreator.tryRestoreLastUrl())) { if (!(shouldRestoreLastUrl && this.urlRouter.tryRestoreLastUrl())) {
const sessionInfos = await this.platform.sessionInfoStorage.getAll(); const sessionInfos = await this.platform.sessionInfoStorage.getAll();
if (sessionInfos.length === 0) { if (sessionInfos.length === 0) {
this.navigation.push("login"); this.navigation.push("login");

View File

@ -29,7 +29,7 @@ export class SessionLoadViewModel extends ViewModel {
this._deleteSessionOnCancel = deleteSessionOnCancel; this._deleteSessionOnCancel = deleteSessionOnCancel;
this._loading = false; this._loading = false;
this._error = null; this._error = null;
this.backUrl = this.urlCreator.urlForSegment("session", true); this.backUrl = this.urlRouter.urlForSegment("session", true);
this._accountSetupViewModel = undefined; this._accountSetupViewModel = undefined;
} }

View File

@ -38,7 +38,7 @@ class SessionItemViewModel extends ViewModel {
} }
get openUrl() { get openUrl() {
return this.urlCreator.urlForSegment("session", this.id); return this.urlRouter.urlForSegment("session", this.id);
} }
get label() { get label() {
@ -94,6 +94,6 @@ export class SessionPickerViewModel extends ViewModel {
} }
get cancelUrl() { get cancelUrl() {
return this.urlCreator.urlForSegment("login"); return this.urlRouter.urlForSegment("login");
} }
} }

View File

@ -33,7 +33,7 @@ import type {IURLRouter} from "./navigation/URLRouter";
export type Options<T extends object = SegmentType> = { export type Options<T extends object = SegmentType> = {
platform: Platform; platform: Platform;
logger: ILogger; logger: ILogger;
urlCreator: IURLRouter<T>; urlRouter: IURLRouter<T>;
navigation: Navigation<T>; navigation: Navigation<T>;
emitChange?: (params: any) => void; emitChange?: (params: any) => void;
} }
@ -137,8 +137,8 @@ export class ViewModel<N extends object = SegmentType, O extends Options<N> = Op
return this.platform.logger; return this.platform.logger;
} }
get urlCreator(): IURLRouter<N> { get urlRouter(): IURLRouter<N> {
return this._options.urlCreator; return this._options.urlRouter;
} }
get navigation(): Navigation<N> { get navigation(): Navigation<N> {

View File

@ -42,7 +42,7 @@ export class StartSSOLoginViewModel extends ViewModel{
async startSSOLogin(): Promise<void> { async startSSOLogin(): Promise<void> {
await this.platform.settingsStorage.setString("sso_ongoing_login_homeserver", this._sso!.homeserver); await this.platform.settingsStorage.setString("sso_ongoing_login_homeserver", this._sso!.homeserver);
const link = this._sso!.createSSORedirectURL(this.urlCreator.createSSOCallbackURL()); const link = this._sso!.createSSORedirectURL(this.urlRouter.createSSOCallbackURL());
this.platform.openUrl(link); this.platform.openUrl(link);
} }
} }

View File

@ -36,7 +36,7 @@ export class SessionStatusViewModel extends ViewModel {
this._reconnector = reconnector; this._reconnector = reconnector;
this._status = this._calculateState(reconnector.connectionStatus.get(), sync.status.get()); this._status = this._calculateState(reconnector.connectionStatus.get(), sync.status.get());
this._session = session; this._session = session;
this._setupKeyBackupUrl = this.urlCreator.urlForSegment("settings"); this._setupKeyBackupUrl = this.urlRouter.urlForSegment("settings");
this._dismissSecretStorage = false; this._dismissSecretStorage = false;
} }

View File

@ -22,7 +22,7 @@ export class InviteTileViewModel extends BaseTileViewModel {
super(options); super(options);
const {invite} = options; const {invite} = options;
this._invite = invite; this._invite = invite;
this._url = this.urlCreator.openRoomActionUrl(this._invite.id); this._url = this.urlRouter.openRoomActionUrl(this._invite.id);
} }
get busy() { return this._invite.accepting || this._invite.rejecting; } get busy() { return this._invite.accepting || this._invite.rejecting; }
@ -53,9 +53,9 @@ export class InviteTileViewModel extends BaseTileViewModel {
export function tests() { export function tests() {
return { return {
"test compare with timestamp": assert => { "test compare with timestamp": assert => {
const urlCreator = {openRoomActionUrl() { return "";}} const urlRouter = {openRoomActionUrl() { return "";}}
const vm1 = new InviteTileViewModel({invite: {timestamp: 500, id: "1"}, urlCreator}); const vm1 = new InviteTileViewModel({invite: {timestamp: 500, id: "1"}, urlRouter});
const vm2 = new InviteTileViewModel({invite: {timestamp: 250, id: "2"}, urlCreator}); const vm2 = new InviteTileViewModel({invite: {timestamp: 250, id: "2"}, urlRouter});
assert(vm1.compare(vm2) < 0); assert(vm1.compare(vm2) < 0);
assert(vm2.compare(vm1) > 0); assert(vm2.compare(vm1) > 0);
assert.equal(vm1.compare(vm1), 0); assert.equal(vm1.compare(vm1), 0);

View File

@ -32,8 +32,8 @@ export class LeftPanelViewModel extends ViewModel {
this._tileViewModels = this._tileViewModelsFilterMap.sortValues((a, b) => a.compare(b)); this._tileViewModels = this._tileViewModelsFilterMap.sortValues((a, b) => a.compare(b));
this._currentTileVM = null; this._currentTileVM = null;
this._setupNavigation(); this._setupNavigation();
this._closeUrl = this.urlCreator.urlForSegment("session"); this._closeUrl = this.urlRouter.urlForSegment("session");
this._settingsUrl = this.urlCreator.urlForSegment("settings"); this._settingsUrl = this.urlRouter.urlForSegment("settings");
} }
_mapTileViewModels(roomsBeingCreated, invites, rooms) { _mapTileViewModels(roomsBeingCreated, invites, rooms) {

View File

@ -23,7 +23,7 @@ export class RoomBeingCreatedTileViewModel extends BaseTileViewModel {
super(options); super(options);
const {roomBeingCreated} = options; const {roomBeingCreated} = options;
this._roomBeingCreated = roomBeingCreated; this._roomBeingCreated = roomBeingCreated;
this._url = this.urlCreator.openRoomActionUrl(this._roomBeingCreated.id); this._url = this.urlRouter.openRoomActionUrl(this._roomBeingCreated.id);
} }
get busy() { return !this._roomBeingCreated.error; } get busy() { return !this._roomBeingCreated.error; }
@ -59,9 +59,9 @@ export class RoomBeingCreatedTileViewModel extends BaseTileViewModel {
export function tests() { export function tests() {
return { return {
"test compare with names": assert => { "test compare with names": assert => {
const urlCreator = {openRoomActionUrl() { return "";}} const urlRouter = {openRoomActionUrl() { return "";}}
const vm1 = new RoomBeingCreatedTileViewModel({roomBeingCreated: {name: "A", id: "1"}, urlCreator}); const vm1 = new RoomBeingCreatedTileViewModel({roomBeingCreated: {name: "A", id: "1"}, urlRouter});
const vm2 = new RoomBeingCreatedTileViewModel({roomBeingCreated: {name: "B", id: "2"}, urlCreator}); const vm2 = new RoomBeingCreatedTileViewModel({roomBeingCreated: {name: "B", id: "2"}, urlRouter});
assert(vm1.compare(vm2) < 0); assert(vm1.compare(vm2) < 0);
assert(vm2.compare(vm1) > 0); assert(vm2.compare(vm1) > 0);
assert.equal(vm1.compare(vm1), 0); assert.equal(vm1.compare(vm1), 0);

View File

@ -22,7 +22,7 @@ export class RoomTileViewModel extends BaseTileViewModel {
super(options); super(options);
const {room} = options; const {room} = options;
this._room = room; this._room = room;
this._url = this.urlCreator.openRoomActionUrl(this._room.id); this._url = this.urlRouter.openRoomActionUrl(this._room.id);
} }
get kind() { get kind() {

View File

@ -48,7 +48,7 @@ export class MemberTileViewModel extends ViewModel {
get detailsUrl() { get detailsUrl() {
const roomId = this.navigation.path.get("room").value; const roomId = this.navigation.path.get("room").value;
return `${this.urlCreator.openRoomActionUrl(roomId)}/member/${this._member.userId}`; return `${this.urlRouter.openRoomActionUrl(roomId)}/member/${this._member.userId}`;
} }
_updatePreviousName(newName) { _updatePreviousName(newName) {

View File

@ -64,8 +64,8 @@ export class RightPanelViewModel extends ViewModel {
this._hookUpdaterToSegment("member", MemberDetailsViewModel, () => this._getMemberDetailsArguments(), this._hookUpdaterToSegment("member", MemberDetailsViewModel, () => this._getMemberDetailsArguments(),
() => { () => {
// If we fail to create the member details panel, fallback to memberlist // If we fail to create the member details panel, fallback to memberlist
const url = `${this.urlCreator.urlUntilSegment("room")}/members`; const url = `${this.urlRouter.urlUntilSegment("room")}/members`;
this.urlCreator.pushUrl(url); this.urlRouter.pushUrl(url);
} }
); );
} }

View File

@ -26,7 +26,7 @@ export class InviteViewModel extends ViewModel {
this._mediaRepository = mediaRepository; this._mediaRepository = mediaRepository;
this._onInviteChange = this._onInviteChange.bind(this); this._onInviteChange = this._onInviteChange.bind(this);
this._error = null; this._error = null;
this._closeUrl = this.urlCreator.urlUntilSegment("session"); this._closeUrl = this.urlRouter.urlUntilSegment("session");
this._invite.on("change", this._onInviteChange); this._invite.on("change", this._onInviteChange);
this._inviter = null; this._inviter = null;
if (this._invite.inviter) { if (this._invite.inviter) {

View File

@ -22,8 +22,7 @@ export class LightboxViewModel extends ViewModel {
this._eventId = options.eventId; this._eventId = options.eventId;
this._unencryptedImageUrl = null; this._unencryptedImageUrl = null;
this._decryptedImage = null; this._decryptedImage = null;
this._closeUrl = this.urlCreator.urlUntilSegment("room"); this._closeUrl = this.urlRouter.urlUntilSegment("room");
this._eventEntry = null;
this._date = null; this._date = null;
this._subscribeToEvent(options.room, options.eventId); this._subscribeToEvent(options.room, options.eventId);
} }

View File

@ -25,7 +25,7 @@ export class RoomBeingCreatedViewModel extends ViewModel {
this._roomBeingCreated = roomBeingCreated; this._roomBeingCreated = roomBeingCreated;
this._mediaRepository = mediaRepository; this._mediaRepository = mediaRepository;
this._onRoomChange = this._onRoomChange.bind(this); this._onRoomChange = this._onRoomChange.bind(this);
this._closeUrl = this.urlCreator.urlUntilSegment("session"); this._closeUrl = this.urlRouter.urlUntilSegment("session");
this._roomBeingCreated.on("change", this._onRoomChange); this._roomBeingCreated.on("change", this._onRoomChange);
} }

View File

@ -43,7 +43,7 @@ export class RoomViewModel extends ViewModel {
this._recreateComposerOnPowerLevelChange(); this._recreateComposerOnPowerLevelChange();
} }
this._clearUnreadTimout = null; this._clearUnreadTimout = null;
this._closeUrl = this.urlCreator.urlUntilSegment("session"); this._closeUrl = this.urlRouter.urlUntilSegment("session");
} }
async load() { async load() {

View File

@ -58,7 +58,7 @@ export class BaseMessageTile extends SimpleTile {
} }
get memberPanelLink() { get memberPanelLink() {
return `${this.urlCreator.urlUntilSegment("room")}/member/${this.sender}`; return `${this.urlRouter.urlUntilSegment("room")}/member/${this.sender}`;
} }
// Avatar view model contract // Avatar view model contract

View File

@ -20,7 +20,7 @@ import {BaseMediaTile} from "./BaseMediaTile.js";
export class ImageTile extends BaseMediaTile { export class ImageTile extends BaseMediaTile {
constructor(entry, options) { constructor(entry, options) {
super(entry, options); super(entry, options);
this._lightboxUrl = this.urlCreator.urlForSegments([ this._lightboxUrl = this.urlRouter.urlForSegments([
// ensure the right room is active if in grid view // ensure the right room is active if in grid view
this.navigation.segment("room", this._room.id), this.navigation.segment("room", this._room.id),
this.navigation.segment("lightbox", this._entry.id) this.navigation.segment("lightbox", this._entry.id)

View File

@ -45,7 +45,7 @@ export class SettingsViewModel extends ViewModel {
const {client} = options; const {client} = options;
this._client = client; this._client = client;
this._keyBackupViewModel = this.track(new KeyBackupViewModel(this.childOptions({session: this._session}))); this._keyBackupViewModel = this.track(new KeyBackupViewModel(this.childOptions({session: this._session})));
this._closeUrl = this.urlCreator.urlUntilSegment("session"); this._closeUrl = this.urlRouter.urlUntilSegment("session");
this._estimate = null; this._estimate = null;
this.sentImageSizeLimit = null; this.sentImageSizeLimit = null;
this.minSentImageSizeLimit = 400; this.minSentImageSizeLimit = 400;

View File

@ -41,7 +41,7 @@ export async function main(platform) {
platform, platform,
// the only public interface of the router is to create urls, // the only public interface of the router is to create urls,
// so we call it that in the view models // so we call it that in the view models
urlCreator: urlRouter, urlRouter: urlRouter,
navigation, navigation,
}); });
await vm.load(); await vm.load();