]> cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/containers/status_container.js
Add dropdown for boost privacy in boost confirmation modal (#15704)
[mastodon.git] / app / javascript / mastodon / containers / status_container.js
1 import React from 'react';
2 import { connect } from 'react-redux';
3 import Status from '../components/status';
4 import { makeGetStatus, makeGetPictureInPicture } from '../selectors';
5 import {
6 replyCompose,
7 mentionCompose,
8 directCompose,
9 } from '../actions/compose';
10 import {
11 reblog,
12 favourite,
13 bookmark,
14 unreblog,
15 unfavourite,
16 unbookmark,
17 pin,
18 unpin,
19 } from '../actions/interactions';
20 import {
21 muteStatus,
22 unmuteStatus,
23 deleteStatus,
24 hideStatus,
25 revealStatus,
26 toggleStatusCollapse,
27 } from '../actions/statuses';
28 import {
29 unmuteAccount,
30 unblockAccount,
31 } from '../actions/accounts';
32 import {
33 blockDomain,
34 unblockDomain,
35 } from '../actions/domain_blocks';
36 import { initMuteModal } from '../actions/mutes';
37 import { initBlockModal } from '../actions/blocks';
38 import { initBoostModal } from '../actions/boosts';
39 import { initReport } from '../actions/reports';
40 import { openModal } from '../actions/modal';
41 import { deployPictureInPicture } from '../actions/picture_in_picture';
42 import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
43 import { boostModal, deleteModal } from '../initial_state';
44 import { showAlertForError } from '../actions/alerts';
45
46 const messages = defineMessages({
47 deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
48 deleteMessage: { id: 'confirmations.delete.message', defaultMessage: 'Are you sure you want to delete this status?' },
49 redraftConfirm: { id: 'confirmations.redraft.confirm', defaultMessage: 'Delete & redraft' },
50 redraftMessage: { id: 'confirmations.redraft.message', defaultMessage: 'Are you sure you want to delete this status and re-draft it? Favourites and boosts will be lost, and replies to the original post will be orphaned.' },
51 replyConfirm: { id: 'confirmations.reply.confirm', defaultMessage: 'Reply' },
52 replyMessage: { id: 'confirmations.reply.message', defaultMessage: 'Replying now will overwrite the message you are currently composing. Are you sure you want to proceed?' },
53 blockDomainConfirm: { id: 'confirmations.domain_block.confirm', defaultMessage: 'Hide entire domain' },
54 });
55
56 const makeMapStateToProps = () => {
57 const getStatus = makeGetStatus();
58 const getPictureInPicture = makeGetPictureInPicture();
59
60 const mapStateToProps = (state, props) => ({
61 status: getStatus(state, props),
62 pictureInPicture: getPictureInPicture(state, props),
63 });
64
65 return mapStateToProps;
66 };
67
68 const mapDispatchToProps = (dispatch, { intl }) => ({
69
70 onReply (status, router) {
71 dispatch((_, getState) => {
72 let state = getState();
73
74 if (state.getIn(['compose', 'text']).trim().length !== 0) {
75 dispatch(openModal('CONFIRM', {
76 message: intl.formatMessage(messages.replyMessage),
77 confirm: intl.formatMessage(messages.replyConfirm),
78 onConfirm: () => dispatch(replyCompose(status, router)),
79 }));
80 } else {
81 dispatch(replyCompose(status, router));
82 }
83 });
84 },
85
86 onModalReblog (status, privacy) {
87 if (status.get('reblogged')) {
88 dispatch(unreblog(status));
89 } else {
90 dispatch(reblog(status, privacy));
91 }
92 },
93
94 onReblog (status, e) {
95 if ((e && e.shiftKey) || !boostModal) {
96 this.onModalReblog(status);
97 } else {
98 dispatch(initBoostModal({ status, onReblog: this.onModalReblog }));
99 }
100 },
101
102 onFavourite (status) {
103 if (status.get('favourited')) {
104 dispatch(unfavourite(status));
105 } else {
106 dispatch(favourite(status));
107 }
108 },
109
110 onBookmark (status) {
111 if (status.get('bookmarked')) {
112 dispatch(unbookmark(status));
113 } else {
114 dispatch(bookmark(status));
115 }
116 },
117
118 onPin (status) {
119 if (status.get('pinned')) {
120 dispatch(unpin(status));
121 } else {
122 dispatch(pin(status));
123 }
124 },
125
126 onEmbed (status) {
127 dispatch(openModal('EMBED', {
128 url: status.get('url'),
129 onError: error => dispatch(showAlertForError(error)),
130 }));
131 },
132
133 onDelete (status, history, withRedraft = false) {
134 if (!deleteModal) {
135 dispatch(deleteStatus(status.get('id'), history, withRedraft));
136 } else {
137 dispatch(openModal('CONFIRM', {
138 message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage),
139 confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm),
140 onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)),
141 }));
142 }
143 },
144
145 onDirect (account, router) {
146 dispatch(directCompose(account, router));
147 },
148
149 onMention (account, router) {
150 dispatch(mentionCompose(account, router));
151 },
152
153 onOpenMedia (statusId, media, index) {
154 dispatch(openModal('MEDIA', { statusId, media, index }));
155 },
156
157 onOpenVideo (statusId, media, options) {
158 dispatch(openModal('VIDEO', { statusId, media, options }));
159 },
160
161 onBlock (status) {
162 const account = status.get('account');
163 dispatch(initBlockModal(account));
164 },
165
166 onUnblock (account) {
167 dispatch(unblockAccount(account.get('id')));
168 },
169
170 onReport (status) {
171 dispatch(initReport(status.get('account'), status));
172 },
173
174 onMute (account) {
175 dispatch(initMuteModal(account));
176 },
177
178 onUnmute (account) {
179 dispatch(unmuteAccount(account.get('id')));
180 },
181
182 onMuteConversation (status) {
183 if (status.get('muted')) {
184 dispatch(unmuteStatus(status.get('id')));
185 } else {
186 dispatch(muteStatus(status.get('id')));
187 }
188 },
189
190 onToggleHidden (status) {
191 if (status.get('hidden')) {
192 dispatch(revealStatus(status.get('id')));
193 } else {
194 dispatch(hideStatus(status.get('id')));
195 }
196 },
197
198 onToggleCollapsed (status, isCollapsed) {
199 dispatch(toggleStatusCollapse(status.get('id'), isCollapsed));
200 },
201
202 onBlockDomain (domain) {
203 dispatch(openModal('CONFIRM', {
204 message: <FormattedMessage id='confirmations.domain_block.message' defaultMessage='Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable. You will not see content from that domain in any public timelines or your notifications. Your followers from that domain will be removed.' values={{ domain: <strong>{domain}</strong> }} />,
205 confirm: intl.formatMessage(messages.blockDomainConfirm),
206 onConfirm: () => dispatch(blockDomain(domain)),
207 }));
208 },
209
210 onUnblockDomain (domain) {
211 dispatch(unblockDomain(domain));
212 },
213
214 deployPictureInPicture (status, type, mediaProps) {
215 dispatch(deployPictureInPicture(status.get('id'), status.getIn(['account', 'id']), type, mediaProps));
216 },
217
218 });
219
220 export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Status));
This page took 0.169427 seconds and 4 git commands to generate.