2017-07-05 18:51:03 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
`<Status>`
|
|
|
|
==========
|
|
|
|
|
|
|
|
Original file by @gargron@mastodon.social et al as part of
|
|
|
|
tootsuite/mastodon. *Heavily* rewritten (and documented!) by
|
|
|
|
@kibi@glitch.social as a part of glitch-soc/mastodon. The following
|
|
|
|
features have been added:
|
|
|
|
|
|
|
|
- Better separating the "guts" of statuses from their wrapper(s)
|
|
|
|
- Collapsing statuses
|
|
|
|
- Moving images inside of CWs
|
|
|
|
|
|
|
|
A number of aspects of this original file have been split off into
|
|
|
|
their own components for better maintainance; for these, see:
|
|
|
|
|
|
|
|
- <StatusHeader>
|
|
|
|
- <StatusPrepend>
|
|
|
|
|
|
|
|
…And, of course, the other <Status>-related components as well.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* * * * */
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Imports:
|
|
|
|
--------
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-07-12 01:02:51 -07:00
|
|
|
// Package imports //
|
2017-05-02 17:04:16 -07:00
|
|
|
import React from 'react';
|
2017-04-21 11:05:35 -07:00
|
|
|
import PropTypes from 'prop-types';
|
2017-07-05 18:51:03 -07:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
|
2017-07-12 01:02:51 -07:00
|
|
|
// Mastodon imports //
|
|
|
|
import scheduleIdleTask from '../../../mastodon/features/ui/util/schedule_idle_task';
|
2017-07-05 18:51:03 -07:00
|
|
|
|
2017-07-12 01:02:51 -07:00
|
|
|
// Our imports //
|
|
|
|
import StatusPrepend from './prepend';
|
|
|
|
import StatusHeader from './header';
|
|
|
|
import StatusContent from './content';
|
|
|
|
import StatusActionBar from './action_bar';
|
|
|
|
import StatusGallery from './gallery';
|
2017-07-13 02:40:16 -07:00
|
|
|
import StatusPlayer from './player';
|
2017-07-21 11:33:16 -07:00
|
|
|
import NotificationOverlayContainer from '../notification/overlay/container';
|
2016-08-24 08:56:44 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/* * * * */
|
2017-06-21 19:05:24 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
2017-06-27 18:34:30 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
The `<Status>` component:
|
|
|
|
-------------------------
|
2017-06-27 18:34:30 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
The `<Status>` component is a container for statuses. It consists of a
|
|
|
|
few parts:
|
2017-06-27 18:34:30 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
- The `<StatusPrepend>`, which contains tangential information about
|
|
|
|
the status, such as who reblogged it.
|
|
|
|
- The `<StatusHeader>`, which contains the avatar and username of the
|
|
|
|
status author, as well as a media icon and the "collapse" toggle.
|
|
|
|
- The `<StatusContent>`, which contains the content of the status.
|
|
|
|
- The `<StatusActionBar>`, which provides actions to be performed
|
|
|
|
on statuses, like reblogging or sending a reply.
|
2017-06-27 18:34:30 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
### Context
|
2017-06-27 18:34:30 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
- __`router` (`PropTypes.object`) :__
|
|
|
|
We need to get our router from the surrounding React context.
|
2017-06-27 18:34:30 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
### Props
|
2017-06-27 18:34:30 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
- __`id` (`PropTypes.number`) :__
|
|
|
|
The id of the status.
|
2017-06-27 18:34:30 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
- __`status` (`ImmutablePropTypes.map`) :__
|
|
|
|
The status object, straight from the store.
|
2017-06-27 18:34:30 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
- __`account` (`ImmutablePropTypes.map`) :__
|
|
|
|
Don't be confused by this one! This is **not** the account which
|
|
|
|
posted the status, but the associated account with any further
|
|
|
|
action (eg, a reblog or a favourite).
|
2017-06-27 18:34:30 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
- __`settings` (`ImmutablePropTypes.map`) :__
|
|
|
|
These are our local settings, fetched from our store. We need this
|
|
|
|
to determine how best to collapse our statuses, among other things.
|
|
|
|
|
|
|
|
- __`me` (`PropTypes.number`) :__
|
|
|
|
This is the id of the currently-signed-in user.
|
|
|
|
|
|
|
|
- __`onFavourite`, `onReblog`, `onModalReblog`, `onDelete`,
|
|
|
|
`onMention`, `onMute`, `onMuteConversation`, onBlock`, `onReport`,
|
|
|
|
`onOpenMedia`, `onOpenVideo` (`PropTypes.func`) :__
|
|
|
|
These are all functions passed through from the
|
|
|
|
`<StatusContainer>`. We don't deal with them directly here.
|
|
|
|
|
|
|
|
- __`reblogModal`, `deleteModal` (`PropTypes.bool`) :__
|
|
|
|
These tell whether or not the user has modals activated for
|
|
|
|
reblogging and deleting statuses. They are used by the `onReblog`
|
|
|
|
and `onDelete` functions, but we don't deal with them here.
|
|
|
|
|
|
|
|
- __`autoPlayGif` (`PropTypes.bool`) :__
|
|
|
|
This tells the frontend whether or not to autoplay gifs!
|
|
|
|
|
|
|
|
- __`muted` (`PropTypes.bool`) :__
|
|
|
|
This has nothing to do with a user or conversation mute! "Muted" is
|
|
|
|
what Mastodon internally calls the subdued look of statuses in the
|
|
|
|
notifications column. This should be `true` for notifications, and
|
|
|
|
`false` otherwise.
|
|
|
|
|
|
|
|
- __`collapse` (`PropTypes.bool`) :__
|
|
|
|
This prop signals a directive from a higher power to (un)collapse
|
|
|
|
a status. Most of the time it should be `undefined`, in which case
|
|
|
|
we do nothing.
|
|
|
|
|
|
|
|
- __`prepend` (`PropTypes.string`) :__
|
|
|
|
The type of prepend: `'reblogged_by'`, `'reblog'`, or
|
|
|
|
`'favourite'`.
|
|
|
|
|
|
|
|
- __`withDismiss` (`PropTypes.bool`) :__
|
|
|
|
Whether or not the status can be dismissed. Used for notifications.
|
|
|
|
|
|
|
|
- __`intersectionObserverWrapper` (`PropTypes.object`) :__
|
|
|
|
This holds our intersection observer. In Mastodon parlance,
|
|
|
|
an "intersection" is just when the status is viewable onscreen.
|
2017-06-27 18:34:30 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
### State
|
|
|
|
|
|
|
|
- __`isExpanded` :__
|
|
|
|
Should be either `true`, `false`, or `null`. The meanings of
|
|
|
|
these values are as follows:
|
|
|
|
|
|
|
|
- __`true` :__ The status contains a CW and the CW is expanded.
|
|
|
|
- __`false` :__ The status is collapsed.
|
|
|
|
- __`null` :__ The status is not collapsed or expanded.
|
|
|
|
|
|
|
|
- __`isIntersecting` :__
|
|
|
|
This boolean tells us whether or not the status is currently
|
|
|
|
onscreen.
|
|
|
|
|
|
|
|
- __`isHidden` :__
|
|
|
|
This boolean tells us if the status has been unrendered to save
|
|
|
|
CPUs.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
export default class Status extends ImmutablePureComponent {
|
2017-04-21 11:05:35 -07:00
|
|
|
|
2017-05-12 05:44:10 -07:00
|
|
|
static contextTypes = {
|
2017-07-05 18:51:03 -07:00
|
|
|
router : PropTypes.object,
|
2017-05-12 05:44:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
2017-07-05 18:51:03 -07:00
|
|
|
id : PropTypes.number,
|
|
|
|
status : ImmutablePropTypes.map,
|
|
|
|
account : ImmutablePropTypes.map,
|
|
|
|
settings : ImmutablePropTypes.map,
|
2017-07-21 11:33:16 -07:00
|
|
|
notification : ImmutablePropTypes.map,
|
2017-07-05 18:51:03 -07:00
|
|
|
me : PropTypes.number,
|
|
|
|
onFavourite : PropTypes.func,
|
|
|
|
onReblog : PropTypes.func,
|
|
|
|
onModalReblog : PropTypes.func,
|
|
|
|
onDelete : PropTypes.func,
|
|
|
|
onMention : PropTypes.func,
|
|
|
|
onMute : PropTypes.func,
|
|
|
|
onMuteConversation : PropTypes.func,
|
|
|
|
onBlock : PropTypes.func,
|
|
|
|
onReport : PropTypes.func,
|
|
|
|
onOpenMedia : PropTypes.func,
|
|
|
|
onOpenVideo : PropTypes.func,
|
|
|
|
reblogModal : PropTypes.bool,
|
|
|
|
deleteModal : PropTypes.bool,
|
|
|
|
autoPlayGif : PropTypes.bool,
|
|
|
|
muted : PropTypes.bool,
|
|
|
|
collapse : PropTypes.bool,
|
|
|
|
prepend : PropTypes.string,
|
|
|
|
withDismiss : PropTypes.bool,
|
|
|
|
intersectionObserverWrapper : PropTypes.object,
|
2017-05-12 05:44:10 -07:00
|
|
|
};
|
|
|
|
|
2017-05-24 08:55:00 -07:00
|
|
|
state = {
|
2017-07-05 18:51:03 -07:00
|
|
|
isExpanded : null,
|
|
|
|
isIntersecting : true,
|
|
|
|
isHidden : false,
|
2017-07-21 11:33:16 -07:00
|
|
|
markedForDelete : false,
|
2017-05-24 08:55:00 -07:00
|
|
|
}
|
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
### Implementation
|
|
|
|
|
|
|
|
#### `updateOnProps` and `updateOnStates`.
|
|
|
|
|
|
|
|
`updateOnProps` and `updateOnStates` tell the component when to update.
|
|
|
|
We specify them explicitly because some of our props are dynamically=
|
|
|
|
generated functions, which would otherwise always trigger an update.
|
|
|
|
Of course, this means that if we add an important prop, we will need
|
|
|
|
to remember to specify it here.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-05-26 05:05:52 -07:00
|
|
|
updateOnProps = [
|
|
|
|
'status',
|
|
|
|
'account',
|
2017-06-28 22:00:54 -07:00
|
|
|
'settings',
|
2017-07-05 18:51:03 -07:00
|
|
|
'prepend',
|
2017-05-26 05:05:52 -07:00
|
|
|
'me',
|
|
|
|
'boostModal',
|
|
|
|
'autoPlayGif',
|
|
|
|
'muted',
|
2017-06-26 14:18:59 -07:00
|
|
|
'collapse',
|
2017-07-21 11:33:16 -07:00
|
|
|
'notification',
|
2017-05-26 05:05:52 -07:00
|
|
|
]
|
|
|
|
|
2017-06-26 14:18:59 -07:00
|
|
|
updateOnStates = [
|
|
|
|
'isExpanded',
|
2017-07-21 11:33:16 -07:00
|
|
|
'markedForDelete',
|
2017-06-26 14:18:59 -07:00
|
|
|
]
|
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
#### `componentWillReceiveProps()`.
|
|
|
|
|
|
|
|
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
|
|
|
|
`componentWillReceiveProps()`.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-06-26 14:18:59 -07:00
|
|
|
componentWillReceiveProps (nextProps) {
|
2017-07-05 18:51:03 -07:00
|
|
|
if (!nextProps.settings.getIn(['collapsed', 'enabled'])) {
|
2017-07-12 10:52:36 -07:00
|
|
|
if (this.state.isExpanded === false) {
|
|
|
|
this.setExpansion(null);
|
|
|
|
}
|
2017-07-05 18:51:03 -07:00
|
|
|
} else if (
|
|
|
|
nextProps.collapse !== this.props.collapse &&
|
|
|
|
nextProps.collapse !== undefined
|
|
|
|
) this.setExpansion(nextProps.collapse ? false : null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
#### `componentDidMount()`.
|
|
|
|
|
|
|
|
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
|
|
|
|
is enabled here, because `setExpansion()` already takes that into
|
|
|
|
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.
|
|
|
|
|
|
|
|
We also start up our intersection observer to monitor our statuses.
|
|
|
|
`componentMounted` lets us know that everything has been set up
|
|
|
|
properly and our intersection observer is good to go.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
const { node, handleIntersection } = this;
|
|
|
|
const {
|
|
|
|
status,
|
|
|
|
settings,
|
|
|
|
collapse,
|
|
|
|
muted,
|
|
|
|
id,
|
|
|
|
intersectionObserverWrapper,
|
|
|
|
} = this.props;
|
|
|
|
const autoCollapseSettings = settings.getIn(['collapsed', 'auto']);
|
|
|
|
|
|
|
|
if (
|
|
|
|
collapse ||
|
|
|
|
autoCollapseSettings.get('all') || (
|
|
|
|
autoCollapseSettings.get('notifications') && muted
|
|
|
|
) || (
|
|
|
|
autoCollapseSettings.get('lengthy') &&
|
|
|
|
node.clientHeight > (
|
|
|
|
status.get('media_attachments').size && !muted ? 650 : 400
|
|
|
|
)
|
|
|
|
) || (
|
|
|
|
autoCollapseSettings.get('replies') &&
|
|
|
|
status.get('in_reply_to_id', null) !== null
|
|
|
|
) || (
|
|
|
|
autoCollapseSettings.get('media') &&
|
|
|
|
!(status.get('spoiler_text').length) &&
|
|
|
|
status.get('media_attachments').size
|
|
|
|
)
|
|
|
|
) this.setExpansion(false);
|
|
|
|
|
|
|
|
if (!intersectionObserverWrapper) return;
|
|
|
|
else intersectionObserverWrapper.observe(
|
|
|
|
id,
|
|
|
|
node,
|
|
|
|
handleIntersection
|
|
|
|
);
|
|
|
|
|
|
|
|
this.componentMounted = true;
|
2017-06-26 14:18:59 -07:00
|
|
|
}
|
2017-05-26 05:05:52 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
#### `shouldComponentUpdate()`.
|
|
|
|
|
|
|
|
If the status is about to be both offscreen (not intersecting) and
|
|
|
|
hidden, then we only need to update it if it's not that way currently.
|
|
|
|
If the status is moving from offscreen to onscreen, then we *have* to
|
|
|
|
re-render, so that we can unhide the element if necessary.
|
|
|
|
|
|
|
|
If neither of these cases are true, we can leave it up to our
|
|
|
|
`updateOnProps` and `updateOnStates` arrays.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-05-26 05:05:52 -07:00
|
|
|
shouldComponentUpdate (nextProps, nextState) {
|
2017-07-05 18:51:03 -07:00
|
|
|
switch (true) {
|
|
|
|
case !nextState.isIntersecting && nextState.isHidden:
|
2017-05-29 09:17:51 -07:00
|
|
|
return this.state.isIntersecting || !this.state.isHidden;
|
2017-07-05 18:51:03 -07:00
|
|
|
case nextState.isIntersecting && !this.state.isIntersecting:
|
2017-05-26 05:05:52 -07:00
|
|
|
return true;
|
2017-07-05 18:51:03 -07:00
|
|
|
default:
|
|
|
|
return super.shouldComponentUpdate(nextProps, nextState);
|
2017-05-26 05:05:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
2017-06-21 20:10:11 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
#### `componentDidUpdate()`.
|
2017-06-21 19:05:24 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
If our component is being rendered for any reason and an update has
|
|
|
|
triggered, this will save its height.
|
2017-06-28 22:00:54 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
This is, frankly, a bit overkill, as the only instance when we
|
|
|
|
actually *need* to update the height right now should be when the
|
|
|
|
value of `isExpanded` has changed. But it makes for more readable
|
|
|
|
code and prevents bugs in the future where the height isn't set
|
|
|
|
properly after some change.
|
2017-06-26 14:18:59 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
*/
|
2017-06-20 11:37:09 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
componentDidUpdate () {
|
|
|
|
if (
|
|
|
|
this.state.isIntersecting || !this.state.isHidden
|
|
|
|
) this.saveHeight();
|
2017-05-24 08:55:00 -07:00
|
|
|
}
|
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
#### `componentWillUnmount()`.
|
|
|
|
|
|
|
|
If our component is about to unmount, then we'd better unset
|
|
|
|
`this.componentMounted`.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-06-19 02:29:57 -07:00
|
|
|
componentWillUnmount () {
|
2017-06-20 11:37:09 -07:00
|
|
|
this.componentMounted = false;
|
2017-06-19 02:29:57 -07:00
|
|
|
}
|
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
#### `handleIntersection()`.
|
|
|
|
|
|
|
|
`handleIntersection()` either hides the status (if it is offscreen) or
|
|
|
|
unhides it (if it is onscreen). It's called by
|
|
|
|
`intersectionObserverWrapper.observe()`.
|
|
|
|
|
|
|
|
If our status isn't intersecting, we schedule an idle task (using the
|
|
|
|
aptly-named `scheduleIdleTask()`) to hide the status at the next
|
|
|
|
available opportunity.
|
|
|
|
|
|
|
|
tootsuite/mastodon left us with the following enlightening comment
|
|
|
|
regarding this function:
|
|
|
|
|
|
|
|
> Edge 15 doesn't support isIntersecting, but we can infer it
|
|
|
|
|
|
|
|
It then implements a polyfill (intersectionRect.height > 0) which isn't
|
|
|
|
actually sufficient. The short answer is, this behaviour isn't really
|
|
|
|
supported on Edge but we can get kinda close.
|
|
|
|
|
|
|
|
*/
|
2017-06-28 22:00:54 -07:00
|
|
|
|
2017-05-29 09:17:51 -07:00
|
|
|
handleIntersection = (entry) => {
|
2017-07-05 18:51:03 -07:00
|
|
|
const isIntersecting = (
|
|
|
|
typeof entry.isIntersecting === 'boolean' ?
|
|
|
|
entry.isIntersecting :
|
|
|
|
entry.intersectionRect.height > 0
|
|
|
|
);
|
|
|
|
this.setState(
|
|
|
|
(prevState) => {
|
|
|
|
if (prevState.isIntersecting && !isIntersecting) {
|
|
|
|
scheduleIdleTask(this.hideIfNotIntersecting);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
isIntersecting : isIntersecting,
|
|
|
|
isHidden : false,
|
|
|
|
};
|
2017-05-24 08:55:00 -07:00
|
|
|
}
|
2017-07-05 18:51:03 -07:00
|
|
|
);
|
2017-05-29 09:17:51 -07:00
|
|
|
}
|
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
#### `hideIfNotIntersecting()`.
|
|
|
|
|
|
|
|
This function will hide the status if we're still not intersecting.
|
|
|
|
Hiding the status means that it will just render an empty div instead
|
|
|
|
of actual content, which saves RAMS and CPUs or some such.
|
2017-06-20 11:37:09 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
hideIfNotIntersecting = () => {
|
|
|
|
if (!this.componentMounted) return;
|
|
|
|
this.setState(
|
|
|
|
(prevState) => ({ isHidden: !prevState.isIntersecting })
|
|
|
|
);
|
2017-05-29 09:17:51 -07:00
|
|
|
}
|
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
#### `saveHeight()`.
|
|
|
|
|
|
|
|
`saveHeight()` saves the height of our status so that when whe hide it
|
|
|
|
we preserve its dimensions. We only want to store our height, though,
|
|
|
|
if our status has content (otherwise, it would imply that it is
|
|
|
|
already hidden).
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-06-13 11:46:21 -07:00
|
|
|
saveHeight = () => {
|
2017-07-05 18:51:03 -07:00
|
|
|
if (this.node && this.node.children.length) {
|
2017-06-27 09:43:53 -07:00
|
|
|
this.height = this.node.getBoundingClientRect().height;
|
2017-06-13 11:46:21 -07:00
|
|
|
}
|
|
|
|
}
|
2017-05-29 09:17:51 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
#### `setExpansion()`.
|
|
|
|
|
|
|
|
`setExpansion()` sets the value of `isExpanded` in our state. It takes
|
|
|
|
one argument, `value`, which gives the desired value for `isExpanded`.
|
|
|
|
The default for this argument is `null`.
|
|
|
|
|
|
|
|
`setExpansion()` automatically checks for us whether toot collapsing
|
|
|
|
is enabled, so we don't have to.
|
|
|
|
|
|
|
|
We use a `switch` statement to simplify our code.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
setExpansion = (value) => {
|
|
|
|
switch (true) {
|
|
|
|
case value === undefined || value === null:
|
|
|
|
this.setState({ isExpanded: null });
|
|
|
|
break;
|
|
|
|
case !value && this.props.settings.getIn(['collapsed', 'enabled']):
|
|
|
|
this.setState({ isExpanded: false });
|
|
|
|
break;
|
|
|
|
case !!value:
|
|
|
|
this.setState({ isExpanded: true });
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
#### `handleRef()`.
|
|
|
|
|
|
|
|
`handleRef()` just saves a reference to our status node to `this.node`.
|
|
|
|
It also saves our height, in case the height of our node has changed.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-05-29 09:17:51 -07:00
|
|
|
handleRef = (node) => {
|
|
|
|
this.node = node;
|
2017-06-13 11:46:21 -07:00
|
|
|
this.saveHeight();
|
2017-05-24 08:55:00 -07:00
|
|
|
}
|
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
2016-09-15 15:21:51 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
#### `parseClick()`.
|
|
|
|
|
|
|
|
`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;
|
|
|
|
const { isExpanded } = this.state;
|
2017-07-15 15:10:06 -07:00
|
|
|
if (!router) return;
|
2017-07-05 18:51:03 -07:00
|
|
|
if (destination === undefined) {
|
|
|
|
destination = `/statuses/${
|
|
|
|
status.getIn(['reblog', 'id'], status.get('id'))
|
|
|
|
}`;
|
|
|
|
}
|
2016-09-15 15:21:51 -07:00
|
|
|
if (e.button === 0) {
|
2017-07-05 18:51:03 -07:00
|
|
|
if (isExpanded === false) this.setExpansion(null);
|
|
|
|
else if (e.shiftKey) {
|
|
|
|
this.setExpansion(false);
|
|
|
|
document.getSelection().removeAllRanges();
|
|
|
|
} else router.history.push(destination);
|
2016-09-15 15:21:51 -07:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
2017-04-21 11:05:35 -07:00
|
|
|
}
|
2016-09-12 17:24:40 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
2017-06-13 11:46:21 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
#### `render()`.
|
|
|
|
|
|
|
|
`render()` actually puts our element on the screen. The particulars of
|
|
|
|
this operation are further explained in the code below.
|
|
|
|
|
|
|
|
*/
|
2017-06-21 19:05:24 -07:00
|
|
|
|
2016-08-24 12:08:00 -07:00
|
|
|
render () {
|
2017-07-15 15:10:06 -07:00
|
|
|
const {
|
|
|
|
parseClick,
|
|
|
|
setExpansion,
|
|
|
|
saveHeight,
|
|
|
|
handleRef,
|
|
|
|
} = this;
|
|
|
|
const { router } = this.context;
|
2017-07-05 18:51:03 -07:00
|
|
|
const {
|
|
|
|
status,
|
|
|
|
account,
|
|
|
|
settings,
|
|
|
|
collapsed,
|
|
|
|
muted,
|
|
|
|
prepend,
|
|
|
|
intersectionObserverWrapper,
|
|
|
|
onOpenVideo,
|
|
|
|
onOpenMedia,
|
|
|
|
autoPlayGif,
|
2017-07-21 11:33:16 -07:00
|
|
|
notification,
|
2017-07-05 18:51:03 -07:00
|
|
|
...other
|
|
|
|
} = this.props;
|
|
|
|
const { isExpanded, isIntersecting, isHidden } = this.state;
|
|
|
|
let background = null;
|
|
|
|
let attachments = null;
|
2017-05-24 08:55:00 -07:00
|
|
|
let media = null;
|
2017-06-28 23:20:47 -07:00
|
|
|
let mediaIcon = null;
|
2017-06-20 21:47:36 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
2016-09-05 11:38:31 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
If we don't have a status, then we don't render anything.
|
2017-06-28 22:00:54 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
*/
|
2017-06-28 22:00:54 -07:00
|
|
|
|
2016-10-25 02:13:16 -07:00
|
|
|
if (status === null) {
|
2017-05-26 05:07:48 -07:00
|
|
|
return null;
|
2017-05-24 08:55:00 -07:00
|
|
|
}
|
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
If our status is offscreen and hidden, then we render an empty <div> in
|
|
|
|
its place. We fill it with "content" but note that opacity is set to 0.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-05-29 09:17:51 -07:00
|
|
|
if (!isIntersecting && isHidden) {
|
2017-05-24 08:55:00 -07:00
|
|
|
return (
|
2017-07-05 18:51:03 -07:00
|
|
|
<div
|
|
|
|
ref={this.handleRef}
|
|
|
|
data-id={status.get('id')}
|
|
|
|
style={{
|
|
|
|
height : `${this.height}px`,
|
|
|
|
opacity : 0,
|
|
|
|
overflow : 'hidden',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
status.getIn(['account', 'display_name']) ||
|
|
|
|
status.getIn(['account', 'username'])
|
|
|
|
}
|
2017-05-24 08:55:00 -07:00
|
|
|
{status.get('content')}
|
|
|
|
</div>
|
|
|
|
);
|
2016-10-25 02:13:16 -07:00
|
|
|
}
|
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
2017-04-19 06:37:18 -07:00
|
|
|
|
2017-07-05 18:51:03 -07: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']);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This handles our media attachments. Note that we don't show media on
|
|
|
|
muted (notification) statuses. If the media type is unknown, then we
|
|
|
|
simply ignore it.
|
|
|
|
|
|
|
|
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');
|
|
|
|
if (attachments.size && !muted) {
|
|
|
|
if (attachments.some((item) => item.get('type') === 'unknown')) {
|
|
|
|
|
|
|
|
} else if (
|
|
|
|
attachments.getIn([0, 'type']) === 'video'
|
|
|
|
) {
|
|
|
|
media = ( // Media type is 'video'
|
2017-07-13 02:40:16 -07:00
|
|
|
<StatusPlayer
|
2017-07-05 18:51:03 -07:00
|
|
|
media={attachments.get(0)}
|
2017-06-30 02:15:18 -07:00
|
|
|
sensitive={status.get('sensitive')}
|
|
|
|
letterbox={settings.getIn(['media', 'letterbox'])}
|
2017-07-08 02:01:56 -07:00
|
|
|
fullwidth={settings.getIn(['media', 'fullwidth'])}
|
2017-06-30 02:15:18 -07:00
|
|
|
height={250}
|
2017-07-05 18:51:03 -07:00
|
|
|
onOpenVideo={onOpenVideo}
|
2017-06-30 02:15:18 -07:00
|
|
|
/>
|
|
|
|
);
|
2017-06-28 23:20:47 -07:00
|
|
|
mediaIcon = 'video-camera';
|
2017-07-05 18:51:03 -07:00
|
|
|
} else { // Media type is 'image' or 'gifv'
|
2017-06-30 02:15:18 -07:00
|
|
|
media = (
|
2017-07-12 01:02:51 -07:00
|
|
|
<StatusGallery
|
2017-07-05 18:51:03 -07:00
|
|
|
media={attachments}
|
2017-06-30 02:15:18 -07:00
|
|
|
sensitive={status.get('sensitive')}
|
|
|
|
letterbox={settings.getIn(['media', 'letterbox'])}
|
2017-07-08 02:01:56 -07:00
|
|
|
fullwidth={settings.getIn(['media', 'fullwidth'])}
|
2017-06-30 02:15:18 -07:00
|
|
|
height={250}
|
2017-07-05 18:51:03 -07:00
|
|
|
onOpenMedia={onOpenMedia}
|
|
|
|
autoPlayGif={autoPlayGif}
|
2017-06-30 02:15:18 -07:00
|
|
|
/>
|
|
|
|
);
|
2017-06-28 23:20:47 -07:00
|
|
|
mediaIcon = 'picture-o';
|
2016-09-17 09:05:02 -07:00
|
|
|
}
|
2017-06-28 22:00:54 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
if (
|
|
|
|
!status.get('sensitive') &&
|
|
|
|
!(status.get('spoiler_text').length > 0) &&
|
|
|
|
settings.getIn(['collapsed', 'backgrounds', 'preview_images'])
|
|
|
|
) background = attachments.getIn([0, 'preview_url']);
|
2017-05-03 02:43:37 -07:00
|
|
|
}
|
|
|
|
|
2017-08-04 13:11:46 -07: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',
|
2017-08-04 13:38:58 -07:00
|
|
|
reblogged_by: 'boosted',
|
2017-08-04 13:11:46 -07:00
|
|
|
}[prepend];
|
|
|
|
|
|
|
|
selectorAttribs[`data-${notifKind}-by`] = `@${account.get('acct')}`;
|
|
|
|
}
|
2016-08-31 13:58:10 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
/*
|
2016-08-24 12:08:00 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
Finally, we can render our status. We just put the pieces together
|
|
|
|
from above. We only render the action bar if the status isn't
|
|
|
|
collapsed.
|
2017-06-25 19:15:03 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
*/
|
2016-09-05 11:38:31 -07:00
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
return (
|
|
|
|
<article
|
|
|
|
className={
|
|
|
|
`status${
|
|
|
|
muted ? ' muted' : ''
|
|
|
|
} status-${status.get('visibility')}${
|
|
|
|
isExpanded === false ? ' collapsed' : ''
|
|
|
|
}${
|
|
|
|
isExpanded === false && background ? ' has-background' : ''
|
2017-07-21 11:33:16 -07:00
|
|
|
}${
|
|
|
|
this.state.markedForDelete ? ' marked-for-delete' : ''
|
2017-07-05 18:51:03 -07:00
|
|
|
}`
|
|
|
|
}
|
|
|
|
style={{
|
|
|
|
backgroundImage: (
|
|
|
|
isExpanded === false && background ?
|
|
|
|
`url(${background})` :
|
|
|
|
'none'
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
ref={handleRef}
|
2017-08-04 13:11:46 -07:00
|
|
|
{...selectorAttribs}
|
2017-07-05 18:51:03 -07:00
|
|
|
>
|
|
|
|
{prepend && account ? (
|
|
|
|
<StatusPrepend
|
|
|
|
type={prepend}
|
|
|
|
account={account}
|
|
|
|
parseClick={parseClick}
|
2017-07-14 08:03:43 -07:00
|
|
|
notificationId={this.props.notificationId}
|
2017-07-05 18:51:03 -07:00
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<StatusHeader
|
2017-07-26 15:41:28 -07:00
|
|
|
status={status}
|
2017-07-05 18:51:03 -07:00
|
|
|
friend={account}
|
|
|
|
mediaIcon={mediaIcon}
|
|
|
|
collapsible={settings.getIn(['collapsed', 'enabled'])}
|
|
|
|
collapsed={isExpanded === false}
|
|
|
|
parseClick={parseClick}
|
|
|
|
setExpansion={setExpansion}
|
|
|
|
/>
|
|
|
|
<StatusContent
|
|
|
|
status={status}
|
|
|
|
media={media}
|
|
|
|
mediaIcon={mediaIcon}
|
|
|
|
expanded={isExpanded}
|
2017-07-15 15:10:06 -07:00
|
|
|
setExpansion={setExpansion}
|
|
|
|
onHeightUpdate={saveHeight}
|
2017-07-05 18:51:03 -07:00
|
|
|
parseClick={parseClick}
|
2017-07-15 15:10:06 -07:00
|
|
|
disabled={!router}
|
2017-07-05 18:51:03 -07:00
|
|
|
/>
|
|
|
|
{isExpanded !== false ? (
|
|
|
|
<StatusActionBar
|
|
|
|
{...other}
|
|
|
|
status={status}
|
|
|
|
account={status.get('account')}
|
|
|
|
/>
|
|
|
|
) : null}
|
2017-07-21 12:12:43 -07:00
|
|
|
{notification ? (
|
|
|
|
<NotificationOverlayContainer
|
|
|
|
notification={notification}
|
|
|
|
/>
|
|
|
|
) : null}
|
2017-07-05 18:51:03 -07:00
|
|
|
</article>
|
2016-08-24 08:56:44 -07:00
|
|
|
);
|
2017-07-05 18:51:03 -07:00
|
|
|
|
2016-08-24 08:56:44 -07:00
|
|
|
}
|
2016-08-31 07:15:12 -07:00
|
|
|
|
2017-04-21 11:05:35 -07:00
|
|
|
}
|