|
|
|
@ -0,0 +1,270 @@
|
|
|
|
|
<article id={elementId}
|
|
|
|
|
class={className}
|
|
|
|
|
tabindex="0"
|
|
|
|
|
aria-posinset={index + 1}
|
|
|
|
|
aria-setsize={length}
|
|
|
|
|
aria-label={ariaLabel}
|
|
|
|
|
style="background: url({avatarHeader}"
|
|
|
|
|
on:recalculateHeight
|
|
|
|
|
ref:article
|
|
|
|
|
>
|
|
|
|
|
<div class="meet-content">
|
|
|
|
|
<StatusSidebar {...params} />
|
|
|
|
|
{#if content && (showContent || preloadHiddenContent)}
|
|
|
|
|
<StatusContent {...params} shown={showContent}/>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
<div class="meet-footer">
|
|
|
|
|
<StatusAuthorName {...params} />
|
|
|
|
|
<StatusAuthorHandle {...params} />
|
|
|
|
|
<StatusRelativeDate {...params} {...timestampParams} />
|
|
|
|
|
{#if showCard }
|
|
|
|
|
<StatusCard {...params} />
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import StatusSidebar from './StatusSidebar.html'
|
|
|
|
|
import StatusAuthorName from './StatusAuthorName.html'
|
|
|
|
|
import StatusAuthorHandle from './StatusAuthorHandle.html'
|
|
|
|
|
import StatusRelativeDate from './StatusRelativeDate.html'
|
|
|
|
|
import StatusCard from './StatusCard.html'
|
|
|
|
|
import StatusContent from './StatusContent.html'
|
|
|
|
|
import { store } from '../../_store/store'
|
|
|
|
|
import { goto } from '../../../../__sapper__/client'
|
|
|
|
|
import { registerClickDelegate } from '../../_utils/delegate'
|
|
|
|
|
import { classname } from '../../_utils/classname'
|
|
|
|
|
import { checkDomAncestors } from '../../_utils/checkDomAncestors'
|
|
|
|
|
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
|
|
|
|
|
import { getAccountAccessibleName } from '../../_a11y/getAccountAccessibleName'
|
|
|
|
|
import { getAccessibleLabelForStatus } from '../../_a11y/getAccessibleLabelForStatus'
|
|
|
|
|
import { formatTimeagoDate } from '../../_intl/formatTimeagoDate'
|
|
|
|
|
import { measureText } from '../../_utils/measureText'
|
|
|
|
|
import { LONG_POST_LENGTH, LONG_POST_TEXT } from '../../_static/statuses'
|
|
|
|
|
import { absoluteDateFormatter } from '../../_utils/formatters'
|
|
|
|
|
import { composeNewStatusMentioning } from '../../_actions/mention'
|
|
|
|
|
import { createStatusOrNotificationUuid } from '../../_utils/createStatusOrNotificationUuid'
|
|
|
|
|
import { addEmojiTooltips } from '../../_utils/addEmojiTooltips'
|
|
|
|
|
import { formatIntl } from '../../_utils/formatIntl'
|
|
|
|
|
|
|
|
|
|
const INPUT_TAGS = new Set(['a', 'button', 'input', 'textarea', 'label'])
|
|
|
|
|
const isUserInputElement = node => INPUT_TAGS.has(node.localName)
|
|
|
|
|
const isToolbar = node => node.classList.contains('status-toolbar')
|
|
|
|
|
const isStatusArticle = node => node.classList.contains('status-article')
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
oncreate () {
|
|
|
|
|
const { elementId, showContent } = this.get()
|
|
|
|
|
const { disableTapOnStatus } = this.store.get()
|
|
|
|
|
if (typeof window !== "undefined") {
|
|
|
|
|
if (!window.location.pathname.startsWith('/statuses/')) {
|
|
|
|
|
registerClickDelegate(this, elementId, (e) => this.onClickOrKeydown(e))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!showContent) {
|
|
|
|
|
scheduleIdleTask(() => {
|
|
|
|
|
// Perf optimization: lazily load the StatusContent when the user is idle so that
|
|
|
|
|
// it's fast when they click the "show more" button
|
|
|
|
|
this.set({ preloadHiddenContent: true })
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
scheduleIdleTask(() => addEmojiTooltips(this.refs.article))
|
|
|
|
|
},
|
|
|
|
|
components: {
|
|
|
|
|
StatusSidebar,
|
|
|
|
|
StatusAuthorName,
|
|
|
|
|
StatusAuthorHandle,
|
|
|
|
|
StatusRelativeDate,
|
|
|
|
|
StatusContent,
|
|
|
|
|
StatusCard
|
|
|
|
|
},
|
|
|
|
|
data: () => ({
|
|
|
|
|
notification: undefined,
|
|
|
|
|
replyVisibility: undefined,
|
|
|
|
|
preloadHiddenContent: false,
|
|
|
|
|
enableShortcuts: null
|
|
|
|
|
}),
|
|
|
|
|
store: () => store,
|
|
|
|
|
methods: {
|
|
|
|
|
onClickOrKeydown (e) {
|
|
|
|
|
const { type, keyCode, target } = e
|
|
|
|
|
|
|
|
|
|
const isClick = type === 'click'
|
|
|
|
|
const isEnter = type === 'keydown' && keyCode === 13
|
|
|
|
|
if (!isClick && !isEnter) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if (checkDomAncestors(target, isUserInputElement, isStatusArticle)) {
|
|
|
|
|
// this element or any ancestors up to the status-article element is
|
|
|
|
|
// a user input element
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if (checkDomAncestors(target, isToolbar, isStatusArticle)) {
|
|
|
|
|
// this element or any of its ancestors is the toolbar
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.open()
|
|
|
|
|
return true
|
|
|
|
|
},
|
|
|
|
|
open () {
|
|
|
|
|
const { originalStatusId } = this.get()
|
|
|
|
|
goto(`/statuses/${originalStatusId}`)
|
|
|
|
|
},
|
|
|
|
|
openAuthorProfile () {
|
|
|
|
|
const { accountForShortcut } = this.get()
|
|
|
|
|
goto(`/accounts/${accountForShortcut.id}`)
|
|
|
|
|
},
|
|
|
|
|
async mentionAuthor () {
|
|
|
|
|
const { accountForShortcut } = this.get()
|
|
|
|
|
await composeNewStatusMentioning(accountForShortcut)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
originalStatus: ({ status }) => status.reblog ? status.reblog : status,
|
|
|
|
|
originalStatusId: ({ originalStatus }) => originalStatus.id,
|
|
|
|
|
statusId: ({ status }) => status.id,
|
|
|
|
|
notificationId: ({ notification }) => notification && notification.id,
|
|
|
|
|
account: ({ notification, status }) => (
|
|
|
|
|
(notification && notification.account) || status.account
|
|
|
|
|
),
|
|
|
|
|
accountId: ({ account }) => account.id,
|
|
|
|
|
avatarHeader: ({ account }) => account.header,
|
|
|
|
|
originalAccount: ({ originalStatus }) => originalStatus.account,
|
|
|
|
|
originalAccountId: ({ originalAccount }) => originalAccount.id,
|
|
|
|
|
accountForShortcut: ({ originalAccount, notification }) => notification ? notification.account : originalAccount,
|
|
|
|
|
visibility: ({ originalStatus }) => originalStatus.visibility,
|
|
|
|
|
plainTextContent: ({ originalStatus }) => originalStatus.plainTextContent || '',
|
|
|
|
|
plainTextContentOverLength: ({ plainTextContent }) => (
|
|
|
|
|
// measureText() is expensive, so avoid doing it when possible.
|
|
|
|
|
// Also measureText() typically only makes text shorter, not longer, so we can measure the raw length
|
|
|
|
|
// as a shortcut. (The only case where it makes text longer is with short URLs which get expanded to a longer
|
|
|
|
|
// placeholder.) This isn't 100% accurate, but we don't need perfect accuracy here because this is just
|
|
|
|
|
// to show a "long post" content warning.
|
|
|
|
|
plainTextContent.length > LONG_POST_LENGTH && measureText(plainTextContent) > LONG_POST_LENGTH
|
|
|
|
|
),
|
|
|
|
|
spoilerText: ({ originalStatus, plainTextContentOverLength }) => (
|
|
|
|
|
originalStatus.spoiler_text || (plainTextContentOverLength && LONG_POST_TEXT)
|
|
|
|
|
),
|
|
|
|
|
inReplyToId: ({ originalStatus }) => originalStatus.in_reply_to_id,
|
|
|
|
|
uuid: ({ $currentInstance, timelineType, timelineValue, notificationId, statusId }) => (
|
|
|
|
|
createStatusOrNotificationUuid($currentInstance, timelineType, timelineValue, notificationId, statusId)
|
|
|
|
|
),
|
|
|
|
|
elementId: ({ uuid }) => uuid,
|
|
|
|
|
shortcutScope: ({ elementId }) => elementId,
|
|
|
|
|
isStatusInNotification: ({ originalStatusId, notification }) => (
|
|
|
|
|
notification && notification.status &&
|
|
|
|
|
notification.type !== 'mention' && notification.status.id === originalStatusId
|
|
|
|
|
),
|
|
|
|
|
spoilerShown: ({ $spoilersShown, uuid }) => !!$spoilersShown[uuid],
|
|
|
|
|
replyShown: ({ $repliesShown, uuid }) => !!$repliesShown[uuid],
|
|
|
|
|
showCard: ({ originalStatus, isStatusInNotification, showMedia, $hideCards }) => (
|
|
|
|
|
!$hideCards &&
|
|
|
|
|
!isStatusInNotification &&
|
|
|
|
|
!showMedia &&
|
|
|
|
|
originalStatus.card &&
|
|
|
|
|
originalStatus.card.title
|
|
|
|
|
),
|
|
|
|
|
showPoll: ({ originalStatus }) => (
|
|
|
|
|
originalStatus.poll
|
|
|
|
|
),
|
|
|
|
|
showMedia: ({ originalStatus, isStatusInNotification }) => (
|
|
|
|
|
!isStatusInNotification &&
|
|
|
|
|
originalStatus.media_attachments &&
|
|
|
|
|
originalStatus.media_attachments.length
|
|
|
|
|
),
|
|
|
|
|
numFavs: ({ $disableFavCounts, overrideNumFavs, originalStatus }) => {
|
|
|
|
|
if ($disableFavCounts) {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
if (typeof overrideNumFavs === 'number') {
|
|
|
|
|
return overrideNumFavs
|
|
|
|
|
}
|
|
|
|
|
return originalStatus.favourites_count || 0
|
|
|
|
|
},
|
|
|
|
|
favoritesLabel: ({ $disableFavCounts, numFavs }) => {
|
|
|
|
|
if ($disableFavCounts) {
|
|
|
|
|
return 'intl.favoriteCountsHidden'
|
|
|
|
|
}
|
|
|
|
|
return formatIntl('intl.favoritedTimes', { count: numFavs })
|
|
|
|
|
},
|
|
|
|
|
originalAccountEmojis: ({ originalAccount }) => (originalAccount.emojis || []),
|
|
|
|
|
originalStatusEmojis: ({ originalStatus }) => (originalStatus.emojis || []),
|
|
|
|
|
originalAccountDisplayName: ({ originalAccount }) => (originalAccount.display_name || originalAccount.username),
|
|
|
|
|
originalAccountAccessibleName: ({ originalAccount, $omitEmojiInDisplayNames }) => {
|
|
|
|
|
return getAccountAccessibleName(originalAccount, $omitEmojiInDisplayNames)
|
|
|
|
|
},
|
|
|
|
|
createdAtDate: ({ originalStatus }) => originalStatus.created_at,
|
|
|
|
|
createdAtDateTS: ({ createdAtDate }) => new Date(createdAtDate).getTime(),
|
|
|
|
|
absoluteFormattedDate: ({ createdAtDateTS }) => absoluteDateFormatter.format(createdAtDateTS),
|
|
|
|
|
timeagoFormattedDate: ({ createdAtDateTS, $now }) => formatTimeagoDate(createdAtDateTS, $now),
|
|
|
|
|
reblog: ({ status }) => status.reblog,
|
|
|
|
|
ariaLabel: ({
|
|
|
|
|
originalAccount, account, plainTextContent, timeagoFormattedDate, spoilerText,
|
|
|
|
|
showContent, reblog, notification, visibility, $omitEmojiInDisplayNames, $disableLongAriaLabels,
|
|
|
|
|
showMedia, showPoll
|
|
|
|
|
}) => (
|
|
|
|
|
getAccessibleLabelForStatus(originalAccount, account, plainTextContent,
|
|
|
|
|
timeagoFormattedDate, spoilerText, showContent,
|
|
|
|
|
reblog, notification, visibility, $omitEmojiInDisplayNames, $disableLongAriaLabels,
|
|
|
|
|
showMedia, showPoll
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
showHeader: ({ notification, status, timelineType }) => (
|
|
|
|
|
(notification && ['reblog', 'favourite', 'poll'].includes(notification.type)) ||
|
|
|
|
|
status.reblog ||
|
|
|
|
|
timelineType === 'pinned'
|
|
|
|
|
),
|
|
|
|
|
className: ({ visibility, timelineType, $underlineLinks, $disableTapOnStatus }) => (classname(
|
|
|
|
|
'status-article',
|
|
|
|
|
'shortcut-list-item',
|
|
|
|
|
'focus-fix',
|
|
|
|
|
timelineType !== 'direct' && visibility === 'direct' && 'status-direct',
|
|
|
|
|
timelineType !== 'search' && 'status-in-timeline',
|
|
|
|
|
$underlineLinks && 'underline-links'
|
|
|
|
|
)),
|
|
|
|
|
content: ({ originalStatus }) => originalStatus.content || '',
|
|
|
|
|
showContent: ({ spoilerText, spoilerShown }) => !spoilerText || spoilerShown,
|
|
|
|
|
// These timestamp params may change every 10 seconds due to now() polling, so keep them
|
|
|
|
|
// separate from the generic `params` list to avoid costly recomputes.
|
|
|
|
|
timestampParams: ({ createdAtDate, createdAtDateTS, timeagoFormattedDate, absoluteFormattedDate }) => ({
|
|
|
|
|
createdAtDate,
|
|
|
|
|
createdAtDateTS,
|
|
|
|
|
timeagoFormattedDate,
|
|
|
|
|
absoluteFormattedDate
|
|
|
|
|
}),
|
|
|
|
|
// This params list deliberately does *not* include `spoilersShown` or `replyShown`, because these
|
|
|
|
|
// change frequently and would therefore cause costly recomputes if included here.
|
|
|
|
|
// The main goal here is to avoid typing by passing as many params as possible to child components.
|
|
|
|
|
params: ({
|
|
|
|
|
notification, notificationId, status, statusId, timelineType,
|
|
|
|
|
account, accountId, uuid, isStatusInNotification,
|
|
|
|
|
originalAccount, originalAccountId, visibility,
|
|
|
|
|
replyVisibility, spoilerText, originalStatus, originalStatusId, inReplyToId,
|
|
|
|
|
enableShortcuts, shortcutScope, originalStatusEmojis
|
|
|
|
|
}) => ({
|
|
|
|
|
notification,
|
|
|
|
|
notificationId,
|
|
|
|
|
status,
|
|
|
|
|
statusId,
|
|
|
|
|
timelineType,
|
|
|
|
|
account,
|
|
|
|
|
accountId,
|
|
|
|
|
uuid,
|
|
|
|
|
isStatusInNotification,
|
|
|
|
|
originalAccount,
|
|
|
|
|
originalAccountId,
|
|
|
|
|
visibility,
|
|
|
|
|
replyVisibility,
|
|
|
|
|
spoilerText,
|
|
|
|
|
originalStatus,
|
|
|
|
|
originalStatusId,
|
|
|
|
|
inReplyToId,
|
|
|
|
|
enableShortcuts,
|
|
|
|
|
shortcutScope,
|
|
|
|
|
originalStatusEmojis
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|