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

View File

@ -34,11 +34,7 @@ class ShowLinkView extends TemplateView {
render(t, vm) { render(t, vm) {
return t.div([ return t.div([
t.view(new PreviewView(vm.previewViewModel)), t.view(new PreviewView(vm.previewViewModel)),
t.p({className: {accept: true, hidden: vm => vm.clientsViewModel}}, t.button({ t.view(new ClientListView(vm.clientsViewModel)),
className: "primary fullwidth",
onClick: () => vm.showClients()
}, vm => vm.showClientsLabel)),
t.mapView(vm => vm.clientsViewModel, childVM => childVM ? new ClientListView(childVM) : null),
t.p({className: {previewSource: true, hidden: vm => !vm.previewDomain}}, [ t.p({className: {previewSource: true, hidden: vm => !vm.previewDomain}}, [
vm => vm.previewFailed ? `${vm.previewDomain} has not returned a preview.` : `Preview provided by ${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() { async _showLink() {
const preferredClient = this.preferences.clientId ? this._clients.find(c => c.id === this.preferences.clientId) : null; const clientId = this.preferences.clientId || this._link.clientId;
this.clientsViewModel = preferredClient ? new ClientListViewModel(this.childOptions({ const preferredClient = clientId ? this._clients.find(c => c.id === clientId) : null;
this.clientsViewModel = new ClientListViewModel(this.childOptions({
clients: this._clients, clients: this._clients,
link: this._link, link: this._link,
client: preferredClient, client: preferredClient,
})) : null; }));
this.previewViewModel = new PreviewViewModel(this.childOptions({ this.previewViewModel = new PreviewViewModel(this.childOptions({
link: this._link, link: this._link,
consentedServers: this.preferences.homeservers consentedServers: this.preferences.homeservers
@ -84,14 +85,4 @@ export class OpenLinkViewModel extends ViewModel {
this._showServerConsent(); this._showServerConsent();
this.emitChange(); this.emitChange();
} }
showClients() {
if (!this.clientsViewModel) {
this.clientsViewModel = new ClientListViewModel(this.childOptions({
clients: this._clients,
link: this._link
}));
this.emitChange();
}
}
} }