From 285e2f82c85a1f9a6b0ce3566a64eecb1ff73e5f Mon Sep 17 00:00:00 2001 From: KMY Date: Tue, 15 Aug 2023 18:37:24 +0900 Subject: [PATCH] Add link card preview with expanding spoiler_text --- app/javascript/mastodon/components/status.jsx | 9 ++++++--- .../features/status/components/detailed_status.jsx | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/javascript/mastodon/components/status.jsx b/app/javascript/mastodon/components/status.jsx index f8edbe163e..09d76b7741 100644 --- a/app/javascript/mastodon/components/status.jsx +++ b/app/javascript/mastodon/components/status.jsx @@ -377,7 +377,7 @@ class Status extends ImmutablePureComponent { openMedia: this.handleHotkeyOpenMedia, }; - let media, statusAvatar, prepend, rebloggedByText; + let media, isCardMediaWithSensitive, statusAvatar, prepend, rebloggedByText; if (hidden) { return ( @@ -467,6 +467,8 @@ class Status extends ImmutablePureComponent { ); } + isCardMediaWithSensitive = false; + if (pictureInPicture.get('inUse')) { media = ; } else if (status.get('media_attachments').size > 0) { @@ -550,7 +552,7 @@ class Status extends ImmutablePureComponent { ); } - } else if (status.get('spoiler_text').length === 0 && status.get('card')) { + } else if (status.get('card')) { media = ( ); + isCardMediaWithSensitive = status.get('spoiler_text').length > 0; } if (account === undefined || account === null) { @@ -611,7 +614,7 @@ class Status extends ImmutablePureComponent { onCollapsedToggle={this.handleCollapsedToggle} /> - {media} + {(!isCardMediaWithSensitive || !status.get('hidden')) && media} diff --git a/app/javascript/mastodon/features/status/components/detailed_status.jsx b/app/javascript/mastodon/features/status/components/detailed_status.jsx index 76ddf12530..70d6d4f8c3 100644 --- a/app/javascript/mastodon/features/status/components/detailed_status.jsx +++ b/app/javascript/mastodon/features/status/components/detailed_status.jsx @@ -157,6 +157,7 @@ class DetailedStatus extends ImmutablePureComponent { } let media = ''; + let isCardMediaWithSensitive = false; let applicationLink = ''; let reblogLink = ''; let reblogIcon = 'retweet'; @@ -230,8 +231,9 @@ class DetailedStatus extends ImmutablePureComponent { /> ); } - } else if (status.get('spoiler_text').length === 0) { + } else if (status.get('card')) { media = ; + isCardMediaWithSensitive = status.get('spoiler_text').length > 0; } let emojiReactionsBar = null; @@ -388,10 +390,10 @@ class DetailedStatus extends ImmutablePureComponent { onTranslate={this.handleTranslate} /> - {media} + {(!isCardMediaWithSensitive || !status.get('hidden')) && media} - + {emojiReactionsBar}