Skip to content

Commit dd05d5a

Browse files
ClearlyClaireGargron
authored andcommitted
Put poll options behind content warnings (mastodon#10983)
* Put poll options behind CWs in WebUI * Put polls behind CWs on public pages * Add poll icon to public pages CWs * Revert to not showing an icon in the CW button
1 parent e476636 commit dd05d5a

6 files changed

Lines changed: 36 additions & 27 deletions

File tree

app/javascript/mastodon/components/status.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { MediaGallery, Video } from '../features/ui/util/async-components';
1616
import { HotKeys } from 'react-hotkeys';
1717
import classNames from 'classnames';
1818
import Icon from 'mastodon/components/icon';
19-
import PollContainer from 'mastodon/containers/poll_container';
2019
import { displayMedia } from '../initial_state';
2120

2221
// We use the component (and not the container) since we do not want
@@ -321,9 +320,7 @@ class Status extends ImmutablePureComponent {
321320
status = status.get('reblog');
322321
}
323322

324-
if (status.get('poll')) {
325-
media = <PollContainer pollId={status.get('poll')} />;
326-
} else if (status.get('media_attachments').size > 0) {
323+
if (status.get('media_attachments').size > 0) {
327324
if (this.props.muted) {
328325
media = (
329326
<AttachmentList

app/javascript/mastodon/components/status_content.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { isRtl } from '../rtl';
55
import { FormattedMessage } from 'react-intl';
66
import Permalink from './permalink';
77
import classnames from 'classnames';
8+
import PollContainer from 'mastodon/containers/poll_container';
89
import Icon from 'mastodon/components/icon';
910

1011
const MAX_HEIGHT = 642; // 20px * 32 (+ 2px padding at the top)
@@ -191,6 +192,8 @@ export default class StatusContent extends React.PureComponent {
191192
{mentionsPlaceholder}
192193

193194
<div tabIndex={!hidden ? 0 : null} className={`status__content__text ${!hidden ? 'status__content__text--visible' : ''}`} style={directionStyle} dangerouslySetInnerHTML={content} lang={status.get('language')} />
195+
196+
{!hidden && !!status.get('poll') && <PollContainer pollId={status.get('poll')} />}
194197
</div>
195198
);
196199
} else if (this.props.onClick) {
@@ -212,18 +215,28 @@ export default class StatusContent extends React.PureComponent {
212215
output.push(readMoreButton);
213216
}
214217

218+
if (status.get('poll')) {
219+
output.push(<PollContainer pollId={status.get('poll')} />);
220+
}
221+
215222
return output;
216223
} else {
217-
return (
224+
const output = [
218225
<div
219226
tabIndex='0'
220227
ref={this.setRef}
221228
className='status__content'
222229
style={directionStyle}
223230
dangerouslySetInnerHTML={content}
224231
lang={status.get('language')}
225-
/>
226-
);
232+
/>,
233+
];
234+
235+
if (status.get('poll')) {
236+
output.push(<PollContainer pollId={status.get('poll')} />);
237+
}
238+
239+
return output;
227240
}
228241
}
229242

app/javascript/mastodon/features/status/components/detailed_status.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import Video from '../../video';
1313
import scheduleIdleTask from '../../ui/util/schedule_idle_task';
1414
import classNames from 'classnames';
1515
import Icon from 'mastodon/components/icon';
16-
import PollContainer from 'mastodon/containers/poll_container';
1716

1817
export default class DetailedStatus extends ImmutablePureComponent {
1918

@@ -107,9 +106,7 @@ export default class DetailedStatus extends ImmutablePureComponent {
107106
outerStyle.height = `${this.state.height}px`;
108107
}
109108

110-
if (status.get('poll')) {
111-
media = <PollContainer pollId={status.get('poll')} />;
112-
} else if (status.get('media_attachments').size > 0) {
109+
if (status.get('media_attachments').size > 0) {
113110
if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
114111
const video = status.getIn(['media_attachments', 0]);
115112

app/javascript/packs/public.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ function main() {
126126
return false;
127127
});
128128

129-
delegate(document, '.status__content__spoiler-link', 'click', ({ target }) => {
130-
const contentEl = target.parentNode.parentNode.querySelector('.e-content');
129+
delegate(document, '.status__content__spoiler-link', 'click', function() {
130+
const contentEl = this.parentNode.parentNode.querySelector('.e-content');
131131

132132
if (contentEl.style.display === 'block') {
133133
contentEl.style.display = 'none';
134-
target.parentNode.style.marginBottom = 0;
134+
this.parentNode.style.marginBottom = 0;
135135
} else {
136136
contentEl.style.display = 'block';
137-
target.parentNode.style.marginBottom = null;
137+
this.parentNode.style.marginBottom = null;
138138
}
139139

140140
return false;

app/views/stream_entries/_detailed_status.html.haml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
- if status.spoiler_text?
2020
%p{ :style => ('margin-bottom: 0' unless current_account&.user&.setting_expand_spoilers) }<
2121
%span.p-summary> #{Formatter.instance.format_spoiler(status, autoplay: autoplay)}&nbsp;
22-
%a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more')
23-
.e-content{ lang: status.language, style: "display: #{!current_account&.user&.setting_expand_spoilers && status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl_status?(status) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status, custom_emojify: true, autoplay: autoplay)
22+
%button.status__content__spoiler-link= t('statuses.show_more')
23+
.e-content{ lang: status.language, style: "display: #{!current_account&.user&.setting_expand_spoilers && status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl_status?(status) ? 'rtl' : 'ltr'}" }
24+
= Formatter.instance.format(status, custom_emojify: true, autoplay: autoplay)
25+
- if status.preloadable_poll
26+
= react_component :poll, disabled: true, poll: ActiveModelSerializers::SerializableResource.new(status.preloadable_poll, serializer: REST::PollSerializer, scope: current_user, scope_name: :current_user).as_json do
27+
= render partial: 'stream_entries/poll', locals: { status: status, poll: status.preloadable_poll, autoplay: autoplay }
2428

25-
- if status.preloadable_poll
26-
= react_component :poll, disabled: true, poll: ActiveModelSerializers::SerializableResource.new(status.preloadable_poll, serializer: REST::PollSerializer, scope: current_user, scope_name: :current_user).as_json do
27-
= render partial: 'stream_entries/poll', locals: { status: status, poll: status.preloadable_poll, autoplay: autoplay }
28-
- elsif !status.media_attachments.empty?
29+
- if !status.media_attachments.empty?
2930
- if status.media_attachments.first.video?
3031
- video = status.media_attachments.first
3132
= react_component :video, src: video.file.url(:original), preview: video.file.url(:small), blurhash: video.blurhash, sensitive: !current_account&.user&.show_all_media? && status.sensitive? || current_account&.user&.hide_all_media?, width: 670, height: 380, detailed: true, inline: true, alt: video.description do

app/views/stream_entries/_simple_status.html.haml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
- if status.spoiler_text?
2424
%p{ :style => ('margin-bottom: 0' unless current_account&.user&.setting_expand_spoilers) }<
2525
%span.p-summary> #{Formatter.instance.format_spoiler(status, autoplay: autoplay)}&nbsp;
26-
%a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more')
27-
.e-content{ lang: status.language, style: "display: #{!current_account&.user&.setting_expand_spoilers && status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl_status?(status) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status, custom_emojify: true, autoplay: autoplay)
26+
%button.status__content__spoiler-link= t('statuses.show_more')
27+
.e-content{ lang: status.language, style: "display: #{!current_account&.user&.setting_expand_spoilers && status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl_status?(status) ? 'rtl' : 'ltr'}" }
28+
= Formatter.instance.format(status, custom_emojify: true, autoplay: autoplay)
29+
- if status.preloadable_poll
30+
= react_component :poll, disabled: true, poll: ActiveModelSerializers::SerializableResource.new(status.preloadable_poll, serializer: REST::PollSerializer, scope: current_user, scope_name: :current_user).as_json do
31+
= render partial: 'stream_entries/poll', locals: { status: status, poll: status.preloadable_poll, autoplay: autoplay }
2832

29-
- if status.preloadable_poll
30-
= react_component :poll, disabled: true, poll: ActiveModelSerializers::SerializableResource.new(status.preloadable_poll, serializer: REST::PollSerializer, scope: current_user, scope_name: :current_user).as_json do
31-
= render partial: 'stream_entries/poll', locals: { status: status, poll: status.preloadable_poll, autoplay: autoplay }
32-
- elsif !status.media_attachments.empty?
33+
- if !status.media_attachments.empty?
3334
- if status.media_attachments.first.video?
3435
- video = status.media_attachments.first
3536
= react_component :video, src: video.file.url(:original), preview: video.file.url(:small), blurhash: video.blurhash, sensitive: !current_account&.user&.show_all_media? && status.sensitive? || current_account&.user&.hide_all_media?, width: 610, height: 343, inline: true, alt: video.description do

0 commit comments

Comments
 (0)