2021-07-04 20:19:04 -07:00
|
|
|
import { getAccountAccessibleName } from './getAccountAccessibleName.js'
|
|
|
|
import { POST_PRIVACY_OPTIONS } from '../_static/statuses.js'
|
|
|
|
import { formatIntl } from '../_utils/formatIntl.js'
|
2018-12-01 00:10:30 -08:00
|
|
|
|
2018-12-01 11:53:20 -08:00
|
|
|
function getNotificationText (notification, omitEmojiInDisplayNames) {
|
2018-11-25 01:20:58 -08:00
|
|
|
if (!notification) {
|
|
|
|
return
|
|
|
|
}
|
2019-08-03 13:49:37 -07:00
|
|
|
const notificationAccountDisplayName = getAccountAccessibleName(notification.account, omitEmojiInDisplayNames)
|
2018-11-25 01:20:58 -08:00
|
|
|
if (notification.type === 'reblog') {
|
2020-11-29 14:13:27 -08:00
|
|
|
return formatIntl('intl.accountRebloggedYou', { account: notificationAccountDisplayName })
|
2018-11-25 01:20:58 -08:00
|
|
|
} else if (notification.type === 'favourite') {
|
2020-11-29 14:13:27 -08:00
|
|
|
return formatIntl('intl.accountFavoritedYou', { account: notificationAccountDisplayName })
|
2022-12-10 10:56:12 -08:00
|
|
|
} else if (notification.type === 'update') {
|
|
|
|
return formatIntl('intl.accountEdited', { account: notificationAccountDisplayName })
|
2018-11-25 01:20:58 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 11:53:20 -08:00
|
|
|
function getPrivacyText (visibility) {
|
2019-08-03 13:49:37 -07:00
|
|
|
for (const option of POST_PRIVACY_OPTIONS) {
|
2018-11-25 01:20:58 -08:00
|
|
|
if (option.key === visibility) {
|
|
|
|
return option.label
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 11:53:20 -08:00
|
|
|
function getReblogText (reblog, account, omitEmojiInDisplayNames) {
|
2018-11-25 01:20:58 -08:00
|
|
|
if (!reblog) {
|
|
|
|
return
|
|
|
|
}
|
2019-08-03 13:49:37 -07:00
|
|
|
const accountDisplayName = getAccountAccessibleName(account, omitEmojiInDisplayNames)
|
2020-11-29 14:13:27 -08:00
|
|
|
return formatIntl('intl.rebloggedByAccount', { account: accountDisplayName })
|
2018-11-25 01:20:58 -08:00
|
|
|
}
|
|
|
|
|
2018-12-01 11:53:20 -08:00
|
|
|
function cleanupText (text) {
|
2018-12-01 00:10:30 -08:00
|
|
|
return text.replace(/\s+/g, ' ').trim()
|
|
|
|
}
|
|
|
|
|
2019-01-13 10:47:07 -08:00
|
|
|
export function getAccessibleLabelForStatus (originalAccount, account, plainTextContent,
|
2021-03-21 18:03:53 -07:00
|
|
|
shortInlineFormattedDate, spoilerText, showContent,
|
2018-12-01 11:53:20 -08:00
|
|
|
reblog, notification, visibility, omitEmojiInDisplayNames,
|
2022-12-03 06:54:03 +10:00
|
|
|
disableLongAriaLabels, showMedia, sensitive, sensitiveShown, mediaAttachments, showPoll) {
|
2019-08-03 13:49:37 -07:00
|
|
|
const originalAccountDisplayName = getAccountAccessibleName(originalAccount, omitEmojiInDisplayNames)
|
|
|
|
const contentTextToShow = (showContent || !spoilerText)
|
2019-01-13 10:47:07 -08:00
|
|
|
? cleanupText(plainTextContent)
|
2020-11-29 14:13:27 -08:00
|
|
|
: formatIntl('intl.contentWarningContent', { spoiler: cleanupText(spoilerText) })
|
|
|
|
const mediaTextToShow = showMedia && 'intl.hasMedia'
|
2022-12-03 06:54:03 +10:00
|
|
|
const mediaDescText = (showMedia && (!sensitive || sensitiveShown))
|
|
|
|
? mediaAttachments.map(media => media.description)
|
|
|
|
: []
|
2020-11-29 14:13:27 -08:00
|
|
|
const pollTextToShow = showPoll && 'intl.hasPoll'
|
2019-08-03 13:49:37 -07:00
|
|
|
const privacyText = getPrivacyText(visibility)
|
2018-12-01 11:53:20 -08:00
|
|
|
|
|
|
|
if (disableLongAriaLabels) {
|
|
|
|
// Long text can crash NVDA; allow users to shorten it like we had it before.
|
|
|
|
// https://github.com/nolanlawson/pinafore/issues/694
|
2020-11-29 14:13:27 -08:00
|
|
|
return formatIntl('intl.shortStatusLabel', { privacy: privacyText, account: originalAccountDisplayName })
|
2018-12-01 11:53:20 -08:00
|
|
|
}
|
2018-11-25 01:20:58 -08:00
|
|
|
|
2019-08-03 13:49:37 -07:00
|
|
|
const values = [
|
2018-12-01 11:53:20 -08:00
|
|
|
getNotificationText(notification, omitEmojiInDisplayNames),
|
2018-11-25 01:20:58 -08:00
|
|
|
originalAccountDisplayName,
|
2018-12-01 00:10:30 -08:00
|
|
|
contentTextToShow,
|
2020-04-25 19:03:39 -07:00
|
|
|
mediaTextToShow,
|
2022-12-03 06:54:03 +10:00
|
|
|
...mediaDescText,
|
2020-04-25 19:03:39 -07:00
|
|
|
pollTextToShow,
|
2021-03-21 18:03:53 -07:00
|
|
|
shortInlineFormattedDate,
|
2018-11-25 01:20:58 -08:00
|
|
|
`@${originalAccount.acct}`,
|
2018-12-01 11:53:20 -08:00
|
|
|
privacyText,
|
|
|
|
getReblogText(reblog, account, omitEmojiInDisplayNames)
|
2018-11-25 01:20:58 -08:00
|
|
|
].filter(Boolean)
|
|
|
|
|
|
|
|
return values.join(', ')
|
|
|
|
}
|