logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

status.js (8340B)


  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import Avatar from './avatar';
  5. import AvatarOverlay from './avatar_overlay';
  6. import RelativeTimestamp from './relative_timestamp';
  7. import DisplayName from './display_name';
  8. import StatusContent from './status_content';
  9. import StatusActionBar from './status_action_bar';
  10. import AttachmentList from './attachment_list';
  11. import { FormattedMessage } from 'react-intl';
  12. import ImmutablePureComponent from 'react-immutable-pure-component';
  13. import { MediaGallery, Video } from '../features/ui/util/async-components';
  14. import { HotKeys } from 'react-hotkeys';
  15. import classNames from 'classnames';
  16. // We use the component (and not the container) since we do not want
  17. // to use the progress bar to show download progress
  18. import Bundle from '../features/ui/components/bundle';
  19. export default class Status extends ImmutablePureComponent {
  20. static contextTypes = {
  21. router: PropTypes.object,
  22. };
  23. static propTypes = {
  24. status: ImmutablePropTypes.map,
  25. account: ImmutablePropTypes.map,
  26. onReply: PropTypes.func,
  27. onFavourite: PropTypes.func,
  28. onReblog: PropTypes.func,
  29. onDelete: PropTypes.func,
  30. onDirect: PropTypes.func,
  31. onMention: PropTypes.func,
  32. onPin: PropTypes.func,
  33. onOpenMedia: PropTypes.func,
  34. onOpenVideo: PropTypes.func,
  35. onBlock: PropTypes.func,
  36. onHeightChange: PropTypes.func,
  37. onToggleHidden: PropTypes.func,
  38. muted: PropTypes.bool,
  39. hidden: PropTypes.bool,
  40. onMoveUp: PropTypes.func,
  41. onMoveDown: PropTypes.func,
  42. };
  43. // Avoid checking props that are functions (and whose equality will always
  44. // evaluate to false. See react-immutable-pure-component for usage.
  45. updateOnProps = [
  46. 'status',
  47. 'account',
  48. 'muted',
  49. 'hidden',
  50. ]
  51. handleClick = () => {
  52. if (!this.context.router) {
  53. return;
  54. }
  55. const { status } = this.props;
  56. this.context.router.history.push(`/statuses/${status.getIn(['reblog', 'id'], status.get('id'))}`);
  57. }
  58. handleAccountClick = (e) => {
  59. if (this.context.router && e.button === 0) {
  60. const id = e.currentTarget.getAttribute('data-id');
  61. e.preventDefault();
  62. this.context.router.history.push(`/accounts/${id}`);
  63. }
  64. }
  65. handleExpandedToggle = () => {
  66. this.props.onToggleHidden(this._properStatus());
  67. };
  68. renderLoadingMediaGallery () {
  69. return <div className='media_gallery' style={{ height: '110px' }} />;
  70. }
  71. renderLoadingVideoPlayer () {
  72. return <div className='media-spoiler-video' style={{ height: '110px' }} />;
  73. }
  74. handleOpenVideo = startTime => {
  75. this.props.onOpenVideo(this._properStatus().getIn(['media_attachments', 0]), startTime);
  76. }
  77. handleHotkeyReply = e => {
  78. e.preventDefault();
  79. this.props.onReply(this._properStatus(), this.context.router.history);
  80. }
  81. handleHotkeyFavourite = () => {
  82. this.props.onFavourite(this._properStatus());
  83. }
  84. handleHotkeyBoost = e => {
  85. this.props.onReblog(this._properStatus(), e);
  86. }
  87. handleHotkeyMention = e => {
  88. e.preventDefault();
  89. this.props.onMention(this._properStatus().get('account'), this.context.router.history);
  90. }
  91. handleHotkeyOpen = () => {
  92. this.context.router.history.push(`/statuses/${this._properStatus().get('id')}`);
  93. }
  94. handleHotkeyOpenProfile = () => {
  95. this.context.router.history.push(`/accounts/${this._properStatus().getIn(['account', 'id'])}`);
  96. }
  97. handleHotkeyMoveUp = () => {
  98. this.props.onMoveUp(this.props.status.get('id'));
  99. }
  100. handleHotkeyMoveDown = () => {
  101. this.props.onMoveDown(this.props.status.get('id'));
  102. }
  103. _properStatus () {
  104. const { status } = this.props;
  105. if (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object') {
  106. return status.get('reblog');
  107. } else {
  108. return status;
  109. }
  110. }
  111. render () {
  112. let media = null;
  113. let statusAvatar, prepend;
  114. const { hidden } = this.props;
  115. let { status, account, ...other } = this.props;
  116. if (status === null) {
  117. return null;
  118. }
  119. if (hidden) {
  120. return (
  121. <div>
  122. {status.getIn(['account', 'display_name']) || status.getIn(['account', 'username'])}
  123. {status.get('content')}
  124. </div>
  125. );
  126. }
  127. if (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object') {
  128. const display_name_html = { __html: status.getIn(['account', 'display_name_html']) };
  129. prepend = (
  130. <div className='status__prepend'>
  131. <div className='status__prepend-icon-wrapper'><i className='fa fa-fw fa-retweet status__prepend-icon' /></div>
  132. <FormattedMessage id='status.reblogged_by' defaultMessage='{name} boosted' values={{ name: <a onClick={this.handleAccountClick} data-id={status.getIn(['account', 'id'])} href={status.getIn(['account', 'url'])} className='status__display-name muted'><bdi><strong dangerouslySetInnerHTML={display_name_html} /></bdi></a> }} />
  133. </div>
  134. );
  135. account = status.get('account');
  136. status = status.get('reblog');
  137. }
  138. if (status.get('media_attachments').size > 0) {
  139. if (this.props.muted || status.get('media_attachments').some(item => item.get('type') === 'unknown')) {
  140. media = (
  141. <AttachmentList
  142. compact
  143. media={status.get('media_attachments')}
  144. />
  145. );
  146. } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
  147. const video = status.getIn(['media_attachments', 0]);
  148. media = (
  149. <Bundle fetchComponent={Video} loading={this.renderLoadingVideoPlayer} >
  150. {Component => (
  151. <Component
  152. preview={video.get('preview_url')}
  153. src={video.get('url')}
  154. width={239}
  155. height={110}
  156. inline
  157. sensitive={status.get('sensitive')}
  158. onOpenVideo={this.handleOpenVideo}
  159. />
  160. )}
  161. </Bundle>
  162. );
  163. } else {
  164. media = (
  165. <Bundle fetchComponent={MediaGallery} loading={this.renderLoadingMediaGallery} >
  166. {Component => <Component media={status.get('media_attachments')} sensitive={status.get('sensitive')} height={110} onOpenMedia={this.props.onOpenMedia} />}
  167. </Bundle>
  168. );
  169. }
  170. }
  171. if (account === undefined || account === null) {
  172. statusAvatar = <Avatar account={status.get('account')} size={48} />;
  173. }else{
  174. statusAvatar = <AvatarOverlay account={status.get('account')} friend={account} />;
  175. }
  176. const handlers = this.props.muted ? {} : {
  177. reply: this.handleHotkeyReply,
  178. favourite: this.handleHotkeyFavourite,
  179. boost: this.handleHotkeyBoost,
  180. mention: this.handleHotkeyMention,
  181. open: this.handleHotkeyOpen,
  182. openProfile: this.handleHotkeyOpenProfile,
  183. moveUp: this.handleHotkeyMoveUp,
  184. moveDown: this.handleHotkeyMoveDown,
  185. };
  186. return (
  187. <HotKeys handlers={handlers}>
  188. <div className={classNames('status__wrapper', `status__wrapper-${status.get('visibility')}`, { focusable: !this.props.muted })} tabIndex={this.props.muted ? null : 0}>
  189. {prepend}
  190. <div className={classNames('status', `status-${status.get('visibility')}`, { muted: this.props.muted })} data-id={status.get('id')}>
  191. <div className='status__info'>
  192. <a href={status.get('url')} className='status__relative-time' target='_blank' rel='noopener'><RelativeTimestamp timestamp={status.get('created_at')} /></a>
  193. <a onClick={this.handleAccountClick} target='_blank' data-id={status.getIn(['account', 'id'])} href={status.getIn(['account', 'url'])} title={status.getIn(['account', 'acct'])} className='status__display-name'>
  194. <div className='status__avatar'>
  195. {statusAvatar}
  196. </div>
  197. <DisplayName account={status.get('account')} />
  198. </a>
  199. </div>
  200. <StatusContent status={status} onClick={this.handleClick} expanded={!status.get('hidden')} onExpandedToggle={this.handleExpandedToggle} />
  201. {media}
  202. <StatusActionBar status={status} account={account} {...other} />
  203. </div>
  204. </div>
  205. </HotKeys>
  206. );
  207. }
  208. }