From 0e93d7e5e3d8ce72c74cd8ec0cb79c473abeb528 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Sat, 11 Jul 2026 10:02:50 -0300 Subject: [PATCH] Normalize alt-text null checks across publishers Use an explicit `!== null` guard in the Facebook, Instagram, Threads, and Discord publishers instead of a truthy `if ($alt = ...)`, matching the Pinterest/X/Mastodon style. The truthy form dropped a literal "0" alt; the explicit check treats every non-null description uniformly. Also add the missing PHPDoc to Platform::supportsAltText(). --- app/Enums/SocialAccount/Platform.php | 4 ++++ app/Services/Social/Discord/DiscordPublisher.php | 4 +++- app/Services/Social/FacebookPublisher.php | 8 ++++++-- app/Services/Social/InstagramPublisher.php | 8 ++++++-- app/Services/Social/ThreadsPublisher.php | 8 ++++++-- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/Enums/SocialAccount/Platform.php b/app/Enums/SocialAccount/Platform.php index 25f2b743..73629c8f 100644 --- a/app/Enums/SocialAccount/Platform.php +++ b/app/Enums/SocialAccount/Platform.php @@ -149,6 +149,10 @@ public function altTextMaxLength(): ?int }; } + /** + * Whether the platform's API accepts image alt text (accessibility + * description) on published media. + */ public function supportsAltText(): bool { return $this->altTextMaxLength() !== null; diff --git a/app/Services/Social/Discord/DiscordPublisher.php b/app/Services/Social/Discord/DiscordPublisher.php index d741d01f..f4d88a60 100644 --- a/app/Services/Social/Discord/DiscordPublisher.php +++ b/app/Services/Social/Discord/DiscordPublisher.php @@ -129,7 +129,9 @@ private function sendWithMedia(string $channelId, array $payload, Collection $me $attachment = ['id' => $index, 'filename' => $filename]; - if ($alt = $item->altText()) { + $alt = $item->altText(); + + if ($alt !== null) { $attachment['description'] = mb_substr($alt, 0, Platform::Discord->altTextMaxLength()); } diff --git a/app/Services/Social/FacebookPublisher.php b/app/Services/Social/FacebookPublisher.php index 6f351b9f..6386bb1b 100644 --- a/app/Services/Social/FacebookPublisher.php +++ b/app/Services/Social/FacebookPublisher.php @@ -136,7 +136,9 @@ private function publishSingleImagePost(string $pageId, string $accessToken, ?st $payload['message'] = $content; } - if ($alt = $this->altFor($media)) { + $alt = $this->altFor($media); + + if ($alt !== null) { $payload['alt_text_custom'] = $alt; } @@ -175,7 +177,9 @@ private function publishMultiImagePost(string $pageId, string $accessToken, ?str 'access_token' => $accessToken, ]; - if ($alt = $this->altFor($media)) { + $alt = $this->altFor($media); + + if ($alt !== null) { $uploadPayload['alt_text_custom'] = $alt; } diff --git a/app/Services/Social/InstagramPublisher.php b/app/Services/Social/InstagramPublisher.php index bd751bdd..2fe669f6 100644 --- a/app/Services/Social/InstagramPublisher.php +++ b/app/Services/Social/InstagramPublisher.php @@ -89,7 +89,9 @@ private function publishSingleImage(string $instagramId, string $accessToken, ?s 'access_token' => $accessToken, ]; - if ($alt = $this->altFor($media)) { + $alt = $this->altFor($media); + + if ($alt !== null) { $params['alt_text'] = $alt; } @@ -215,7 +217,9 @@ private function publishCarousel(string $instagramId, string $accessToken, ?stri } else { $params['image_url'] = $this->cropImageForAspectRatio($media->url, $aspectRatio); - if ($alt = $this->altFor($media)) { + $alt = $this->altFor($media); + + if ($alt !== null) { $params['alt_text'] = $alt; } } diff --git a/app/Services/Social/ThreadsPublisher.php b/app/Services/Social/ThreadsPublisher.php index e5bf968b..89f87cfc 100644 --- a/app/Services/Social/ThreadsPublisher.php +++ b/app/Services/Social/ThreadsPublisher.php @@ -109,7 +109,9 @@ private function publishImagePost(string $userId, string $accessToken, ?string $ 'access_token' => $accessToken, ]; - if ($alt = $this->altFor($media)) { + $alt = $this->altFor($media); + + if ($alt !== null) { $params['alt_text'] = $alt; } @@ -193,7 +195,9 @@ private function publishCarousel(string $userId, string $accessToken, ?string $c $params['media_type'] = 'IMAGE'; $params['image_url'] = $media->url; - if ($alt = $this->altFor($media)) { + $alt = $this->altFor($media); + + if ($alt !== null) { $params['alt_text'] = $alt; } }