mirror of https://github.com/vector-im/riot-web
Move route splitting inside route parsing
parent
00059c49ab
commit
fd7c50f683
|
@ -75,11 +75,19 @@ export default class ElementPermalinkConstructor extends PermalinkConstructor {
|
|||
throw new Error("Does not appear to be a permalink");
|
||||
}
|
||||
|
||||
const parts = fullUrl.substring(`${this._elementUrl}/#/`.length).split("/");
|
||||
return ElementPermalinkConstructor.parseLinkParts(parts);
|
||||
const parts = fullUrl.substring(`${this._elementUrl}/#/`.length);
|
||||
return ElementPermalinkConstructor.parseAppRoute(parts);
|
||||
}
|
||||
|
||||
static parseLinkParts(parts: string[]): PermalinkParts {
|
||||
/**
|
||||
* Parses an app route (`(user|room|group)/identifer`) to a Matrix entity
|
||||
* (room, user, group).
|
||||
* @param {string} route The app route
|
||||
* @returns {PermalinkParts}
|
||||
*/
|
||||
static parseAppRoute(route: string): PermalinkParts {
|
||||
const parts = route.split("/");
|
||||
|
||||
if (parts.length < 2) { // we're expecting an entity and an ID of some kind at least
|
||||
throw new Error("URL is missing parts");
|
||||
}
|
||||
|
@ -93,10 +101,6 @@ export default class ElementPermalinkConstructor extends PermalinkConstructor {
|
|||
// Probably a group, no further parsing needed.
|
||||
return PermalinkParts.forGroup(entity);
|
||||
} else if (entityType === 'room') {
|
||||
if (parts.length === 2) {
|
||||
return PermalinkParts.forRoom(entity, []);
|
||||
}
|
||||
|
||||
// rejoin the rest because v3 events can have slashes (annoyingly)
|
||||
const eventIdAndQuery = parts.length > 2 ? parts.slice(2).join('/') : "";
|
||||
const secondaryParts = eventIdAndQuery.split("?");
|
||||
|
|
|
@ -414,8 +414,8 @@ export function parsePermalink(fullUrl: string): PermalinkParts {
|
|||
*/
|
||||
export function parseAppLocalLink(localLink: string): PermalinkParts {
|
||||
try {
|
||||
const segments = localLink.replace("#/", "").split("/");
|
||||
return ElementPermalinkConstructor.parseLinkParts(segments);
|
||||
const segments = localLink.replace("#/", "");
|
||||
return ElementPermalinkConstructor.parseAppRoute(segments);
|
||||
} catch (e) {
|
||||
// Ignore failures
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue