2018-11-25 10:20:58 +01:00
|
|
|
import { getAccountAccessibleName } from './getAccountAccessibleName'
|
|
|
|
import { POST_PRIVACY_OPTIONS } from '../_static/statuses'
|
2018-12-01 09:10:30 +01:00
|
|
|
import { htmlToPlainText } from '../_utils/htmlToPlainText'
|
|
|
|
|
2018-12-01 20:53:20 +01:00
|
|
|
function getNotificationText (notification, omitEmojiInDisplayNames) {
|
2018-11-25 10:20:58 +01:00
|
|
|
if (!notification) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let notificationAccountDisplayName = getAccountAccessibleName(notification.account, omitEmojiInDisplayNames)
|
|
|
|
if (notification.type === 'reblog') {
|
|
|
|
return `${notificationAccountDisplayName} boosted your status`
|
|
|
|
} else if (notification.type === 'favourite') {
|
|
|
|
return `${notificationAccountDisplayName} favorited your status`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 20:53:20 +01:00
|
|
|
function getPrivacyText (visibility) {
|
2018-11-25 10:20:58 +01:00
|
|
|
for (let option of POST_PRIVACY_OPTIONS) {
|
|
|
|
if (option.key === visibility) {
|
|
|
|
return option.label
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 20:53:20 +01:00
|
|
|
function getReblogText (reblog, account, omitEmojiInDisplayNames) {
|
2018-11-25 10:20:58 +01:00
|
|
|
if (!reblog) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let accountDisplayName = getAccountAccessibleName(account, omitEmojiInDisplayNames)
|
|
|
|
return `Boosted by ${accountDisplayName}`
|
|
|
|
}
|
|
|
|
|
2018-12-01 20:53:20 +01:00
|
|
|
function cleanupText (text) {
|
2018-12-01 09:10:30 +01:00
|
|
|
return text.replace(/\s+/g, ' ').trim()
|
|
|
|
}
|
|
|
|
|
2018-11-25 10:20:58 +01:00
|
|
|
export function getAccessibleLabelForStatus (originalAccount, account, content,
|
|
|
|
timeagoFormattedDate, spoilerText, showContent,
|
2018-12-01 20:53:20 +01:00
|
|
|
reblog, notification, visibility, omitEmojiInDisplayNames,
|
|
|
|
disableLongAriaLabels) {
|
2018-11-25 10:20:58 +01:00
|
|
|
let originalAccountDisplayName = getAccountAccessibleName(originalAccount, omitEmojiInDisplayNames)
|
2018-12-01 09:10:30 +01:00
|
|
|
let contentTextToShow = (showContent || !spoilerText)
|
2018-12-01 20:53:20 +01:00
|
|
|
? cleanupText(htmlToPlainText(content))
|
|
|
|
: `Content warning: ${cleanupText(spoilerText)}`
|
|
|
|
let privacyText = getPrivacyText(visibility)
|
|
|
|
|
|
|
|
if (disableLongAriaLabels) {
|
|
|
|
// Long text can crash NVDA; allow users to shorten it like we had it before.
|
|
|
|
// https://github.com/nolanlawson/pinafore/issues/694
|
|
|
|
return `${privacyText} status by ${originalAccountDisplayName}`
|
|
|
|
}
|
2018-11-25 10:20:58 +01:00
|
|
|
|
|
|
|
let values = [
|
2018-12-01 20:53:20 +01:00
|
|
|
getNotificationText(notification, omitEmojiInDisplayNames),
|
2018-11-25 10:20:58 +01:00
|
|
|
originalAccountDisplayName,
|
2018-12-01 09:10:30 +01:00
|
|
|
contentTextToShow,
|
2018-11-25 10:20:58 +01:00
|
|
|
timeagoFormattedDate,
|
|
|
|
`@${originalAccount.acct}`,
|
2018-12-01 20:53:20 +01:00
|
|
|
privacyText,
|
|
|
|
getReblogText(reblog, account, omitEmojiInDisplayNames)
|
2018-11-25 10:20:58 +01:00
|
|
|
].filter(Boolean)
|
|
|
|
|
|
|
|
return values.join(', ')
|
|
|
|
}
|