allow specifying client in url

This commit is contained in:
Bruno Windels 2020-12-07 14:05:57 +01:00
parent bc0fb89846
commit bcd1cbc1b1
3 changed files with 20 additions and 27 deletions

View File

@ -70,14 +70,19 @@ export class Link {
if (!fragment) {
return null;
}
let [linkStr, queryParams] = fragment.split("?");
let [linkStr, queryParamsStr] = fragment.split("?");
let viaServers = [];
if (queryParams) {
viaServers = queryParams.split("&")
.map(pair => pair.split("="))
let clientId = null;
if (queryParamsStr) {
const queryParams = queryParamsStr.split("&").map(pair => pair.split("="));
viaServers = queryParams
.filter(([key, value]) => key === "via")
.map(([,value]) => value);
const clientParam = queryParams.find(([key]) => key === "client");
if (clientParam) {
clientId = clientParam[1];
}
}
if (linkStr.startsWith("#/")) {
@ -91,36 +96,37 @@ export class Link {
if (matches) {
const server = matches[2];
const localPart = matches[1];
return new Link(viaServers, IdentifierKind.UserId, localPart, server);
return new Link(clientId, viaServers, IdentifierKind.UserId, localPart, server);
}
matches = ROOMALIAS_PATTERN.exec(identifier);
if (matches) {
const server = matches[2];
const localPart = matches[1];
return new Link(viaServers, IdentifierKind.RoomAlias, localPart, server, eventId);
return new Link(clientId, viaServers, IdentifierKind.RoomAlias, localPart, server, eventId);
}
matches = ROOMID_PATTERN.exec(identifier);
if (matches) {
const server = matches[2];
const localPart = matches[1];
return new Link(viaServers, IdentifierKind.RoomId, localPart, server, eventId);
return new Link(clientId, viaServers, IdentifierKind.RoomId, localPart, server, eventId);
}
matches = GROUPID_PATTERN.exec(identifier);
if (matches) {
const server = matches[2];
const localPart = matches[1];
return new Link(viaServers, IdentifierKind.GroupId, localPart, server);
return new Link(clientId, viaServers, IdentifierKind.GroupId, localPart, server);
}
return null;
}
constructor(viaServers, identifierKind, localPart, server, eventId) {
constructor(clientId, viaServers, identifierKind, localPart, server, eventId) {
const servers = [server];
servers.push(...viaServers);
this.servers = orderedUnique(servers);
this.identifierKind = identifierKind;
this.identifier = `${asPrefix(identifierKind)}${localPart}:${server}`;
this.eventId = eventId;
this.clientId = clientId;
}
get kind() {

View File

@ -34,11 +34,7 @@ class ShowLinkView extends TemplateView {
render(t, vm) {
return t.div([
t.view(new PreviewView(vm.previewViewModel)),
t.p({className: {accept: true, hidden: vm => vm.clientsViewModel}}, t.button({
className: "primary fullwidth",
onClick: () => vm.showClients()
}, vm => vm.showClientsLabel)),
t.mapView(vm => vm.clientsViewModel, childVM => childVM ? new ClientListView(childVM) : null),
t.view(new ClientListView(vm.clientsViewModel)),
t.p({className: {previewSource: true, hidden: vm => !vm.previewDomain}}, [
vm => vm.previewFailed ? `${vm.previewDomain} has not returned a preview.` : `Preview provided by ${vm.previewDomain}.`,
" ",

View File

@ -49,12 +49,13 @@ export class OpenLinkViewModel extends ViewModel {
}
async _showLink() {
const preferredClient = this.preferences.clientId ? this._clients.find(c => c.id === this.preferences.clientId) : null;
this.clientsViewModel = preferredClient ? new ClientListViewModel(this.childOptions({
const clientId = this.preferences.clientId || this._link.clientId;
const preferredClient = clientId ? this._clients.find(c => c.id === clientId) : null;
this.clientsViewModel = new ClientListViewModel(this.childOptions({
clients: this._clients,
link: this._link,
client: preferredClient,
})) : null;
}));
this.previewViewModel = new PreviewViewModel(this.childOptions({
link: this._link,
consentedServers: this.preferences.homeservers
@ -84,14 +85,4 @@ export class OpenLinkViewModel extends ViewModel {
this._showServerConsent();
this.emitChange();
}
showClients() {
if (!this.clientsViewModel) {
this.clientsViewModel = new ClientListViewModel(this.childOptions({
clients: this._clients,
link: this._link
}));
this.emitChange();
}
}
}