Pass args to client

This commit is contained in:
Jorik Schellekens 2020-09-24 11:11:07 +01:00
parent 32c6119243
commit fc052e6fae
6 changed files with 14 additions and 7 deletions

View File

@ -36,23 +36,25 @@ const Element: LinkedClient = {
experimental: false, experimental: false,
clientId: ClientId.Element, clientId: ClientId.Element,
toUrl: (link) => { toUrl: (link) => {
const params = link.arguments.originalParams.toString();
const prefixedParams = params ? `?${params}` : '';
switch (link.kind) { switch (link.kind) {
case LinkKind.Alias: case LinkKind.Alias:
case LinkKind.RoomId: case LinkKind.RoomId:
return new URL( return new URL(
`https://app.element.io/#/room/${link.identifier}` `https://app.element.io/#/room/${link.identifier}${prefixedParams}`
); );
case LinkKind.UserId: case LinkKind.UserId:
return new URL( return new URL(
`https://app.element.io/#/user/${link.identifier}` `https://app.element.io/#/user/${link.identifier}${prefixedParams}`
); );
case LinkKind.Permalink: case LinkKind.Permalink:
return new URL( return new URL(
`https://app.element.io/#/room/${link.identifier}` `https://app.element.io/#/room/${link.identifier}${prefixedParams}`
); );
case LinkKind.GroupId: case LinkKind.GroupId:
return new URL( return new URL(
`https://app.element.io/#/group/${link.identifier}` `https://app.element.io/#/group/${link.identifier}${prefixedParams}`
); );
} }
}, },

View File

@ -34,7 +34,7 @@ export const Default: React.FC = () => (
<HomeserverOptions <HomeserverOptions
link={{ link={{
identifier: '#banter:matrix.org', identifier: '#banter:matrix.org',
arguments: { vias: [] }, arguments: { vias: [], originalParams: new URLSearchParams() },
kind: LinkKind.Alias, kind: LinkKind.Alias,
originalLink: 'This is all made up', originalLink: 'This is all made up',
}} }}

View File

@ -42,6 +42,7 @@ const userLink: SafeLink = {
identifier: '@jorik:matrix.org', identifier: '@jorik:matrix.org',
arguments: { arguments: {
vias: [], vias: [],
originalParams: new URLSearchParams(),
}, },
originalLink: 'asdfsadf', originalLink: 'asdfsadf',
}; };
@ -51,6 +52,7 @@ const roomLink: SafeLink = {
identifier: '#element-dev:matrix.org', identifier: '#element-dev:matrix.org',
arguments: { arguments: {
vias: [], vias: [],
originalParams: new URLSearchParams(),
}, },
originalLink: 'asdfsadf', originalLink: 'asdfsadf',
}; };

View File

@ -169,7 +169,7 @@ const LinkPreview: React.FC<IProps> = ({ link }: IProps) => {
link={{ link={{
kind: LinkKind.UserId, kind: LinkKind.UserId,
identifier: link.arguments.sharer, identifier: link.arguments.sharer,
arguments: { vias: [] }, arguments: { vias: [], originalParams: new URLSearchParams() },
originalLink: '', originalLink: '',
}} }}
/> />

View File

@ -92,6 +92,7 @@ export function parseArgs(args: string): Arguments {
vias: params.getAll('via'), vias: params.getAll('via'),
client: bottomExchange(params.get('client')), client: bottomExchange(params.get('client')),
sharer: bottomExchange(params.get('sharer')), sharer: bottomExchange(params.get('sharer')),
originalParams: params,
}; };
} }

View File

@ -4,6 +4,8 @@ export interface Arguments {
client?: string; client?: string;
// MXID // MXID
sharer?: string; sharer?: string;
// Original params
originalParams: URLSearchParams;
} }
export interface LinkContent { export interface LinkContent {