From 72d5011dedcfc86cda7a695fa8aeeea85fb928da Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 7 Sep 2024 07:33:39 +0000 Subject: [PATCH] Remove custom emojis from contact names --- src/Model/APContact.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 36f0b864de..5296043169 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -245,6 +245,8 @@ class APContact } } + $apcontact['name'] = self::removeCustomEmojis($apcontact['name'], JsonLD::fetchElementArray($compacted, 'as:tag') ?? []); + $apcontact['photo'] = JsonLD::fetchElement($compacted, 'as:icon', '@id'); if (is_array($apcontact['photo']) || !empty($compacted['as:icon']['as:url']['@id'])) { $apcontact['photo'] = JsonLD::fetchElement($compacted['as:icon'], 'as:url', '@id'); @@ -484,6 +486,19 @@ class APContact return DBA::selectFirst('apcontact', [], ['url' => $apcontact['url']]) ?: []; } + public static function removeCustomEmojis(string $name, array $tags): string + { + $original = $name; + foreach ($tags as $tag) { + if ($tag['@type'] != 'toot:Emoji') { + continue; + } + $name = trim(str_replace($tag['as:name'], '', $name)); + } + + return $name ?: $original; + } + /** * Fetch the number of statuses for the given owner *