feat: wrap long posts with spoilers (#873)
* Wrap LONG posts with spoilers Some ActivityPub software facilitates long form blog posts being pushed out onto timelines. Some ActivityPub software have toot lengths which are much larger than Mastodon's default of 500. This wraps spoiler tags around those statuses. * fix lint, extract consts * extract consts to separate file * fix test hopefully * Revert "fix test hopefully" This reverts commit 7d8e2671ad158b317f6f75a7dd5dacac9e12cf80. * Fix failing test * Revert "Fix failing test" This reverts commit 15b06e11589b49979ca5eb85b7fe5c7510a62ba7. * Revert "Revert "fix test hopefully"" This reverts commit d3776bc9d64dcfd209a307a0639d33cbe6ca3884. * measure text after shortening URLs
This commit is contained in:
parent
c2bd2f306a
commit
aa69e651ac
|
@ -1,6 +1,5 @@
|
||||||
import { getAccountAccessibleName } from './getAccountAccessibleName'
|
import { getAccountAccessibleName } from './getAccountAccessibleName'
|
||||||
import { POST_PRIVACY_OPTIONS } from '../_static/statuses'
|
import { POST_PRIVACY_OPTIONS } from '../_static/statuses'
|
||||||
import { htmlToPlainText } from '../_utils/htmlToPlainText'
|
|
||||||
|
|
||||||
function getNotificationText (notification, omitEmojiInDisplayNames) {
|
function getNotificationText (notification, omitEmojiInDisplayNames) {
|
||||||
if (!notification) {
|
if (!notification) {
|
||||||
|
@ -34,13 +33,13 @@ function cleanupText (text) {
|
||||||
return text.replace(/\s+/g, ' ').trim()
|
return text.replace(/\s+/g, ' ').trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAccessibleLabelForStatus (originalAccount, account, content,
|
export function getAccessibleLabelForStatus (originalAccount, account, plainTextContent,
|
||||||
timeagoFormattedDate, spoilerText, showContent,
|
timeagoFormattedDate, spoilerText, showContent,
|
||||||
reblog, notification, visibility, omitEmojiInDisplayNames,
|
reblog, notification, visibility, omitEmojiInDisplayNames,
|
||||||
disableLongAriaLabels) {
|
disableLongAriaLabels) {
|
||||||
let originalAccountDisplayName = getAccountAccessibleName(originalAccount, omitEmojiInDisplayNames)
|
let originalAccountDisplayName = getAccountAccessibleName(originalAccount, omitEmojiInDisplayNames)
|
||||||
let contentTextToShow = (showContent || !spoilerText)
|
let contentTextToShow = (showContent || !spoilerText)
|
||||||
? cleanupText(htmlToPlainText(content))
|
? cleanupText(plainTextContent)
|
||||||
: `Content warning: ${cleanupText(spoilerText)}`
|
: `Content warning: ${cleanupText(spoilerText)}`
|
||||||
let privacyText = getPrivacyText(visibility)
|
let privacyText = getPrivacyText(visibility)
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,9 @@
|
||||||
import { getAccountAccessibleName } from '../../_a11y/getAccountAccessibleName'
|
import { getAccountAccessibleName } from '../../_a11y/getAccountAccessibleName'
|
||||||
import { getAccessibleLabelForStatus } from '../../_a11y/getAccessibleLabelForStatus'
|
import { getAccessibleLabelForStatus } from '../../_a11y/getAccessibleLabelForStatus'
|
||||||
import { formatTimeagoDate } from '../../_intl/formatTimeagoDate'
|
import { formatTimeagoDate } from '../../_intl/formatTimeagoDate'
|
||||||
|
import { htmlToPlainText } from '../../_utils/htmlToPlainText'
|
||||||
|
import { measureText } from '../../_utils/measureText'
|
||||||
|
import { LONG_POST_LENGTH, LONG_POST_TEXT } from '../../_static/statuses'
|
||||||
|
|
||||||
const INPUT_TAGS = new Set(['a', 'button', 'input', 'textarea'])
|
const INPUT_TAGS = new Set(['a', 'button', 'input', 'textarea'])
|
||||||
const isUserInputElement = node => INPUT_TAGS.has(node.localName)
|
const isUserInputElement = node => INPUT_TAGS.has(node.localName)
|
||||||
|
@ -207,7 +210,12 @@
|
||||||
originalAccount: ({ originalStatus }) => originalStatus.account,
|
originalAccount: ({ originalStatus }) => originalStatus.account,
|
||||||
originalAccountId: ({ originalAccount }) => originalAccount.id,
|
originalAccountId: ({ originalAccount }) => originalAccount.id,
|
||||||
visibility: ({ originalStatus }) => originalStatus.visibility,
|
visibility: ({ originalStatus }) => originalStatus.visibility,
|
||||||
spoilerText: ({ originalStatus }) => originalStatus.spoiler_text,
|
plainTextContent: ({ content }) => htmlToPlainText(content),
|
||||||
|
plainTextContentLength: ({ plainTextContent }) => measureText(plainTextContent),
|
||||||
|
plainTextContentOverLength: ({ plainTextContentLength }) => plainTextContentLength > LONG_POST_LENGTH,
|
||||||
|
spoilerText: ({ originalStatus, plainTextContentOverLength }) => (
|
||||||
|
originalStatus.spoiler_text || (plainTextContentOverLength && LONG_POST_TEXT)
|
||||||
|
),
|
||||||
inReplyToId: ({ originalStatus }) => originalStatus.in_reply_to_id,
|
inReplyToId: ({ originalStatus }) => originalStatus.in_reply_to_id,
|
||||||
uuid: ({ $currentInstance, timelineType, timelineValue, notificationId, statusId }) => (
|
uuid: ({ $currentInstance, timelineType, timelineValue, notificationId, statusId }) => (
|
||||||
`${$currentInstance}/${timelineType}/${timelineValue}/${notificationId || ''}/${statusId}`
|
`${$currentInstance}/${timelineType}/${timelineValue}/${notificationId || ''}/${statusId}`
|
||||||
|
@ -235,9 +243,9 @@
|
||||||
createdAtDate: ({ originalStatus }) => originalStatus.created_at,
|
createdAtDate: ({ originalStatus }) => originalStatus.created_at,
|
||||||
timeagoFormattedDate: ({ createdAtDate }) => formatTimeagoDate(createdAtDate),
|
timeagoFormattedDate: ({ createdAtDate }) => formatTimeagoDate(createdAtDate),
|
||||||
reblog: ({ status }) => status.reblog,
|
reblog: ({ status }) => status.reblog,
|
||||||
ariaLabel: ({ originalAccount, account, content, timeagoFormattedDate, spoilerText,
|
ariaLabel: ({ originalAccount, account, plainTextContent, timeagoFormattedDate, spoilerText,
|
||||||
showContent, reblog, notification, visibility, $omitEmojiInDisplayNames, $disableLongAriaLabels }) => (
|
showContent, reblog, notification, visibility, $omitEmojiInDisplayNames, $disableLongAriaLabels }) => (
|
||||||
getAccessibleLabelForStatus(originalAccount, account, content,
|
getAccessibleLabelForStatus(originalAccount, account, plainTextContent,
|
||||||
timeagoFormattedDate, spoilerText, showContent,
|
timeagoFormattedDate, spoilerText, showContent,
|
||||||
reblog, notification, visibility, $omitEmojiInDisplayNames, $disableLongAriaLabels)
|
reblog, notification, visibility, $omitEmojiInDisplayNames, $disableLongAriaLabels)
|
||||||
),
|
),
|
||||||
|
|
|
@ -59,7 +59,6 @@
|
||||||
Shortcut
|
Shortcut
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
spoilerText: ({ originalStatus }) => originalStatus.spoiler_text,
|
|
||||||
emojis: ({ originalStatus }) => originalStatus.emojis,
|
emojis: ({ originalStatus }) => originalStatus.emojis,
|
||||||
massagedSpoilerText: ({ spoilerText, emojis, $autoplayGifs }) => {
|
massagedSpoilerText: ({ spoilerText, emojis, $autoplayGifs }) => {
|
||||||
spoilerText = escapeHtml(spoilerText)
|
spoilerText = escapeHtml(spoilerText)
|
||||||
|
|
|
@ -20,3 +20,6 @@ export const POST_PRIVACY_OPTIONS = [
|
||||||
icon: '#fa-envelope'
|
icon: '#fa-envelope'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export const LONG_POST_LENGTH = 1024
|
||||||
|
export const LONG_POST_TEXT = 'Long post'
|
||||||
|
|
Loading…
Reference in a new issue