2017-11-17 22:11:18 -05:00
|
|
|
import React from 'react';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import StatusPrepend from './status_prepend';
|
|
|
|
import StatusHeader from './status_header';
|
2018-03-12 20:57:28 -04:00
|
|
|
import StatusIcons from './status_icons';
|
2017-11-17 22:11:18 -05:00
|
|
|
import StatusContent from './status_content';
|
|
|
|
import StatusActionBar from './status_action_bar';
|
2018-03-27 09:40:10 -04:00
|
|
|
import AttachmentList from './attachment_list';
|
2018-10-29 09:44:04 -04:00
|
|
|
import Card from '../features/status/components/card';
|
2018-08-28 06:10:40 -04:00
|
|
|
import { injectIntl, FormattedMessage } from 'react-intl';
|
2017-11-17 22:11:18 -05:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2019-08-23 16:38:02 -04:00
|
|
|
import { MediaGallery, Video, Audio } from 'flavours/glitch/util/async-components';
|
2017-11-17 22:11:18 -05:00
|
|
|
import { HotKeys } from 'react-hotkeys';
|
2017-12-04 02:26:40 -05:00
|
|
|
import NotificationOverlayContainer from 'flavours/glitch/features/notifications/containers/overlay_container';
|
2017-11-27 16:17:12 -05:00
|
|
|
import classNames from 'classnames';
|
2018-08-28 11:16:30 -04:00
|
|
|
import { autoUnfoldCW } from 'flavours/glitch/util/content_warning';
|
2019-03-03 16:18:23 -05:00
|
|
|
import PollContainer from 'flavours/glitch/containers/poll_container';
|
2019-05-26 12:58:14 -04:00
|
|
|
import { displayMedia } from 'flavours/glitch/util/initial_state';
|
2017-11-17 22:11:18 -05:00
|
|
|
|
|
|
|
// We use the component (and not the container) since we do not want
|
|
|
|
// to use the progress bar to show download progress
|
|
|
|
import Bundle from '../features/ui/components/bundle';
|
|
|
|
|
2018-08-28 06:10:40 -04:00
|
|
|
export const textForScreenReader = (intl, status, rebloggedByText = false, expanded = false) => {
|
|
|
|
const displayName = status.getIn(['account', 'display_name']);
|
|
|
|
|
|
|
|
const values = [
|
|
|
|
displayName.length === 0 ? status.getIn(['account', 'acct']).split('@')[0] : displayName,
|
|
|
|
status.get('spoiler_text') && !expanded ? status.get('spoiler_text') : status.get('search_index').slice(status.get('spoiler_text').length),
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return values.join(', ');
|
|
|
|
};
|
|
|
|
|
2019-05-26 12:58:14 -04:00
|
|
|
export const defaultMediaVisibility = (status, settings) => {
|
|
|
|
if (!status) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object') {
|
|
|
|
status = status.get('reblog');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings.getIn(['media', 'reveal_behind_cw']) && !!status.get('spoiler_text')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (displayMedia !== 'hide_all' && !status.get('sensitive') || displayMedia === 'show_all');
|
|
|
|
}
|
|
|
|
|
2019-06-29 12:10:54 -04:00
|
|
|
export default @injectIntl
|
|
|
|
class Status extends ImmutablePureComponent {
|
2017-11-17 22:11:18 -05:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
2017-11-27 16:17:12 -05:00
|
|
|
containerId: PropTypes.string,
|
2017-11-17 22:11:18 -05:00
|
|
|
id: PropTypes.string,
|
|
|
|
status: ImmutablePropTypes.map,
|
2019-06-09 06:07:23 -04:00
|
|
|
otherAccounts: ImmutablePropTypes.list,
|
2017-11-17 22:11:18 -05:00
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
onReply: PropTypes.func,
|
|
|
|
onFavourite: PropTypes.func,
|
|
|
|
onReblog: PropTypes.func,
|
2019-04-27 13:08:38 -04:00
|
|
|
onBookmark: PropTypes.func,
|
2017-11-17 22:11:18 -05:00
|
|
|
onDelete: PropTypes.func,
|
2018-04-10 15:38:02 -04:00
|
|
|
onDirect: PropTypes.func,
|
|
|
|
onMention: PropTypes.func,
|
2017-11-17 22:11:18 -05:00
|
|
|
onPin: PropTypes.func,
|
|
|
|
onOpenMedia: PropTypes.func,
|
|
|
|
onOpenVideo: PropTypes.func,
|
|
|
|
onBlock: PropTypes.func,
|
|
|
|
onEmbed: PropTypes.func,
|
|
|
|
onHeightChange: PropTypes.func,
|
|
|
|
muted: PropTypes.bool,
|
|
|
|
collapse: PropTypes.bool,
|
|
|
|
hidden: PropTypes.bool,
|
2019-06-09 06:07:23 -04:00
|
|
|
unread: PropTypes.bool,
|
2017-11-17 22:11:18 -05:00
|
|
|
prepend: PropTypes.string,
|
|
|
|
withDismiss: PropTypes.bool,
|
|
|
|
onMoveUp: PropTypes.func,
|
|
|
|
onMoveDown: PropTypes.func,
|
2018-04-15 15:29:03 -04:00
|
|
|
getScrollPosition: PropTypes.func,
|
|
|
|
updateScrollBottom: PropTypes.func,
|
2018-03-28 13:56:46 -04:00
|
|
|
expanded: PropTypes.bool,
|
2018-08-28 06:10:40 -04:00
|
|
|
intl: PropTypes.object.isRequired,
|
2019-02-09 14:54:11 -05:00
|
|
|
cacheMediaWidth: PropTypes.func,
|
|
|
|
cachedMediaWidth: PropTypes.number,
|
2019-06-09 06:07:23 -04:00
|
|
|
onClick: PropTypes.func,
|
2017-11-17 22:11:18 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
2018-03-28 09:40:34 -04:00
|
|
|
isCollapsed: false,
|
2018-04-15 15:29:03 -04:00
|
|
|
autoCollapsed: false,
|
2018-08-28 11:16:30 -04:00
|
|
|
isExpanded: undefined,
|
2019-05-26 12:58:14 -04:00
|
|
|
showMedia: undefined,
|
|
|
|
statusId: undefined,
|
|
|
|
revealBehindCW: undefined,
|
2019-06-29 12:10:54 -04:00
|
|
|
showCard: false,
|
2019-07-12 12:53:40 -04:00
|
|
|
forceFilter: undefined,
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid checking props that are functions (and whose equality will always
|
|
|
|
// evaluate to false. See react-immutable-pure-component for usage.
|
|
|
|
updateOnProps = [
|
|
|
|
'status',
|
|
|
|
'account',
|
|
|
|
'settings',
|
|
|
|
'prepend',
|
|
|
|
'muted',
|
|
|
|
'collapse',
|
|
|
|
'notification',
|
2017-11-21 21:27:34 -05:00
|
|
|
'hidden',
|
2018-04-26 13:39:10 -04:00
|
|
|
'expanded',
|
2017-11-17 22:11:18 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
updateOnStates = [
|
|
|
|
'isExpanded',
|
2018-03-28 09:40:34 -04:00
|
|
|
'isCollapsed',
|
2019-05-26 12:58:14 -04:00
|
|
|
'showMedia',
|
2019-07-12 12:53:40 -04:00
|
|
|
'forceFilter',
|
2017-11-17 22:11:18 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
// If our settings have changed to disable collapsed statuses, then we
|
|
|
|
// need to make sure that we uncollapse every one. We do that by watching
|
|
|
|
// for changes to `settings.collapsed.enabled` in
|
2018-04-26 14:23:25 -04:00
|
|
|
// `getderivedStateFromProps()`.
|
2017-11-17 22:11:18 -05:00
|
|
|
|
|
|
|
// We also need to watch for changes on the `collapse` prop---if this
|
|
|
|
// changes to anything other than `undefined`, then we need to collapse or
|
|
|
|
// uncollapse our status accordingly.
|
2018-04-26 14:23:25 -04:00
|
|
|
static getDerivedStateFromProps(nextProps, prevState) {
|
|
|
|
let update = {};
|
|
|
|
let updated = false;
|
|
|
|
|
|
|
|
// Make sure the state mirrors props we track…
|
|
|
|
if (nextProps.collapse !== prevState.collapseProp) {
|
|
|
|
update.collapseProp = nextProps.collapse;
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
if (nextProps.expanded !== prevState.expandedProp) {
|
|
|
|
update.expandedProp = nextProps.expanded;
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update state based on new props
|
2017-11-17 22:11:18 -05:00
|
|
|
if (!nextProps.settings.getIn(['collapsed', 'enabled'])) {
|
2018-04-26 14:23:25 -04:00
|
|
|
if (prevState.isCollapsed) {
|
|
|
|
update.isCollapsed = false;
|
|
|
|
updated = true;
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
} else if (
|
2018-04-26 14:23:25 -04:00
|
|
|
nextProps.collapse !== prevState.collapseProp &&
|
2017-11-17 22:11:18 -05:00
|
|
|
nextProps.collapse !== undefined
|
2018-04-26 14:23:25 -04:00
|
|
|
) {
|
|
|
|
update.isCollapsed = nextProps.collapse;
|
|
|
|
if (nextProps.collapse) update.isExpanded = false;
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
if (nextProps.expanded !== prevState.expandedProp &&
|
2018-03-28 13:56:46 -04:00
|
|
|
nextProps.expanded !== undefined
|
2018-04-26 14:23:25 -04:00
|
|
|
) {
|
|
|
|
update.isExpanded = nextProps.expanded;
|
|
|
|
if (nextProps.expanded) update.isCollapsed = false;
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
|
2018-08-28 11:16:30 -04:00
|
|
|
if (nextProps.expanded === undefined &&
|
|
|
|
prevState.isExpanded === undefined &&
|
|
|
|
update.isExpanded === undefined
|
|
|
|
) {
|
|
|
|
const isExpanded = autoUnfoldCW(nextProps.settings, nextProps.status);
|
|
|
|
if (isExpanded !== undefined) {
|
|
|
|
update.isExpanded = isExpanded;
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 12:58:14 -04:00
|
|
|
if (nextProps.status && nextProps.status.get('id') !== prevState.statusId) {
|
|
|
|
update.showMedia = defaultMediaVisibility(nextProps.status, nextProps.settings);
|
|
|
|
update.statusId = nextProps.status.get('id');
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextProps.settings.getIn(['media', 'reveal_behind_cw']) !== prevState.revealBehindCW) {
|
|
|
|
update.revealBehindCW = nextProps.settings.getIn(['media', 'reveal_behind_cw']);
|
|
|
|
if (update.revealBehindCW) {
|
|
|
|
update.showMedia = defaultMediaVisibility(nextProps.status, nextProps.settings);
|
|
|
|
}
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
|
2018-04-26 14:23:25 -04:00
|
|
|
return updated ? update : null;
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// When mounting, we just check to see if our status should be collapsed,
|
|
|
|
// and collapse it if so. We don't need to worry about whether collapsing
|
2018-03-28 09:40:34 -04:00
|
|
|
// is enabled here, because `setCollapsed()` already takes that into
|
2017-11-17 22:11:18 -05:00
|
|
|
// account.
|
|
|
|
|
|
|
|
// The cases where a status should be collapsed are:
|
|
|
|
//
|
|
|
|
// - The `collapse` prop has been set to `true`
|
|
|
|
// - The user has decided in local settings to collapse all statuses.
|
|
|
|
// - The user has decided to collapse all notifications ('muted'
|
|
|
|
// statuses).
|
|
|
|
// - The user has decided to collapse long statuses and the status is
|
|
|
|
// over 400px (without media, or 650px with).
|
|
|
|
// - The status is a reply and the user has decided to collapse all
|
|
|
|
// replies.
|
|
|
|
// - The status contains media and the user has decided to collapse all
|
|
|
|
// statuses with media.
|
|
|
|
// - The status is a reblog the user has decided to collapse all
|
|
|
|
// statuses which are reblogs.
|
|
|
|
componentDidMount () {
|
|
|
|
const { node } = this;
|
|
|
|
const {
|
|
|
|
status,
|
|
|
|
settings,
|
|
|
|
collapse,
|
|
|
|
muted,
|
|
|
|
prepend,
|
|
|
|
} = this.props;
|
2018-05-26 13:21:02 -04:00
|
|
|
|
|
|
|
// Prevent a crash when node is undefined. Not completely sure why this
|
|
|
|
// happens, might be because status === null.
|
|
|
|
if (node === undefined) return;
|
|
|
|
|
2017-11-17 22:11:18 -05:00
|
|
|
const autoCollapseSettings = settings.getIn(['collapsed', 'auto']);
|
|
|
|
|
|
|
|
if (function () {
|
|
|
|
switch (true) {
|
2018-01-14 16:29:51 -05:00
|
|
|
case !!collapse:
|
|
|
|
case !!autoCollapseSettings.get('all'):
|
|
|
|
case autoCollapseSettings.get('notifications') && !!muted:
|
2017-11-17 22:11:18 -05:00
|
|
|
case autoCollapseSettings.get('lengthy') && node.clientHeight > (
|
|
|
|
status.get('media_attachments').size && !muted ? 650 : 400
|
|
|
|
):
|
|
|
|
case autoCollapseSettings.get('reblogs') && prepend === 'reblogged_by':
|
|
|
|
case autoCollapseSettings.get('replies') && status.get('in_reply_to_id', null) !== null:
|
2018-01-14 16:29:51 -05:00
|
|
|
case autoCollapseSettings.get('media') && !(status.get('spoiler_text').length) && !!status.get('media_attachments').size:
|
2017-11-17 22:11:18 -05:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-15 15:29:03 -04:00
|
|
|
}()) {
|
2018-03-28 09:40:34 -04:00
|
|
|
this.setCollapsed(true);
|
2018-04-15 15:29:03 -04:00
|
|
|
// Hack to fix timeline jumps on second rendering when auto-collapsing
|
|
|
|
this.setState({ autoCollapsed: true });
|
|
|
|
}
|
2019-02-09 15:24:43 -05:00
|
|
|
|
2019-06-29 12:10:54 -04:00
|
|
|
// Hack to fix timeline jumps when a preview card is fetched
|
|
|
|
this.setState({
|
|
|
|
showCard: !this.props.muted && !this.props.hidden && this.props.status && this.props.status.get('card') && this.props.settings.get('inline_preview_cards'),
|
|
|
|
});
|
2018-04-15 15:29:03 -04:00
|
|
|
}
|
|
|
|
|
2019-06-29 12:10:54 -04:00
|
|
|
// Hack to fix timeline jumps on second rendering when auto-collapsing
|
|
|
|
// or on subsequent rendering when a preview card has been fetched
|
2018-04-15 15:29:03 -04:00
|
|
|
getSnapshotBeforeUpdate (prevProps, prevState) {
|
2019-06-29 12:10:54 -04:00
|
|
|
if (!this.props.getScrollPosition) return null;
|
|
|
|
|
|
|
|
const { muted, hidden, status, settings } = this.props;
|
|
|
|
|
|
|
|
const doShowCard = !muted && !hidden && status && status.get('card') && settings.get('inline_preview_cards');
|
|
|
|
if (this.state.autoCollapsed || (doShowCard && !this.state.showCard)) {
|
|
|
|
if (doShowCard) this.setState({ showCard: true });
|
|
|
|
if (this.state.autoCollapsed) this.setState({ autoCollapsed: false });
|
2018-04-15 15:29:03 -04:00
|
|
|
return this.props.getScrollPosition();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps, prevState, snapshot) {
|
2019-06-29 12:10:54 -04:00
|
|
|
if (snapshot !== null && this.props.updateScrollBottom && this.node.offsetTop < snapshot.top) {
|
|
|
|
this.props.updateScrollBottom(snapshot.height - snapshot.top);
|
2018-04-15 15:29:03 -04:00
|
|
|
}
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
|
2019-02-09 16:08:57 -05:00
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.node && this.props.getScrollPosition) {
|
|
|
|
const position = this.props.getScrollPosition();
|
|
|
|
if (position !== null && this.node.offsetTop < position.top) {
|
|
|
|
requestAnimationFrame(() => { this.props.updateScrollBottom(position.height - position.top); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 09:40:34 -04:00
|
|
|
// `setCollapsed()` sets the value of `isCollapsed` in our state, that is,
|
|
|
|
// whether the toot is collapsed or not.
|
2017-11-17 22:11:18 -05:00
|
|
|
|
2018-03-28 09:40:34 -04:00
|
|
|
// `setCollapsed()` automatically checks for us whether toot collapsing
|
2017-11-17 22:11:18 -05:00
|
|
|
// is enabled, so we don't have to.
|
2018-03-28 09:40:34 -04:00
|
|
|
setCollapsed = (value) => {
|
|
|
|
if (this.props.settings.getIn(['collapsed', 'enabled'])) {
|
|
|
|
this.setState({ isCollapsed: value });
|
|
|
|
if (value) {
|
|
|
|
this.setExpansion(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.setState({ isCollapsed: false });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 22:11:18 -05:00
|
|
|
setExpansion = (value) => {
|
2018-03-28 09:40:34 -04:00
|
|
|
this.setState({ isExpanded: value });
|
|
|
|
if (value) {
|
|
|
|
this.setCollapsed(false);
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// `parseClick()` takes a click event and responds appropriately.
|
|
|
|
// If our status is collapsed, then clicking on it should uncollapse it.
|
|
|
|
// If `Shift` is held, then clicking on it should collapse it.
|
|
|
|
// Otherwise, we open the url handed to us in `destination`, if
|
|
|
|
// applicable.
|
|
|
|
parseClick = (e, destination) => {
|
|
|
|
const { router } = this.context;
|
|
|
|
const { status } = this.props;
|
2018-03-28 09:40:34 -04:00
|
|
|
const { isCollapsed } = this.state;
|
2017-11-17 22:11:18 -05:00
|
|
|
if (!router) return;
|
2019-06-09 06:07:23 -04:00
|
|
|
|
2018-08-10 12:00:30 -04:00
|
|
|
if (e.button === 0 && !(e.ctrlKey || e.altKey || e.metaKey)) {
|
2018-03-28 09:40:34 -04:00
|
|
|
if (isCollapsed) this.setCollapsed(false);
|
2017-11-17 22:11:18 -05:00
|
|
|
else if (e.shiftKey) {
|
2018-03-28 09:40:34 -04:00
|
|
|
this.setCollapsed(true);
|
2017-11-17 22:11:18 -05:00
|
|
|
document.getSelection().removeAllRanges();
|
2019-06-09 06:07:23 -04:00
|
|
|
} else if (this.props.onClick) {
|
|
|
|
this.props.onClick();
|
|
|
|
return;
|
2019-04-15 16:23:05 -04:00
|
|
|
} else {
|
2019-06-09 06:07:23 -04:00
|
|
|
if (destination === undefined) {
|
|
|
|
destination = `/statuses/${
|
|
|
|
status.getIn(['reblog', 'id'], status.get('id'))
|
|
|
|
}`;
|
|
|
|
}
|
2019-04-15 16:23:05 -04:00
|
|
|
let state = {...router.history.location.state};
|
|
|
|
state.mastodonBackSteps = (state.mastodonBackSteps || 0) + 1;
|
|
|
|
router.history.push(destination, state);
|
|
|
|
}
|
2017-11-17 22:11:18 -05:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 12:58:14 -04:00
|
|
|
handleToggleMediaVisibility = () => {
|
|
|
|
this.setState({ showMedia: !this.state.showMedia });
|
|
|
|
}
|
|
|
|
|
2017-11-17 22:11:18 -05:00
|
|
|
handleAccountClick = (e) => {
|
|
|
|
if (this.context.router && e.button === 0) {
|
|
|
|
const id = e.currentTarget.getAttribute('data-id');
|
|
|
|
e.preventDefault();
|
2019-04-15 16:23:05 -04:00
|
|
|
let state = {...this.context.router.history.location.state};
|
|
|
|
state.mastodonBackSteps = (state.mastodonBackSteps || 0) + 1;
|
|
|
|
this.context.router.history.push(`/accounts/${id}`, state);
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleExpandedToggle = () => {
|
2017-11-27 16:17:12 -05:00
|
|
|
if (this.props.status.get('spoiler_text')) {
|
2018-03-28 09:40:34 -04:00
|
|
|
this.setExpansion(!this.state.isExpanded);
|
2017-11-27 16:17:12 -05:00
|
|
|
}
|
2017-11-17 22:11:18 -05:00
|
|
|
};
|
|
|
|
|
2018-05-17 11:10:17 -04:00
|
|
|
handleOpenVideo = (media, startTime) => {
|
|
|
|
this.props.onOpenVideo(media, startTime);
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
|
2019-11-29 11:02:36 -05:00
|
|
|
handleHotkeyOpenMedia = e => {
|
|
|
|
const { status, onOpenMedia, onOpenVideo } = this.props;
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if (status.get('media_attachments').size > 0) {
|
|
|
|
if (status.getIn(['media_attachments', 0, 'type']) === 'audio') {
|
|
|
|
// TODO: toggle play/paused?
|
|
|
|
} else if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
|
|
|
|
onOpenVideo(status.getIn(['media_attachments', 0]), 0);
|
|
|
|
} else {
|
|
|
|
onOpenMedia(status.get('media_attachments'), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 22:11:18 -05:00
|
|
|
handleHotkeyReply = e => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.onReply(this.props.status, this.context.router.history);
|
|
|
|
}
|
|
|
|
|
2017-12-09 13:06:00 -05:00
|
|
|
handleHotkeyFavourite = (e) => {
|
2017-12-09 11:26:22 -05:00
|
|
|
this.props.onFavourite(this.props.status, e);
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyBoost = e => {
|
|
|
|
this.props.onReblog(this.props.status, e);
|
|
|
|
}
|
|
|
|
|
2019-04-27 13:08:38 -04:00
|
|
|
handleHotkeyBookmark = e => {
|
|
|
|
this.props.onBookmark(this.props.status, e);
|
|
|
|
}
|
|
|
|
|
2017-11-17 22:11:18 -05:00
|
|
|
handleHotkeyMention = e => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.onMention(this.props.status.get('account'), this.context.router.history);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyOpen = () => {
|
2019-04-15 16:23:05 -04:00
|
|
|
let state = {...this.context.router.history.location.state};
|
|
|
|
state.mastodonBackSteps = (state.mastodonBackSteps || 0) + 1;
|
|
|
|
this.context.router.history.push(`/statuses/${this.props.status.get('id')}`, state);
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyOpenProfile = () => {
|
2019-04-15 16:23:05 -04:00
|
|
|
let state = {...this.context.router.history.location.state};
|
|
|
|
state.mastodonBackSteps = (state.mastodonBackSteps || 0) + 1;
|
|
|
|
this.context.router.history.push(`/accounts/${this.props.status.getIn(['account', 'id'])}`, state);
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
|
2018-04-22 16:08:30 -04:00
|
|
|
handleHotkeyMoveUp = e => {
|
|
|
|
this.props.onMoveUp(this.props.containerId || this.props.id, e.target.getAttribute('data-featured'));
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
|
2018-04-22 16:08:30 -04:00
|
|
|
handleHotkeyMoveDown = e => {
|
|
|
|
this.props.onMoveDown(this.props.containerId || this.props.id, e.target.getAttribute('data-featured'));
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
|
2019-04-27 13:17:42 -04:00
|
|
|
handleHotkeyCollapse = e => {
|
|
|
|
if (!this.props.settings.getIn(['collapsed', 'enabled']))
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.setCollapsed(!this.state.isCollapsed);
|
|
|
|
}
|
|
|
|
|
2019-05-26 12:58:14 -04:00
|
|
|
handleHotkeyToggleSensitive = () => {
|
|
|
|
this.handleToggleMediaVisibility();
|
|
|
|
}
|
2019-04-27 13:17:42 -04:00
|
|
|
|
2019-07-12 10:01:33 -04:00
|
|
|
handleUnfilterClick = e => {
|
|
|
|
const { onUnfilter, status } = this.props;
|
2019-07-12 12:53:40 -04:00
|
|
|
onUnfilter(status.get('reblog') ? status.get('reblog') : status, () => this.setState({ forceFilter: false }));
|
2019-07-12 10:01:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
handleFilterClick = () => {
|
2019-07-12 12:53:40 -04:00
|
|
|
this.setState({ forceFilter: true });
|
2019-07-12 10:01:33 -04:00
|
|
|
}
|
|
|
|
|
2017-11-18 14:05:23 -05:00
|
|
|
handleRef = c => {
|
|
|
|
this.node = c;
|
|
|
|
}
|
|
|
|
|
2017-11-17 22:11:18 -05:00
|
|
|
renderLoadingMediaGallery () {
|
2019-08-23 16:38:02 -04:00
|
|
|
return <div className='media-gallery' style={{ height: '110px' }} />;
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
renderLoadingVideoPlayer () {
|
2019-08-23 16:38:02 -04:00
|
|
|
return <div className='video-player' style={{ height: '110px' }} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderLoadingAudioPlayer () {
|
|
|
|
return <div className='audio-player' style={{ height: '110px' }} />;
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {
|
2017-11-18 14:05:23 -05:00
|
|
|
handleRef,
|
2017-11-17 22:11:18 -05:00
|
|
|
parseClick,
|
|
|
|
setExpansion,
|
2018-03-28 09:40:34 -04:00
|
|
|
setCollapsed,
|
2017-11-17 22:11:18 -05:00
|
|
|
} = this;
|
|
|
|
const { router } = this.context;
|
|
|
|
const {
|
2018-08-28 06:10:40 -04:00
|
|
|
intl,
|
2017-11-17 22:11:18 -05:00
|
|
|
status,
|
|
|
|
account,
|
2019-06-09 06:07:23 -04:00
|
|
|
otherAccounts,
|
2017-11-17 22:11:18 -05:00
|
|
|
settings,
|
|
|
|
collapsed,
|
|
|
|
muted,
|
|
|
|
prepend,
|
|
|
|
intersectionObserverWrapper,
|
|
|
|
onOpenVideo,
|
|
|
|
onOpenMedia,
|
|
|
|
notification,
|
|
|
|
hidden,
|
2019-06-09 06:07:23 -04:00
|
|
|
unread,
|
2018-04-22 16:08:30 -04:00
|
|
|
featured,
|
2017-11-17 22:11:18 -05:00
|
|
|
...other
|
|
|
|
} = this.props;
|
2019-07-19 12:00:14 -04:00
|
|
|
const { isExpanded, isCollapsed, forceFilter } = this.state;
|
2017-11-17 22:11:18 -05:00
|
|
|
let background = null;
|
|
|
|
let attachments = null;
|
|
|
|
let media = null;
|
|
|
|
let mediaIcon = null;
|
|
|
|
|
|
|
|
if (status === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-08-19 15:14:32 -04:00
|
|
|
const handlers = {
|
|
|
|
reply: this.handleHotkeyReply,
|
|
|
|
favourite: this.handleHotkeyFavourite,
|
|
|
|
boost: this.handleHotkeyBoost,
|
|
|
|
mention: this.handleHotkeyMention,
|
|
|
|
open: this.handleHotkeyOpen,
|
|
|
|
openProfile: this.handleHotkeyOpenProfile,
|
|
|
|
moveUp: this.handleHotkeyMoveUp,
|
|
|
|
moveDown: this.handleHotkeyMoveDown,
|
|
|
|
toggleSpoiler: this.handleExpandedToggle,
|
|
|
|
bookmark: this.handleHotkeyBookmark,
|
|
|
|
toggleCollapse: this.handleHotkeyCollapse,
|
|
|
|
toggleSensitive: this.handleHotkeyToggleSensitive,
|
2019-11-29 11:02:36 -05:00
|
|
|
openMedia: this.handleHotkeyOpenMedia,
|
2019-08-19 15:14:32 -04:00
|
|
|
};
|
|
|
|
|
2017-11-17 22:11:18 -05:00
|
|
|
if (hidden) {
|
|
|
|
return (
|
2019-08-19 15:14:32 -04:00
|
|
|
<HotKeys handlers={handlers}>
|
|
|
|
<div ref={this.handleRef} className='status focusable' tabIndex='0'>
|
|
|
|
{status.getIn(['account', 'display_name']) || status.getIn(['account', 'username'])}
|
|
|
|
{' '}
|
|
|
|
{status.get('content')}
|
|
|
|
</div>
|
|
|
|
</HotKeys>
|
2017-11-17 22:11:18 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-19 12:00:14 -04:00
|
|
|
const filtered = (status.get('filtered') || status.getIn(['reblog', 'filtered'])) && settings.get('filtering_behavior') !== 'content_warning';
|
|
|
|
if (forceFilter === undefined ? filtered : forceFilter) {
|
2018-07-08 14:04:53 -04:00
|
|
|
const minHandlers = this.props.muted ? {} : {
|
|
|
|
moveUp: this.handleHotkeyMoveUp,
|
|
|
|
moveDown: this.handleHotkeyMoveDown,
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<HotKeys handlers={minHandlers}>
|
2019-02-10 05:50:31 -05:00
|
|
|
<div className='status__wrapper status__wrapper--filtered focusable' tabIndex='0' ref={this.handleRef}>
|
2018-07-08 14:04:53 -04:00
|
|
|
<FormattedMessage id='status.filtered' defaultMessage='Filtered' />
|
2019-07-14 15:39:07 -04:00
|
|
|
{settings.get('filtering_behavior') !== 'upstream' && ' '}
|
2019-07-12 12:53:40 -04:00
|
|
|
{settings.get('filtering_behavior') !== 'upstream' && (
|
2019-07-12 12:27:43 -04:00
|
|
|
<button className='status__wrapper--filtered__button' onClick={this.handleUnfilterClick}>
|
2019-07-14 15:39:07 -04:00
|
|
|
<FormattedMessage id='status.show_filter_reason' defaultMessage='(show why)' />
|
2019-07-12 12:27:43 -04:00
|
|
|
</button>
|
|
|
|
)}
|
2018-07-08 14:04:53 -04:00
|
|
|
</div>
|
|
|
|
</HotKeys>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-17 22:11:18 -05:00
|
|
|
// If user backgrounds for collapsed statuses are enabled, then we
|
|
|
|
// initialize our background accordingly. This will only be rendered if
|
|
|
|
// the status is collapsed.
|
|
|
|
if (settings.getIn(['collapsed', 'backgrounds', 'user_backgrounds'])) {
|
|
|
|
background = status.getIn(['account', 'header']);
|
|
|
|
}
|
|
|
|
|
2018-03-27 09:50:05 -04:00
|
|
|
// This handles our media attachments.
|
|
|
|
// If a media file is of unknwon type or if the status is muted
|
|
|
|
// (notification), we show a list of links instead of embedded media.
|
2017-11-17 22:11:18 -05:00
|
|
|
|
|
|
|
// After we have generated our appropriate media element and stored it in
|
|
|
|
// `media`, we snatch the thumbnail to use as our `background` if media
|
|
|
|
// backgrounds for collapsed statuses are enabled.
|
|
|
|
attachments = status.get('media_attachments');
|
2019-03-03 16:18:23 -05:00
|
|
|
if (status.get('poll')) {
|
|
|
|
media = <PollContainer pollId={status.get('poll')} />;
|
2019-03-06 06:21:18 -05:00
|
|
|
mediaIcon = 'tasks';
|
2019-03-03 16:18:23 -05:00
|
|
|
} else if (attachments.size > 0) {
|
2018-03-27 09:50:05 -04:00
|
|
|
if (muted || attachments.some(item => item.get('type') === 'unknown')) {
|
2018-03-27 09:40:10 -04:00
|
|
|
media = (
|
|
|
|
<AttachmentList
|
|
|
|
compact
|
|
|
|
media={status.get('media_attachments')}
|
|
|
|
/>
|
|
|
|
);
|
2019-08-23 16:38:02 -04:00
|
|
|
} else if (attachments.getIn([0, 'type']) === 'audio') {
|
|
|
|
const attachment = status.getIn(['media_attachments', 0]);
|
|
|
|
|
|
|
|
media = (
|
|
|
|
<Bundle fetchComponent={Audio} loading={this.renderLoadingAudioPlayer} >
|
|
|
|
{Component => (
|
|
|
|
<Component
|
|
|
|
src={attachment.get('url')}
|
|
|
|
alt={attachment.get('description')}
|
|
|
|
duration={attachment.getIn(['meta', 'original', 'duration'], 0)}
|
2019-08-25 09:09:19 -04:00
|
|
|
peaks={[0]}
|
|
|
|
height={70}
|
2019-08-23 16:38:02 -04:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Bundle>
|
|
|
|
);
|
|
|
|
mediaIcon = 'music';
|
|
|
|
} else if (attachments.getIn([0, 'type']) === 'video') {
|
2019-06-19 17:42:38 -04:00
|
|
|
const attachment = status.getIn(['media_attachments', 0]);
|
2017-11-17 22:11:18 -05:00
|
|
|
|
|
|
|
media = (
|
|
|
|
<Bundle fetchComponent={Video} loading={this.renderLoadingVideoPlayer} >
|
2018-01-18 10:13:07 -05:00
|
|
|
{Component => (<Component
|
2019-06-19 17:42:38 -04:00
|
|
|
preview={attachment.get('preview_url')}
|
|
|
|
blurhash={attachment.get('blurhash')}
|
|
|
|
src={attachment.get('url')}
|
|
|
|
alt={attachment.get('description')}
|
2018-04-14 11:14:04 -04:00
|
|
|
inline
|
2017-11-17 22:11:18 -05:00
|
|
|
sensitive={status.get('sensitive')}
|
|
|
|
letterbox={settings.getIn(['media', 'letterbox'])}
|
|
|
|
fullwidth={settings.getIn(['media', 'fullwidth'])}
|
2018-09-04 12:50:45 -04:00
|
|
|
preventPlayback={isCollapsed || !isExpanded}
|
2017-11-17 22:11:18 -05:00
|
|
|
onOpenVideo={this.handleOpenVideo}
|
2019-02-09 14:54:11 -05:00
|
|
|
width={this.props.cachedMediaWidth}
|
|
|
|
cacheWidth={this.props.cacheMediaWidth}
|
2019-05-26 12:58:14 -04:00
|
|
|
visible={this.state.showMedia}
|
|
|
|
onToggleVisibility={this.handleToggleMediaVisibility}
|
2018-01-18 10:13:07 -05:00
|
|
|
/>)}
|
2017-11-17 22:11:18 -05:00
|
|
|
</Bundle>
|
|
|
|
);
|
2019-08-23 16:38:02 -04:00
|
|
|
mediaIcon = 'video-camera';
|
2017-11-17 22:11:18 -05:00
|
|
|
} else { // Media type is 'image' or 'gifv'
|
|
|
|
media = (
|
2018-07-31 17:03:16 -04:00
|
|
|
<Bundle fetchComponent={MediaGallery} loading={this.renderLoadingMediaGallery}>
|
2017-11-17 22:11:18 -05:00
|
|
|
{Component => (
|
|
|
|
<Component
|
|
|
|
media={attachments}
|
|
|
|
sensitive={status.get('sensitive')}
|
|
|
|
letterbox={settings.getIn(['media', 'letterbox'])}
|
|
|
|
fullwidth={settings.getIn(['media', 'fullwidth'])}
|
2018-10-20 13:28:54 -04:00
|
|
|
hidden={isCollapsed || !isExpanded}
|
2017-11-17 22:11:18 -05:00
|
|
|
onOpenMedia={this.props.onOpenMedia}
|
2019-02-09 14:54:11 -05:00
|
|
|
cacheWidth={this.props.cacheMediaWidth}
|
|
|
|
defaultWidth={this.props.cachedMediaWidth}
|
2019-05-26 12:58:14 -04:00
|
|
|
visible={this.state.showMedia}
|
|
|
|
onToggleVisibility={this.handleToggleMediaVisibility}
|
2017-11-17 22:11:18 -05:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Bundle>
|
|
|
|
);
|
|
|
|
mediaIcon = 'picture-o';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status.get('sensitive') && !(status.get('spoiler_text').length > 0) && settings.getIn(['collapsed', 'backgrounds', 'preview_images'])) {
|
|
|
|
background = attachments.getIn([0, 'preview_url']);
|
|
|
|
}
|
2018-10-30 09:46:48 -04:00
|
|
|
} else if (status.get('card') && settings.get('inline_preview_cards')) {
|
2018-10-29 09:44:04 -04:00
|
|
|
media = (
|
|
|
|
<Card
|
|
|
|
onOpenMedia={this.props.onOpenMedia}
|
|
|
|
card={status.get('card')}
|
|
|
|
compact
|
2019-02-09 14:54:11 -05:00
|
|
|
cacheWidth={this.props.cacheMediaWidth}
|
|
|
|
defaultWidth={this.props.cachedMediaWidth}
|
2018-10-29 09:44:04 -04:00
|
|
|
/>
|
|
|
|
);
|
2018-10-30 09:39:00 -04:00
|
|
|
mediaIcon = 'link';
|
2017-11-17 22:11:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Here we prepare extra data-* attributes for CSS selectors.
|
|
|
|
// Users can use those for theming, hiding avatars etc via UserStyle
|
|
|
|
const selectorAttribs = {
|
|
|
|
'data-status-by': `@${status.getIn(['account', 'acct'])}`,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (prepend && account) {
|
|
|
|
const notifKind = {
|
|
|
|
favourite: 'favourited',
|
|
|
|
reblog: 'boosted',
|
|
|
|
reblogged_by: 'boosted',
|
|
|
|
}[prepend];
|
|
|
|
|
|
|
|
selectorAttribs[`data-${notifKind}-by`] = `@${account.get('acct')}`;
|
|
|
|
}
|
|
|
|
|
2018-08-28 06:10:40 -04:00
|
|
|
let rebloggedByText;
|
|
|
|
|
|
|
|
if (prepend === 'reblog') {
|
|
|
|
rebloggedByText = intl.formatMessage({ id: 'status.reblogged_by', defaultMessage: '{name} boosted' }, { name: account.get('acct') });
|
|
|
|
}
|
|
|
|
|
2017-11-27 16:17:12 -05:00
|
|
|
const computedClass = classNames('status', `status-${status.get('visibility')}`, {
|
2018-03-28 09:40:34 -04:00
|
|
|
collapsed: isCollapsed,
|
|
|
|
'has-background': isCollapsed && background,
|
2018-08-28 05:05:17 -04:00
|
|
|
'status__wrapper-reply': !!status.get('in_reply_to_id'),
|
2019-06-09 06:07:23 -04:00
|
|
|
read: unread === false,
|
2017-11-27 16:17:12 -05:00
|
|
|
muted,
|
|
|
|
}, 'focusable');
|
|
|
|
|
2017-11-17 22:11:18 -05:00
|
|
|
return (
|
|
|
|
<HotKeys handlers={handlers}>
|
|
|
|
<div
|
2017-11-27 16:17:12 -05:00
|
|
|
className={computedClass}
|
2018-03-28 09:40:34 -04:00
|
|
|
style={isCollapsed && background ? { backgroundImage: `url(${background})` } : null}
|
2017-11-17 22:11:18 -05:00
|
|
|
{...selectorAttribs}
|
2017-11-18 14:05:23 -05:00
|
|
|
ref={handleRef}
|
2017-11-27 16:17:12 -05:00
|
|
|
tabIndex='0'
|
2018-04-22 16:08:30 -04:00
|
|
|
data-featured={featured ? 'true' : null}
|
2018-08-28 06:10:40 -04:00
|
|
|
aria-label={textForScreenReader(intl, status, rebloggedByText, !status.get('hidden'))}
|
2017-11-17 22:11:18 -05:00
|
|
|
>
|
2018-03-12 20:57:28 -04:00
|
|
|
<header className='status__info'>
|
2018-03-18 13:42:28 -04:00
|
|
|
<span>
|
|
|
|
{prepend && account ? (
|
|
|
|
<StatusPrepend
|
|
|
|
type={prepend}
|
|
|
|
account={account}
|
|
|
|
parseClick={parseClick}
|
|
|
|
notificationId={this.props.notificationId}
|
|
|
|
/>
|
|
|
|
) : null}
|
2018-03-28 09:40:34 -04:00
|
|
|
{!muted || !isCollapsed ? (
|
2018-03-18 13:42:28 -04:00
|
|
|
<StatusHeader
|
|
|
|
status={status}
|
|
|
|
friend={account}
|
2018-03-28 09:40:34 -04:00
|
|
|
collapsed={isCollapsed}
|
2018-03-18 13:42:28 -04:00
|
|
|
parseClick={parseClick}
|
2019-06-09 06:07:23 -04:00
|
|
|
otherAccounts={otherAccounts}
|
2018-03-18 13:42:28 -04:00
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</span>
|
2018-03-12 20:57:28 -04:00
|
|
|
<StatusIcons
|
|
|
|
status={status}
|
|
|
|
mediaIcon={mediaIcon}
|
|
|
|
collapsible={settings.getIn(['collapsed', 'enabled'])}
|
2018-03-28 09:40:34 -04:00
|
|
|
collapsed={isCollapsed}
|
|
|
|
setCollapsed={setCollapsed}
|
2019-06-09 06:07:23 -04:00
|
|
|
directMessage={!!otherAccounts}
|
2017-11-17 22:11:18 -05:00
|
|
|
/>
|
2018-03-12 20:57:28 -04:00
|
|
|
</header>
|
2017-11-17 22:11:18 -05:00
|
|
|
<StatusContent
|
|
|
|
status={status}
|
|
|
|
media={media}
|
|
|
|
mediaIcon={mediaIcon}
|
|
|
|
expanded={isExpanded}
|
2018-03-28 13:56:46 -04:00
|
|
|
onExpandedToggle={this.handleExpandedToggle}
|
2017-11-17 22:11:18 -05:00
|
|
|
parseClick={parseClick}
|
|
|
|
disabled={!router}
|
2019-08-01 12:48:16 -04:00
|
|
|
tagLinks={settings.get('tag_misleading_links')}
|
2019-08-28 16:13:41 -04:00
|
|
|
rewriteMentions={settings.get('rewrite_mentions')}
|
2017-11-17 22:11:18 -05:00
|
|
|
/>
|
2018-09-29 19:44:02 -04:00
|
|
|
{!isCollapsed || !(muted || !settings.getIn(['collapsed', 'show_action_bar'])) ? (
|
2017-11-17 22:11:18 -05:00
|
|
|
<StatusActionBar
|
|
|
|
{...other}
|
|
|
|
status={status}
|
|
|
|
account={status.get('account')}
|
2018-08-22 07:17:21 -04:00
|
|
|
showReplyCount={settings.get('show_reply_count')}
|
2019-06-09 06:07:23 -04:00
|
|
|
directMessage={!!otherAccounts}
|
2019-07-12 10:01:33 -04:00
|
|
|
onFilter={this.handleFilterClick}
|
2017-11-17 22:11:18 -05:00
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
{notification ? (
|
|
|
|
<NotificationOverlayContainer
|
|
|
|
notification={notification}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
</HotKeys>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|