]> cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/containers/status_container.js
Summary: fix slowness due to layout thrashing when reloading a large … (#12661)
[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 } 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 { initReport } from '../actions/reports';
39 import { openModal } from '../actions/modal';
40 import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
41 import { boostModal, deleteModal } from '../initial_state';
42 import { showAlertForError } from '../actions/alerts';
43
44 const messages = defineMessages({
45 deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
46 deleteMessage: { id: 'confirmations.delete.message', defaultMessage: 'Are you sure you want to delete this status?' },
47 redraftConfirm: { id: 'confirmations.redraft.confirm', defaultMessage: 'Delete & redraft' },
48 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.' },
49 replyConfirm: { id: 'confirmations.reply.confirm', defaultMessage: 'Reply' },
50 replyMessage: { id: 'confirmations.reply.message', defaultMessage: 'Replying now will overwrite the message you are currently composing. Are you sure you want to proceed?' },
51 blockDomainConfirm: { id: 'confirmations.domain_block.confirm', defaultMessage: 'Hide entire domain' },
52 });
53
54 const makeMapStateToProps = () => {
55 const getStatus = makeGetStatus();
56
57 const mapStateToProps = (state, props) => ({
58 status: getStatus(state, props),
59 });
60
61 return mapStateToProps;
62 };
63
64 const mapDispatchToProps = (dispatch, { intl }) => ({
65
66 onReply (status, router) {
67 dispatch((_, getState) => {
68 let state = getState();
69
70 if (state.getIn(['compose', 'text']).trim().length !== 0) {
71 dispatch(openModal('CONFIRM', {
72 message: intl.formatMessage(messages.replyMessage),
73 confirm: intl.formatMessage(messages.replyConfirm),
74 onConfirm: () => dispatch(replyCompose(status, router)),
75 }));
76 } else {
77 dispatch(replyCompose(status, router));
78 }
79 });
80 },
81
82 onModalReblog (status) {
83 if (status.get('reblogged')) {
84 dispatch(unreblog(status));
85 } else {
86 dispatch(reblog(status));
87 }
88 },
89
90 onReblog (status, e) {
91 if ((e && e.shiftKey) || !boostModal) {
92 this.onModalReblog(status);
93 } else {
94 dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
95 }
96 },
97
98 onFavourite (status) {
99 if (status.get('favourited')) {
100 dispatch(unfavourite(status));
101 } else {
102 dispatch(favourite(status));
103 }
104 },
105
106 onBookmark (status) {
107 if (status.get('bookmarked')) {
108 dispatch(unbookmark(status));
109 } else {
110 dispatch(bookmark(status));
111 }
112 },
113
114 onPin (status) {
115 if (status.get('pinned')) {
116 dispatch(unpin(status));
117 } else {
118 dispatch(pin(status));
119 }
120 },
121
122 onEmbed (status) {
123 dispatch(openModal('EMBED', {
124 url: status.get('url'),
125 onError: error => dispatch(showAlertForError(error)),
126 }));
127 },
128
129 onDelete (status, history, withRedraft = false) {
130 if (!deleteModal) {
131 dispatch(deleteStatus(status.get('id'), history, withRedraft));
132 } else {
133 dispatch(openModal('CONFIRM', {
134 message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage),
135 confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm),
136 onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)),
137 }));
138 }
139 },
140
141 onDirect (account, router) {
142 dispatch(directCompose(account, router));
143 },
144
145 onMention (account, router) {
146 dispatch(mentionCompose(account, router));
147 },
148
149 onOpenMedia (media, index) {
150 dispatch(openModal('MEDIA', { media, index }));
151 },
152
153 onOpenVideo (media, time) {
154 dispatch(openModal('VIDEO', { media, time }));
155 },
156
157 onBlock (status) {
158 const account = status.get('account');
159 dispatch(initBlockModal(account));
160 },
161
162 onUnblock (account) {
163 dispatch(unblockAccount(account.get('id')));
164 },
165
166 onReport (status) {
167 dispatch(initReport(status.get('account'), status));
168 },
169
170 onMute (account) {
171 dispatch(initMuteModal(account));
172 },
173
174 onUnmute (account) {
175 dispatch(unmuteAccount(account.get('id')));
176 },
177
178 onMuteConversation (status) {
179 if (status.get('muted')) {
180 dispatch(unmuteStatus(status.get('id')));
181 } else {
182 dispatch(muteStatus(status.get('id')));
183 }
184 },
185
186 onToggleHidden (status) {
187 if (status.get('hidden')) {
188 dispatch(revealStatus(status.get('id')));
189 } else {
190 dispatch(hideStatus(status.get('id')));
191 }
192 },
193
194 onToggleCollapsed (status, isCollapsed) {
195 dispatch(toggleStatusCollapse(status.get('id'), isCollapsed));
196 },
197
198 onBlockDomain (domain) {
199 dispatch(openModal('CONFIRM', {
200 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> }} />,
201 confirm: intl.formatMessage(messages.blockDomainConfirm),
202 onConfirm: () => dispatch(blockDomain(domain)),
203 }));
204 },
205
206 onUnblockDomain (domain) {
207 dispatch(unblockDomain(domain));
208 },
209
210 });
211
212 export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Status));
This page took 0.114892 seconds and 5 git commands to generate.