about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/components/status.js
blob: 800832dc8e4f9c701449ef51eb3f829b89c84230 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
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';
import StatusIcons from './status_icons';
import StatusContent from './status_content';
import StatusActionBar from './status_action_bar';
import AttachmentList from './attachment_list';
import Card from '../features/status/components/card';
import { injectIntl, FormattedMessage } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { MediaGallery, Video, Audio } from '../features/ui/util/async-components';
import { HotKeys } from 'react-hotkeys';
import NotificationOverlayContainer from 'flavours/glitch/features/notifications/containers/overlay_container';
import classNames from 'classnames';
import { autoUnfoldCW } from 'flavours/glitch/utils/content_warning';
import PollContainer from 'flavours/glitch/containers/poll_container';
import { displayMedia } from 'flavours/glitch/initial_state';
import PictureInPicturePlaceholder from 'flavours/glitch/components/picture_in_picture_placeholder';

// 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';

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(', ');
};

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');
}

export default @injectIntl
class Status extends ImmutablePureComponent {

  static contextTypes = {
    router: PropTypes.object,
  };

  static propTypes = {
    containerId: PropTypes.string,
    id: PropTypes.string,
    status: ImmutablePropTypes.map,
    account: ImmutablePropTypes.map,
    onReply: PropTypes.func,
    onFavourite: PropTypes.func,
    onReblog: PropTypes.func,
    onBookmark: PropTypes.func,
    onDelete: PropTypes.func,
    onDirect: PropTypes.func,
    onMention: PropTypes.func,
    onPin: PropTypes.func,
    onOpenMedia: PropTypes.func,
    onOpenVideo: PropTypes.func,
    onBlock: PropTypes.func,
    onAddFilter: PropTypes.func,
    onEmbed: PropTypes.func,
    onHeightChange: PropTypes.func,
    onToggleHidden: PropTypes.func,
    onInteractionModal: PropTypes.func,
    muted: PropTypes.bool,
    hidden: PropTypes.bool,
    unread: PropTypes.bool,
    prepend: PropTypes.string,
    withDismiss: PropTypes.bool,
    onMoveUp: PropTypes.func,
    onMoveDown: PropTypes.func,
    getScrollPosition: PropTypes.func,
    updateScrollBottom: PropTypes.func,
    expanded: PropTypes.bool,
    intl: PropTypes.object.isRequired,
    cacheMediaWidth: PropTypes.func,
    cachedMediaWidth: PropTypes.number,
    onClick: PropTypes.func,
    scrollKey: PropTypes.string,
    deployPictureInPicture: PropTypes.func,
    settings: ImmutablePropTypes.map.isRequired,
    pictureInPicture: PropTypes.shape({
      inUse: PropTypes.bool,
      available: PropTypes.bool,
    }),
  };

  state = {
    isCollapsed: false,
    autoCollapsed: false,
    isExpanded: undefined,
    showMedia: undefined,
    statusId: undefined,
    revealBehindCW: undefined,
    showCard: false,
    forceFilter: undefined,
  }

