From 56ca3602ab97fabcd2b4a7ba521b39eec48612ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Mon, 22 Sep 2025 18:52:38 +0200 Subject: [PATCH] Parser fix, 3 --- .../NostrSchemeExtension/NostrSchemeParser.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Util/CommonMark/NostrSchemeExtension/NostrSchemeParser.php b/src/Util/CommonMark/NostrSchemeExtension/NostrSchemeParser.php index ce69840..b40a0b0 100644 --- a/src/Util/CommonMark/NostrSchemeExtension/NostrSchemeParser.php +++ b/src/Util/CommonMark/NostrSchemeExtension/NostrSchemeParser.php @@ -2,6 +2,7 @@ namespace App\Util\CommonMark\NostrSchemeExtension; +use App\Service\RedisCacheService; use League\CommonMark\Parser\Inline\InlineParserInterface; use League\CommonMark\Parser\Inline\InlineParserMatch; use League\CommonMark\Parser\InlineParserContext; @@ -15,8 +16,11 @@ use nostriphant\NIP19\Data\NPub; class NostrSchemeParser implements InlineParserInterface { - public function __construct() + private RedisCacheService $redisCacheService; + + public function __construct(RedisCacheService $redisCache, RedisCacheService $redisCacheService) { + $this->redisCacheService = $redisCacheService; } public function getMatchDefinition(): InlineParserMatch @@ -40,7 +44,12 @@ class NostrSchemeParser implements InlineParserInterface case 'npub': /** @var NPub $object */ $object = $decoded->data; - $inlineContext->getContainer()->appendChild(new NostrMentionLink(null, $bechEncoded)); + $profile = $this->redisCacheService->getMetadata($bechEncoded); + if (isset($profile['name'])) { + $inlineContext->getContainer()->appendChild(new NostrMentionLink($profile['name'], $bechEncoded)); + } else { + $inlineContext->getContainer()->appendChild(new NostrMentionLink(null, $bechEncoded)); + } break; case 'nprofile': /** @var NProfile $decodedProfile */ @@ -48,7 +57,7 @@ class NostrSchemeParser implements InlineParserInterface $inlineContext->getContainer()->appendChild(new NostrMentionLink(null, $decodedProfile->pubkey)); break; case 'nevent': - /** @var NEvent $decodedNpub */ + /** @var NEvent $decodedEvent */ $decodedEvent = $decoded->data; $eventId = $decodedEvent->id; $relays = $decodedEvent->relays; @@ -57,7 +66,7 @@ class NostrSchemeParser implements InlineParserInterface $inlineContext->getContainer()->appendChild(new NostrSchemeData('nevent', $bechEncoded, $relays, $author, $kind)); break; case 'naddr': - /** @var NAddr $decodedNpub */ + /** @var NAddr $decodedEvent */ $decodedEvent = $decoded->data; $identifier = $decodedEvent->identifier; $pubkey = $decodedEvent->pubkey;