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; } }