  // 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',
    'notification',
    'hidden',
    'expanded',
    'unread',
    'pictureInPicture',
  ]

  updateOnStates = [
    'isExpanded',
    'isCollapsed',
    'showMedia',
    'forceFilter',
  ]

  //  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
  //  `getderivedStateFromProps()`.

  //  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.
  static getDerivedStateFromProps(nextProps, prevState) {
    let update = {};
    let updated = false;

    // Make sure the state mirrors props we track…
    if (nextProps.expanded !== prevState.expandedProp) {
      update.expandedProp = nextProps.expanded;
      updated = true;
    }
    if (nextProps.status?.get('hidden') !== prevState.statusPropHidden) {
      update.statusPropHidden = nextProps.status?.get('hidden');
      updated = true;
    }

    // Update state based on new props
    if (!nextProps.settings.getIn(['collapsed', 'enabled'])) {
      if (prevState.isCollapsed) {
        update.isCollapsed = false;
        updated = true;
      }
    }

    // Handle uncollapsing toots when the shared CW state is expanded
    if (nextProps.settings.getIn(['content_warnings', 'shared_state']) &&
      nextProps.status?.get('spoiler_text')?.length && nextProps.status?.get('hidden') === false &&
      prevState.statusPropHidden !== false && prevState.isCollapsed
    ) {
      update.isCollapsed = false;
      updated = true;
    }

    // The “expanded” prop is used to one-off change the local state.
    // It's used in the thread view when unfolding/re-folding all CWs at once.
    if (nextProps.expanded !== prevState.expandedProp &&
      nextProps.expanded !== undefined
    ) {
      update.isExpanded = nextProps.expanded;
      if (nextProps.expanded) update.isCollapsed = false;
      updated = true;
    }

    if (prevState.isExpanded === undefined && update.isExpanded === undefined) {
      update.isExpanded = autoUnfoldCW(nextProps.settings, nextProps.status);
      updated = true;
    }

    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;
    }

    return updated ? update : null;
  }

  //  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 `setCollapsed()` 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.
  //   -  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;

    // Prevent a crash when node is undefined. Not completely sure why this
    // happens, might be because status === null.
    if (node === undefined) return;

    const autoCollapseSettings = settings.getIn(['collapsed', 'auto']);

    // Don't autocollapse if CW state is shared and status is explicitly revealed,
    // as it could cause surprising changes when receiving notifications
    if (settings.getIn(['content_warnings', 'shared_state']) && status.get('spoiler_text').length && !status.get('hidden')) return;

    if (collapse ||
      autoCollapseSettings.get('all') ||
      (autoCollapseSettings.get('notifications') && muted) ||
      (autoCollapseSettings.get('lengthy') && node.clientHeight > ((status.get('media_attachments').size && !muted) ? 650 : 400)) ||
      (autoCollapseSettings.get('reblogs') && prepend === 'reblogged_by') ||
      (autoCollapseSettings.get('replies') && status.get('in_reply_to_id', null) !== null) ||
      (autoCollapseSettings.get('media') && !(status.get('spoiler_text').length) && status.get('media_attachments').size > 0)
    ) {
      this.setCollapsed(true);
      // Hack to fix timeline jumps on second rendering when auto-collapsing
      this.setState({ autoCollapsed: true });
    }

    // 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'),
    });
  }

  //  Hack to fix timeline jumps on second rendering when auto-collapsing
  //  or on subsequent rendering when a preview card has been fetched
  getSnapshotBeforeUpdate (prevProps, prevState) {
    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 });
      return this.props.getScrollPosition();
    } else {
      return null;
    }
  }

  componentDidUpdate (prevProps, prevState, snapshot) {
    if (snapshot !== null && this.props.updateScrollBottom && this.node.offsetTop < snapshot.top) {
      this.props.updateScrollBottom(snapshot.height - snapshot.top);
    }
  }

  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); });
      }
    }
  }

  //  `setCollapsed()` sets the value of `isCollapsed` in our state, that is,
  //  whether the toot is collapsed or not.

  //  `setCollapsed()` automatically checks for us whether toot collapsing
  //  is enabled, so we don't have to.
  setCollapsed = (value) => {
    if (this.props.settings.getIn(['collapsed', 'enabled'])) {
      if (value) {
        this.setExpansion(false);
      }
      this.setState({ isCollapsed: value });
    } else {
      this.setState({ isCollapsed: false });
    }
  }

  setExpansion = (value) => {
    if (this.props.settings.getIn(['content_warnings', 'shared_state']) && this.props.status.get('hidden') === value) {
      this.props.onToggleHidden(this.props.status);
    }

    this.setState({ isExpanded: value });
    if (value) {
      this.setCollapsed(false);
    }
  }

  //  `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 { isCollapsed } = this.state;
    if (!router) return;

    if (e.button === 0 && !(e.ctrlKey || e.altKey || e.metaKey)) {
      if (isCollapsed) this.setCollapsed(false);
      else if (e.shiftKey) {
        this.setCollapsed(true);
        document.getSelection().removeAllRanges();
      } else if (this.props.onClick) {
        this.props.onClick();
        return;
      } else {
        if (destination === undefined) {
          destination = `/@${
            status.getIn(['reblog', 'account', 'acct'], status.getIn(['account', 'acct']))
          }/${
            status.getIn(['reblog', 'id'], status.get('id'))
          }`;
        }
        let state = {...router.history.location.state};
        state.mastodonBackSteps = (state.mastodonBackSteps || 0) + 1;
        router.history.push(destination, state);
      }
      e.preventDefault();
    }
  }

  handleToggleMediaVisibility = () => {
    this.setState({ showMedia: !this.state.showMedia });
  }

  handleExpandedToggle = () => {
    if (this.props.settings.getIn(['content_warnings', 'shared_state'])) {
      this.props.onToggleHidden(this.props.status);
    } else if (this.props.status.get('spoiler_text')) {
      this.setExpansion(!this.state.isExpanded);
    }
  };

  handleOpenVideo = (options) => {
    const { status } = this.props;
    this.props.onOpenVideo(status.get('id'), status.getIn(['media_attachments', 0]), options);
  }

  handleOpenMedia = (media, index) => {
    this.props.onOpenMedia(this.props.status.get('id'), media, index);
  }

  handleHotkeyOpenMedia = e => {
    const { status, onOpenMedia, onOpenVideo } = this.props;
    const statusId = status.get('id');

    e.preventDefault();

    if (status.get('media_attachments').size > 0) {
      if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
        onOpenVideo(statusId, status.getIn(['media_attachments', 0]), { startTime: 0 });
      } else {
        onOpenMedia(statusId, status.get('media_attachments'), 0);
      }
    }
  }

  handleDeployPictureInPicture = (type, mediaProps) => {
    const { deployPictureInPicture, status } = this.props;

    deployPictureInPicture(status, type, mediaProps);
  }

  handleHotkeyReply = e => {
    e.preventDefault();
    this.props.onReply(this.props.status, this.context.router.history);
  }

  handleHotkeyFavourite = (e) => {
    this.props.onFavourite(this.props.status, e);
  }

  handleHotkeyBoost = e => {
    this.props.onReblog(this.props.status, e);
  }

  handleHotkeyBookmark = e => {
    this.props.onBookmark(this.props.status, e);
  }

  handleHotkeyMention = e => {
    e.preventDefault();
    this.props.onMention(this.props.status.get('account'), this.context.router.history);
  }

  handleHotkeyOpen = () => {
    let state = {...this.context.router.history.location.state};
    state.mastodonBackSteps = (state.mastodonBackSteps || 0) + 1;
    const status = this.props.status;
    this.context.router.history.push(`/@${status.getIn(['account', 'acct'])}/${status.get('id')}`, state);
  }

  handleHotkeyOpenProfile = () => {
    let state = {...this.context.router.history.location.state};
    state.mastodonBackSteps = (state.mastodonBackSteps || 0) + 1;
    this.context.router.history.push(`/@${this.props.status.getIn(['account', 'acct'])}`, state);
  }

  handleHotkeyMoveUp = e => {
    this.props.onMoveUp(this.props.containerId || this.props.id, e.target.getAttribute('data-featured'));
  }

  handleHotkeyMoveDown = e => {
    this.props.onMoveDown(this.props.containerId || this.props.id, e.target.getAttribute('data-featured'));
  }

  handleHotkeyCollapse = e => {
    if (!this.props.settings.getIn(['collapsed', 'enabled']))
      return;

    this.setCollapsed(!this.state.isCollapsed);
  }

  handleHotkeyToggleSensitive = () => {
    this.handleToggleMediaVisibility();
  }

  handleUnfilterClick = e => {
    this.setState({ forceFilter: false });
    e.preventDefault();
  }

  handleFilterClick = () => {
    this.setState({ forceFilter: true });
  }

  handleRef = c => {
    this.node = c;
  }

  renderLoadingMediaGallery () {
    return <div className='media-gallery' style={{ height: '110px' }} />;
  }

  renderLoadingVideoPlayer () {
    return <div className='video-player' style={{ height: '110px' }} />;
  }

  renderLoadingAudioPlayer () {
    return <div className='audio-player' style={{ height: '110px' }} />;
  }

  render () {
    const {
      handleRef,
      parseClick,
      setExpansion,
      setCollapsed,
    } = this;
    const { router } = this.context;
    const {
      intl,
      status,
      account,
      settings,
      collapsed,
      muted,
      intersectionObserverWrapper,
      onOpenVideo,
      onOpenMedia,
      notification,
      hidden,
      unread,
      featured,
      pictureInPicture,
      ...other
    } = this.props;
    const { isCollapsed, forceFilter } = this.state;
    let background = null;
    let attachments = null;

    //  Depending on user settings, some media are considered as parts of the
    //  contents (affected by CW) while other will be displayed outside of the
    //  CW.
    let contentMedia = [];
    let contentMediaIcons = [];
    let extraMedia = [];
    let extraMediaIcons = [];
    let media = contentMedia;
    let mediaIcons = contentMediaIcons;

    if (settings.getIn(['content_warnings', 'media_outside'])) {
      media = extraMedia;
      mediaIcons = extraMediaIcons;
    }

    if (status === null) {
      return null;
    }

    const isExpanded = settings.getIn(['content_warnings', 'shared_state']) ? !status.get('hidden') : this.state.isExpanded;

    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,
      openMedia: this.handleHotkeyOpenMedia,
    };

    if (hidden) {
      return (
        <HotKeys handlers={handlers}>
          <div ref={this.handleRef} className='status focusable' tabIndex='0'>
            <span>{status.getIn(['account', 'display_name']) || status.getIn(['account', 'username'])}</span>
            <span>{status.get('content')}</span>
          </div>
        </HotKeys>
      );
    }

    const matchedFilters = status.get('matched_filters');
    if (this.state.forceFilter === undefined ? matchedFilters : this.state.forceFilter) {
      const minHandlers = this.props.muted ? {} : {
        moveUp: this.handleHotkeyMoveUp,
        moveDown: this.handleHotkeyMoveDown,
      };

      return (
        <HotKeys handlers={minHandlers}>
          <div className='status__wrapper status__wrapper--filtered focusable' tabIndex='0' ref={this.handleRef}>
            <FormattedMessage id='status.filtered' defaultMessage='Filtered' />: {matchedFilters.join(', ')}.
            {' '}
            <button className='status__wrapper--filtered__button' onClick={this.handleUnfilterClick}>
              <FormattedMessage id='status.show_filter_reason' defaultMessage='Show anyway' />
            </button>
          </div>
        </HotKeys>
      );
    }

    //  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.
    //  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.

    //  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 (pictureInPicture.inUse) {
      media.push(<PictureInPicturePlaceholder width={this.props.cachedMediaWidth} />);
      mediaIcons.push('video-camera');
    } else if (attachments.size > 0) {
      if (muted || attachments.some(item => item.get('type') === 'unknown')) {
        media.push(
          <AttachmentList
            compact
            media={status.get('media_attachments')}
          />,
        );
      } else if (attachments.getIn([0, 'type']) === 'audio') {
        const attachment = status.getIn(['media_attachments', 0]);

        media.push(
          <Bundle fetchComponent={Audio} loading={this.renderLoadingAudioPlayer} >
            {Component => (
              <Component
                src={attachment.get('url')}
                alt={attachment.get('description')}
                poster={attachment.get('preview_url') || status.getIn(['account', 'avatar_static'])}
                backgroundColor={attachment.getIn(['meta', 'colors', 'background'])}
                foregroundColor={attachment.getIn(['meta', 'colors', 'foreground'])}
                accentColor={attachment.getIn(['meta', 'colors', 'accent'])}
                duration={attachment.getIn(['meta', 'original', 'duration'], 0)}
                width={this.props.cachedMediaWidth}
                height={110}
                cacheWidth={this.props.cacheMediaWidth}
                deployPictureInPicture={pictureInPicture.available ? this.handleDeployPictureInPicture : undefined}
                sensitive={status.get('sensitive')}
                blurhash={attachment.get('blurhash')}
                visible={this.state.showMedia}
                onToggleVisibility={this.handleToggleMediaVisibility}
              />
            )}
          </Bundle>,
        );
        mediaIcons.push('music');
      } else if (attachments.getIn([0, 'type']) === 'video') {
        const attachment = status.getIn(['media_attachments', 0]);

        media.push(
          <Bundle fetchComponent={Video} loading={this.renderLoadingVideoPlayer} >
            {Component => (<Component
              preview={attachment.get('preview_url')}
              frameRate={attachment.getIn(['meta', 'original', 'frame_rate'])}
              blurhash={attachment.get('blurhash')}
              src={attachment.get('url')}
              alt={attachment.get('description')}
              inline
              sensitive={status.get('sensitive')}
              letterbox={settings.getIn(['media', 'letterbox'])}
              fullwidth={settings.getIn(['media', 'fullwidth'])}
              preventPlayback={isCollapsed || !isExpanded}
              onOpenVideo={this.handleOpenVideo}
              width={this.props.cachedMediaWidth}
              cacheWidth={this.props.cacheMediaWidth}
              deployPictureInPicture={pictureInPicture.available ? this.handleDeployPictureInPicture : undefined}
              visible={this.state.showMedia}
              onToggleVisibility={this.handleToggleMediaVisibility}
            />)}
          </Bundle>,
        );
        mediaIcons.push('video-camera');
      } else {  //  Media type is 'image' or 'gifv'
        media.push(
          <Bundle fetchComponent={MediaGallery} loading={this.renderLoadingMediaGallery}>
            {Component => (
              <Component
                media={attachments}
                sensitive={status.get('sensitive')}
                letterbox={settings.getIn(['media', 'letterbox'])}
                fullwidth={settings.getIn(['media', 'fullwidth'])}
                hidden={isCollapsed || !isExpanded}
                onOpenMedia={this.handleOpenMedia}
                cacheWidth={this.props.cacheMediaWidth}
                defaultWidth={this.props.cachedMediaWidth}
                visible={this.state.showMedia}
                onToggleVisibility={this.handleToggleMediaVisibility}
              />
            )}
          </Bundle>,
        );
        mediaIcons.push('picture-o');
      }

      if (!status.get('sensitive') && !(status.get('spoiler_text').length > 0) && settings.getIn(['collapsed', 'backgrounds', 'preview_images'])) {
        background = attachments.getIn([0, 'preview_url']);
      }
    } else if (status.get('card') && settings.get('inline_preview_cards') && !this.props.muted) {
      media.push(
        <Card
          onOpenMedia={this.handleOpenMedia}
          card={status.get('card')}
          compact
          cacheWidth={this.props.cacheMediaWidth}
          defaultWidth={this.props.cachedMediaWidth}
          sensitive={status.get('sensitive')}
        />,
      );
      mediaIcons.push('link');
    }

    if (status.get('poll')) {
      contentMedia.push(<PollContainer pollId={status.get('poll')} />);
      contentMediaIcons.push('tasks');
    }

    //  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'])}`,
    };

    let prepend;

    if (this.props.prepend && account) {
      const notifKind = {
        favourite: 'favourited',
        reblog: 'boosted',
        reblogged_by: 'boosted',
        status: 'posted',
      }[this.props.prepend];

      selectorAttribs[`data-${notifKind}-by`] = `@${account.get('acct')}`;

      prepend = (
        <StatusPrepend
          type={this.props.prepend}
          account={account}
          parseClick={parseClick}
          notificationId={this.props.notificationId}
        />
      );
    }

    let rebloggedByText;

    if (this.props.prepend === 'reblog') {
      rebloggedByText = intl.formatMessage({ id: 'status.reblogged_by', defaultMessage: '{name} boosted' }, { name: account.get('acct') });
    }

    const computedClass = classNames('status', `status-${status.get('visibility')}`, {
      collapsed: isCollapsed,
      'has-background': isCollapsed && background,
      'status__wrapper-reply': !!status.get('in_reply_to_id'),
      unread,
      muted,
    }, 'focusable');

    return (
      <HotKeys handlers={handlers}>
        <div
          className={computedClass}
          style={isCollapsed && background ? { backgroundImage: `url(${background})` } : null}
          {...selectorAttribs}
          ref={handleRef}
          tabIndex='0'
          data-featured={featured ? 'true' : null}
          aria-label={textForScreenReader(intl, status, rebloggedByText, !status.get('hidden'))}
        >
          {!muted && prepend}
          <header className='status__info'>
            <span>
              {muted && prepend}
              {!muted || !isCollapsed ? (
                <StatusHeader
                  status={status}
                  friend={account}
                  collapsed={isCollapsed}
                  parseClick={parseClick}
                />
              ) : null}
            </span>
            <StatusIcons
              status={status}
              mediaIcons={contentMediaIcons.concat(extraMediaIcons)}
              collapsible={settings.getIn(['collapsed', 'enabled'])}
              collapsed={isCollapsed}
              setCollapsed={setCollapsed}
              settings={settings.get('status_icons')}
            />
          </header>
          <StatusContent
            status={status}
            media={contentMedia}
            extraMedia={extraMedia}
            mediaIcons={contentMediaIcons}
            expanded={isExpanded}
            onExpandedToggle={this.handleExpandedToggle}
            parseClick={parseClick}
            disabled={!router}
            tagLinks={settings.get('tag_misleading_links')}
            rewriteMentions={settings.get('rewrite_mentions')}
          />

          {!isCollapsed || !(muted || !settings.getIn(['collapsed', 'show_action_bar'])) ? (
            <StatusActionBar
              status={status}
              account={status.get('account')}
              showReplyCount={settings.get('show_reply_count')}
              onFilter={matchedFilters ? this.handleFilterClick : null}
              {...other}
            />
          ) : null}
          {notification ? (
            <NotificationOverlayContainer
              notification={notification}
            />
          ) : null}
        </div>
      </HotKeys>
    );
  }

}