Pillify event permalinks (#10392)

This commit is contained in:
Michael Weimann 2023-03-21 10:23:20 +01:00 committed by GitHub
parent d8acdd1750
commit 96d1b74ffc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 742 additions and 144 deletions

View file

@ -28,8 +28,6 @@ import { PermalinkParts } from "./permalinks/PermalinkConstructor";
/**
* A node here is an A element with a href attribute tag.
*
* It should not be pillified if the permalink parser result contains an event Id.
*
* It should be pillified if the permalink parser returns a result and one of the following conditions match:
* - Text content equals href. This is the case when sending a plain permalink inside a message.
* - The link does not have the "linkified" class.
@ -37,9 +35,14 @@ import { PermalinkParts } from "./permalinks/PermalinkConstructor";
* Linkify will not linkify things again. There won't be a "linkified" class.
*/
const shouldBePillified = (node: Element, href: string, parts: PermalinkParts | null): boolean => {
if (!parts || parts.eventId) return false;
// permalink parser didn't return any parts
if (!parts) return false;
const textContent = node.textContent;
// event permalink with custom label
if (parts.eventId && href !== textContent) return false;
return href === textContent || !node.classList.contains("linkified");
};