Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,30 @@ export class Link {
return `/${this.identifier}`;
}
}

static toMatrixUri(link) {
let identifier = encodeURIComponent(link.identifier.substring(1));
let isRoomid = link.identifier.substring(0, 1) === '!';
let fragmentPath;
switch (link.kind) {
case LinkKind.User:
fragmentPath = `u/${identifier}?action=chat`;
break;
case LinkKind.Room:
case LinkKind.Event:
if (isRoomid)
fragmentPath = `roomid/${identifier}`;
else
fragmentPath = `r/${identifier}`;

if (link.kind === LinkKind.Event)
fragmentPath += `/e/${encodeURIComponent(link.eventId.substring(1))}`;
fragmentPath += '?action=join';
fragmentPath += link.servers.map(server => `&via=${encodeURIComponent(server)}`).join('');
break;
case LinkKind.Group:
return;
}
return `matrix:${fragmentPath}`;
}
}
8 changes: 8 additions & 0 deletions src/open/OpenLinkViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {PreviewViewModel} from "../preview/PreviewViewModel.js";
import {ServerConsentViewModel} from "./ServerConsentViewModel.js";
import {getLabelForLinkKind} from "../Link.js";
import {orderedUnique} from "../utils/unique.js";
import {Link} from "../Link.js"

export class OpenLinkViewModel extends ViewModel {
constructor(options) {
Expand All @@ -37,6 +38,13 @@ export class OpenLinkViewModel extends ViewModel {
} else {
this._showLink();
}

this._openLink();
}

async _openLink() {
// Proactively try to open the default Matrix client of the user.
window.open(Link.toMatrixUri(this._link), '_self');
}

_showServerConsent() {
Expand Down
25 changes: 2 additions & 23 deletions src/open/clients/Fractal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

import {Maturity, Platform, LinkKind, FlathubLink} from "../types.js";
import {Link} from "../../Link.js"

/**
* Information on how to deep link to a given matrix client.
Expand All @@ -31,29 +32,7 @@ export class Fractal {

getDeepLink(platform, link) {
if (platform === Platform.Linux) {
let identifier = encodeURIComponent(link.identifier.substring(1));
let isRoomid = link.identifier.substring(0, 1) === '!';
let fragmentPath;
switch (link.kind) {
case LinkKind.User:
fragmentPath = `u/${identifier}?action=chat`;
break;
case LinkKind.Room:
case LinkKind.Event:
if (isRoomid)
fragmentPath = `roomid/${identifier}`;
else
fragmentPath = `r/${identifier}`;

if (link.kind === LinkKind.Event)
fragmentPath += `/e/${encodeURIComponent(link.eventId.substring(1))}`;
fragmentPath += '?action=join';
fragmentPath += link.servers.map(server => `&via=${encodeURIComponent(server)}`).join('');
break;
case LinkKind.Group:
return;
}
return `matrix:${fragmentPath}`;
return Link.toMatrixUri(link);
}
}

Expand Down
25 changes: 2 additions & 23 deletions src/open/clients/NeoChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
*/

import {Maturity, Platform, LinkKind, FlathubLink, style} from "../types.js";
import {Link} from "../../Link.js"

export class NeoChat {
get id() { return "neochat"; }
Expand All @@ -28,29 +29,7 @@ export class NeoChat {
getMaturity(platform) { return Maturity.Beta; }
getDeepLink(platform, link) {
if (platform === Platform.Linux || platform === Platform.Windows) {
let identifier = encodeURIComponent(link.identifier.substring(1));
let isRoomid = link.identifier.substring(0, 1) === '!';
let fragmentPath;
switch (link.kind) {
case LinkKind.User:
fragmentPath = `u/${identifier}?action=chat`;
break;
case LinkKind.Room:
case LinkKind.Event:
if (isRoomid)
fragmentPath = `roomid/${identifier}`;
else
fragmentPath = `r/${identifier}`;

if (link.kind === LinkKind.Event)
fragmentPath += `/e/${encodeURIComponent(link.eventId.substring(1))}`;
fragmentPath += '?action=join';
fragmentPath += link.servers.map(server => `&via=${encodeURIComponent(server)}`).join('');
break;
case LinkKind.Group:
return;
}
return `matrix:${fragmentPath}`;
return Link.toMatrixUri(link);
}
}
canInterceptMatrixToLinks(platform) { return false; }
Expand Down
25 changes: 2 additions & 23 deletions src/open/clients/Nheko.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

import {Maturity, Platform, LinkKind, FlathubLink, WebsiteLink, style} from "../types.js";
import {Link} from "../../Link.js"

/**
* Information on how to deep link to a given matrix client.
Expand All @@ -30,29 +31,7 @@ export class Nheko {
getMaturity(platform) { return Maturity.Beta; }
getDeepLink(platform, link) {
if (platform === Platform.Linux || platform === Platform.Windows) {
let identifier = encodeURIComponent(link.identifier.substring(1));
let isRoomid = link.identifier.substring(0, 1) === '!';
let fragmentPath;
switch (link.kind) {
case LinkKind.User:
fragmentPath = `u/${identifier}?action=chat`;
break;
case LinkKind.Room:
case LinkKind.Event:
if (isRoomid)
fragmentPath = `roomid/${identifier}`;
else
fragmentPath = `r/${identifier}`;

if (link.kind === LinkKind.Event)
fragmentPath += `/e/${encodeURIComponent(link.eventId.substring(1))}`;
fragmentPath += '?action=join';
fragmentPath += link.servers.map(server => `&via=${encodeURIComponent(server)}`).join('');
break;
case LinkKind.Group:
return;
}
return `matrix:${fragmentPath}`;
return Link.toMatrixUri(link);
}
}
canInterceptMatrixToLinks(platform) { return false; }
Expand Down