From ba724f80b12085a1f8032a7b38c1ae9249cdf561 Mon Sep 17 00:00:00 2001 From: diondiondion Date: Mon, 22 Sep 2025 15:50:29 +0200 Subject: [PATCH] [Glitch] Add quote-related info to a post's `aria-label` Port e473583da0d4c183ea48482d4b9e1d3beac93f98 to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/components/status.jsx | 22 +++++++++---------- .../components/status/boost_button_utils.ts | 6 ++++- .../flavours/glitch/features/status/index.jsx | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/javascript/flavours/glitch/components/status.jsx b/app/javascript/flavours/glitch/components/status.jsx index 1ec04ac37a..a472ad394f 100644 --- a/app/javascript/flavours/glitch/components/status.jsx +++ b/app/javascript/flavours/glitch/components/status.jsx @@ -36,7 +36,12 @@ import { IconButton } from './icon_button'; const domParser = new DOMParser(); -export const textForScreenReader = (intl, status, rebloggedByText = false, expanded = false) => { +const messages = defineMessages({ + quote_noun: { id: 'status.quote_noun', defaultMessage: 'Quote', description: 'Quote as a noun' }, + quote_cancel: { id: 'status.quote.cancel', defaultMessage: 'Cancel quote' }, +}); + +export const textForScreenReader = ({intl, status, rebloggedByText = false, isQuote = false, expanded = false}) => { const displayName = status.getIn(['account', 'display_name']); const spoilerText = status.getIn(['translation', 'spoiler_text']) || status.get('spoiler_text'); @@ -44,15 +49,14 @@ export const textForScreenReader = (intl, status, rebloggedByText = false, expan const contentText = domParser.parseFromString(contentHtml, 'text/html').documentElement.textContent; const values = [ + isQuote ? intl.formatMessage(messages.quote_noun) : undefined, displayName.length === 0 ? status.getIn(['account', 'acct']).split('@')[0] : displayName, spoilerText && !expanded ? spoilerText : contentText, + !!status.get('quote') ? intl.formatMessage(messages.contains_quote) : undefined, intl.formatDate(status.get('created_at'), { hour: '2-digit', minute: '2-digit', month: 'short', day: 'numeric' }), status.getIn(['account', 'acct']), - ]; - - if (rebloggedByText) { - values.push(rebloggedByText); - } + rebloggedByText, + ].filter(val => !!val); return values.join(', '); }; @@ -73,10 +77,6 @@ export const defaultMediaVisibility = (status, settings) => { return !status.get('matched_media_filters') && (displayMedia !== 'hide_all' && !status.get('sensitive') || displayMedia === 'show_all'); }; -const messages = defineMessages({ - quote_cancel: { id: 'status.quote.cancel', defaultMessage: 'Cancel quote' }, -}); - class Status extends ImmutablePureComponent { static contextType = SensitiveMediaContext; @@ -688,7 +688,7 @@ class Status extends ImmutablePureComponent { {...selectorAttribs} tabIndex={unfocusable ? null : 0} data-featured={featured ? 'true' : null} - aria-label={textForScreenReader(intl, status, rebloggedByText, !status.get('hidden'))} + aria-label={textForScreenReader({intl, status, rebloggedByText, isQuote: isQuotedPost, expanded: !status.get('hidden')})} ref={this.handleRef} data-nosnippet={status.getIn(['account', 'noindex'], true) || undefined} > diff --git a/app/javascript/flavours/glitch/components/status/boost_button_utils.ts b/app/javascript/flavours/glitch/components/status/boost_button_utils.ts index a5745e48d1..7d004ca65d 100644 --- a/app/javascript/flavours/glitch/components/status/boost_button_utils.ts +++ b/app/javascript/flavours/glitch/components/status/boost_button_utils.ts @@ -18,7 +18,11 @@ export const messages = defineMessages({ id: 'status.all_disabled', defaultMessage: 'Boosts and quotes are disabled', }, - quote: { id: 'status.quote', defaultMessage: 'Quote' }, + quote: { + id: 'status.quote', + defaultMessage: 'Quote', + description: 'Quote as a verb (e.g. Quote this post)', + }, quote_cannot: { id: 'status.cannot_quote', defaultMessage: 'You are not allowed to quote this post', diff --git a/app/javascript/flavours/glitch/features/status/index.jsx b/app/javascript/flavours/glitch/features/status/index.jsx index 0a4df3990c..a5ef88057f 100644 --- a/app/javascript/flavours/glitch/features/status/index.jsx +++ b/app/javascript/flavours/glitch/features/status/index.jsx @@ -623,7 +623,7 @@ class Status extends ImmutablePureComponent { {ancestors} -
+