Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 971ade5

Browse files
authored
Merge pull request #5386 from matrix-org/travis/element-permalink
Rebrand Riot -> Element in the permalink classes
2 parents ced58b9 + dacc7bc commit 971ade5

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

src/utils/permalinks/RiotPermalinkConstructor.js renamed to src/utils/permalinks/ElementPermalinkConstructor.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@ import PermalinkConstructor, {PermalinkParts} from "./PermalinkConstructor";
1919
/**
2020
* Generates permalinks that self-reference the running webapp
2121
*/
22-
export default class RiotPermalinkConstructor extends PermalinkConstructor {
23-
_riotUrl: string;
22+
export default class ElementPermalinkConstructor extends PermalinkConstructor {
23+
_elementUrl: string;
2424

25-
constructor(riotUrl: string) {
25+
constructor(elementUrl: string) {
2626
super();
27-
this._riotUrl = riotUrl;
27+
this._elementUrl = elementUrl;
2828

29-
if (!this._riotUrl.startsWith("http:") && !this._riotUrl.startsWith("https:")) {
30-
throw new Error("Riot prefix URL does not appear to be an HTTP(S) URL");
29+
if (!this._elementUrl.startsWith("http:") && !this._elementUrl.startsWith("https:")) {
30+
throw new Error("Element prefix URL does not appear to be an HTTP(S) URL");
3131
}
3232
}
3333

3434
forEvent(roomId: string, eventId: string, serverCandidates: string[]): string {
35-
return `${this._riotUrl}/#/room/${roomId}/${eventId}${this.encodeServerCandidates(serverCandidates)}`;
35+
return `${this._elementUrl}/#/room/${roomId}/${eventId}${this.encodeServerCandidates(serverCandidates)}`;
3636
}
3737

3838
forRoom(roomIdOrAlias: string, serverCandidates: string[]): string {
39-
return `${this._riotUrl}/#/room/${roomIdOrAlias}${this.encodeServerCandidates(serverCandidates)}`;
39+
return `${this._elementUrl}/#/room/${roomIdOrAlias}${this.encodeServerCandidates(serverCandidates)}`;
4040
}
4141

4242
forUser(userId: string): string {
43-
return `${this._riotUrl}/#/user/${userId}`;
43+
return `${this._elementUrl}/#/user/${userId}`;
4444
}
4545

4646
forGroup(groupId: string): string {
47-
return `${this._riotUrl}/#/group/${groupId}`;
47+
return `${this._elementUrl}/#/group/${groupId}`;
4848
}
4949

5050
forEntity(entityId: string): string {
@@ -58,7 +58,7 @@ export default class RiotPermalinkConstructor extends PermalinkConstructor {
5858
}
5959

6060
isPermalinkHost(testHost: string): boolean {
61-
const parsedUrl = new URL(this._riotUrl);
61+
const parsedUrl = new URL(this._elementUrl);
6262
return testHost === (parsedUrl.host || parsedUrl.hostname); // one of the hosts should match
6363
}
6464

@@ -69,13 +69,13 @@ export default class RiotPermalinkConstructor extends PermalinkConstructor {
6969

7070
// Heavily inspired by/borrowed from the matrix-bot-sdk (with permission):
7171
// https://github.com/turt2live/matrix-js-bot-sdk/blob/7c4665c9a25c2c8e0fe4e509f2616505b5b66a1c/src/Permalinks.ts#L33-L61
72-
// Adapted for Riot's URL format
72+
// Adapted for Element's URL format
7373
parsePermalink(fullUrl: string): PermalinkParts {
74-
if (!fullUrl || !fullUrl.startsWith(this._riotUrl)) {
74+
if (!fullUrl || !fullUrl.startsWith(this._elementUrl)) {
7575
throw new Error("Does not appear to be a permalink");
7676
}
7777

78-
const parts = fullUrl.substring(`${this._riotUrl}/#/`.length).split("/");
78+
const parts = fullUrl.substring(`${this._elementUrl}/#/`.length).split("/");
7979
if (parts.length < 2) { // we're expecting an entity and an ID of some kind at least
8080
throw new Error("URL is missing parts");
8181
}
@@ -100,7 +100,7 @@ export default class RiotPermalinkConstructor extends PermalinkConstructor {
100100
const eventId = secondaryParts[0];
101101
const query = secondaryParts.length > 1 ? secondaryParts[1] : "";
102102

103-
// TODO: Verify Riot works with via args
103+
// TODO: Verify Element works with via args
104104
const via = query.split("via=").filter(p => !!p);
105105

106106
return PermalinkParts.forEvent(entity, eventId, via);

src/utils/permalinks/Permalinks.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import isIp from "is-ip";
1919
import * as utils from 'matrix-js-sdk/src/utils';
2020
import SpecPermalinkConstructor, {baseUrl as matrixtoBaseUrl} from "./SpecPermalinkConstructor";
2121
import PermalinkConstructor, {PermalinkParts} from "./PermalinkConstructor";
22-
import RiotPermalinkConstructor from "./RiotPermalinkConstructor";
22+
import ElementPermalinkConstructor from "./ElementPermalinkConstructor";
2323
import matrixLinkify from "../../linkify-matrix";
2424
import SdkConfig from "../../SdkConfig";
2525

@@ -325,7 +325,7 @@ export function tryTransformPermalinkToLocalHref(permalink: string): string {
325325
return m[1];
326326
}
327327

328-
// A bit of a hack to convert permalinks of unknown origin to Riot links
328+
// A bit of a hack to convert permalinks of unknown origin to Element links
329329
try {
330330
const permalinkParts = parsePermalink(permalink);
331331
if (permalinkParts) {
@@ -357,7 +357,7 @@ export function getPrimaryPermalinkEntity(permalink: string): string {
357357
const m = permalink.match(matrixLinkify.VECTOR_URL_PATTERN);
358358
if (m) {
359359
// A bit of a hack, but it gets the job done
360-
const handler = new RiotPermalinkConstructor("http://localhost");
360+
const handler = new ElementPermalinkConstructor("http://localhost");
361361
const entityInfo = m[1].split('#').slice(1).join('#');
362362
permalinkParts = handler.parsePermalink(`http://localhost/#${entityInfo}`);
363363
}
@@ -375,20 +375,20 @@ export function getPrimaryPermalinkEntity(permalink: string): string {
375375
}
376376

377377
function getPermalinkConstructor(): PermalinkConstructor {
378-
const riotPrefix = SdkConfig.get()['permalinkPrefix'];
379-
if (riotPrefix && riotPrefix !== matrixtoBaseUrl) {
380-
return new RiotPermalinkConstructor(riotPrefix);
378+
const elementPrefix = SdkConfig.get()['permalinkPrefix'];
379+
if (elementPrefix && elementPrefix !== matrixtoBaseUrl) {
380+
return new ElementPermalinkConstructor(elementPrefix);
381381
}
382382

383383
return new SpecPermalinkConstructor();
384384
}
385385

386386
export function parsePermalink(fullUrl: string): PermalinkParts {
387-
const riotPrefix = SdkConfig.get()['permalinkPrefix'];
387+
const elementPrefix = SdkConfig.get()['permalinkPrefix'];
388388
if (fullUrl.startsWith(matrixtoBaseUrl)) {
389389
return new SpecPermalinkConstructor().parsePermalink(fullUrl);
390-
} else if (riotPrefix && fullUrl.startsWith(riotPrefix)) {
391-
return new RiotPermalinkConstructor(riotPrefix).parsePermalink(fullUrl);
390+
} else if (elementPrefix && fullUrl.startsWith(elementPrefix)) {
391+
return new ElementPermalinkConstructor(elementPrefix).parsePermalink(fullUrl);
392392
}
393393

394394
return null; // not a permalink we can handle

0 commit comments

Comments
 (0)