Try open matrix: links before showing clients
This commit is contained in:
parent
c25a9dae4d
commit
bfcac9fafb
3 changed files with 46 additions and 13 deletions
21
src/Link.js
21
src/Link.js
|
@ -40,6 +40,16 @@ function asPrefix(identifierKind) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function asPath(identifierKind) {
|
||||||
|
switch (identifierKind) {
|
||||||
|
case IdentifierKind.RoomId: return "roomid";
|
||||||
|
case IdentifierKind.RoomAlias: return "r";
|
||||||
|
case IdentifierKind.GroupId: return null;
|
||||||
|
case IdentifierKind.UserId: return "u";
|
||||||
|
default: throw new Error("invalid id kind " + identifierKind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getWebInstanceMap(queryParams) {
|
function getWebInstanceMap(queryParams) {
|
||||||
const prefix = "web-instance[";
|
const prefix = "web-instance[";
|
||||||
const postfix = "]";
|
const postfix = "]";
|
||||||
|
@ -183,4 +193,15 @@ export class Link {
|
||||||
return `/${this.identifier}`;
|
return `/${this.identifier}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toMatrixUrl() {
|
||||||
|
const prefix = asPath(this.identifierKind);
|
||||||
|
if (!prefix) {
|
||||||
|
// Some matrix.to links aren't valid matrix: links (i.e. groups)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const identifier = this.identifier.substring(1);
|
||||||
|
const suffix = this.eventId ? `/e/${this.eventId.substring(1)}` : "";
|
||||||
|
return `matrix:${prefix}/${identifier}${suffix}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,21 +21,23 @@ import {LoadServerPolicyView} from "./policy/LoadServerPolicyView.js";
|
||||||
|
|
||||||
export class RootView extends TemplateView {
|
export class RootView extends TemplateView {
|
||||||
render(t, vm) {
|
render(t, vm) {
|
||||||
return t.div({className: "RootView"}, [
|
return t.if(vm => !vm.hidden,
|
||||||
t.mapView(vm => vm.openLinkViewModel, vm => vm ? new OpenLinkView(vm) : null),
|
vm => t.div({className: "RootView"}, [
|
||||||
t.mapView(vm => vm.createLinkViewModel, vm => vm ? new CreateLinkView(vm) : null),
|
t.mapView(vm => vm.openLinkViewModel, vm => vm ? new OpenLinkView(vm) : null),
|
||||||
t.mapView(vm => vm.loadServerPolicyViewModel, vm => vm ? new LoadServerPolicyView(vm) : null),
|
t.mapView(vm => vm.createLinkViewModel, vm => vm ? new CreateLinkView(vm) : null),
|
||||||
t.div({className: "footer"}, [
|
t.mapView(vm => vm.loadServerPolicyViewModel, vm => vm ? new LoadServerPolicyView(vm) : null),
|
||||||
t.p(t.img({src: "images/matrix-logo.svg"})),
|
t.div({className: "footer"}, [
|
||||||
t.p(["This invite uses ", externalLink(t, "https://matrix.org", "Matrix"), ", an open network for secure, decentralized communication."]),
|
t.p(t.img({src: "images/matrix-logo.svg"})),
|
||||||
t.ul({className: "links"}, [
|
t.p(["This invite uses ", externalLink(t, "https://matrix.org", "Matrix"), ", an open network for secure, decentralized communication."]),
|
||||||
t.li(externalLink(t, "https://github.com/matrix-org/matrix.to", "GitHub project")),
|
t.ul({className: "links"}, [
|
||||||
t.li(externalLink(t, "https://github.com/matrix-org/matrix.to/tree/main/src/open/clients", "Add your app")),
|
t.li(externalLink(t, "https://github.com/matrix-org/matrix.to", "GitHub project")),
|
||||||
t.li({className: {hidden: vm => !vm.hasPreferences}},
|
t.li(externalLink(t, "https://github.com/matrix-org/matrix.to/tree/main/src/open/clients", "Add your app")),
|
||||||
t.button({className: "text", onClick: () => vm.clearPreferences()}, "Clear preferences")),
|
t.li({className: {hidden: vm => !vm.hasPreferences}},
|
||||||
|
t.button({className: "text", onClick: () => vm.clearPreferences()}, "Clear preferences")),
|
||||||
|
])
|
||||||
])
|
])
|
||||||
])
|
])
|
||||||
]);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import {Platform} from "./Platform.js";
|
||||||
export class RootViewModel extends ViewModel {
|
export class RootViewModel extends ViewModel {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
|
this.hidden = false;
|
||||||
this.link = null;
|
this.link = null;
|
||||||
this.openLinkViewModel = null;
|
this.openLinkViewModel = null;
|
||||||
this.createLinkViewModel = null;
|
this.createLinkViewModel = null;
|
||||||
|
@ -58,6 +59,15 @@ export class RootViewModel extends ViewModel {
|
||||||
} else {
|
} else {
|
||||||
const oldLink = this.link;
|
const oldLink = this.link;
|
||||||
this.link = Link.parse(hash);
|
this.link = Link.parse(hash);
|
||||||
|
const matrixUrl = this.link.toMatrixUrl()
|
||||||
|
if (matrixUrl) {
|
||||||
|
this.hidden = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
this.hidden = false;
|
||||||
|
this.emitChange();
|
||||||
|
}, 1000);
|
||||||
|
this.openLink(this.link.toMatrixUrl());
|
||||||
|
}
|
||||||
this._updateChildVMs(oldLink);
|
this._updateChildVMs(oldLink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue