diff --git a/src/utils/permalinks/ElementPermalinkConstructor.js b/src/utils/permalinks/ElementPermalinkConstructor.js index 29f2602304..7d1096e22d 100644 --- a/src/utils/permalinks/ElementPermalinkConstructor.js +++ b/src/utils/permalinks/ElementPermalinkConstructor.js @@ -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("?"); diff --git a/src/utils/permalinks/Permalinks.js b/src/utils/permalinks/Permalinks.js index 9851bc3cb3..086abc669d 100644 --- a/src/utils/permalinks/Permalinks.js +++ b/src/utils/permalinks/Permalinks.js @@ -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 }