Fix permalink via parsing for rooms
This adjusts the app local link parsing path to better handle `via`s in query params. Previously this path only expected them when an event ID was also present, but it's also valid to have `via`s without event IDs as well. Fixes https://github.com/vector-im/element-web/issues/16345
This commit is contained in:
parent
fd7c50f683
commit
474c029db5
3 changed files with 41 additions and 10 deletions
|
@ -92,6 +92,11 @@ export default class ElementPermalinkConstructor extends PermalinkConstructor {
|
|||
throw new Error("URL is missing parts");
|
||||
}
|
||||
|
||||
// Split optional query out of last part
|
||||
const [lastPartMaybeWithQuery] = parts.splice(-1, 1);
|
||||
const [lastPart, query = ""] = lastPartMaybeWithQuery.split("?");
|
||||
parts.push(lastPart);
|
||||
|
||||
const entityType = parts[0];
|
||||
const entity = parts[1];
|
||||
if (entityType === 'user') {
|
||||
|
@ -101,16 +106,9 @@ export default class ElementPermalinkConstructor extends PermalinkConstructor {
|
|||
// Probably a group, no further parsing needed.
|
||||
return PermalinkParts.forGroup(entity);
|
||||
} else if (entityType === 'room') {
|
||||
// rejoin the rest because v3 events can have slashes (annoyingly)
|
||||
const eventIdAndQuery = parts.length > 2 ? parts.slice(2).join('/') : "";
|
||||
const secondaryParts = eventIdAndQuery.split("?");
|
||||
|
||||
const eventId = secondaryParts[0];
|
||||
const query = secondaryParts.length > 1 ? secondaryParts[1] : "";
|
||||
|
||||
// TODO: Verify Element works with via args
|
||||
const via = query.split("via=").filter(p => !!p);
|
||||
|
||||
// Rejoin the rest because v3 events can have slashes (annoyingly)
|
||||
const eventId = parts.length > 2 ? parts.slice(2).join('/') : "";
|
||||
const via = query.split(/&?via=/).filter(p => !!p);
|
||||
return PermalinkParts.forEvent(entity, eventId, via);
|
||||
} else {
|
||||
throw new Error("Unknown entity type in permalink");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue