1 import api
from '../api';
6 refreshCommunityTimeline
,
10 export const COMPOSE_CHANGE
= 'COMPOSE_CHANGE';
11 export const COMPOSE_SUBMIT_REQUEST
= 'COMPOSE_SUBMIT_REQUEST';
12 export const COMPOSE_SUBMIT_SUCCESS
= 'COMPOSE_SUBMIT_SUCCESS';
13 export const COMPOSE_SUBMIT_FAIL
= 'COMPOSE_SUBMIT_FAIL';
14 export const COMPOSE_REPLY
= 'COMPOSE_REPLY';
15 export const COMPOSE_REPLY_CANCEL
= 'COMPOSE_REPLY_CANCEL';
16 export const COMPOSE_MENTION
= 'COMPOSE_MENTION';
17 export const COMPOSE_UPLOAD_REQUEST
= 'COMPOSE_UPLOAD_REQUEST';
18 export const COMPOSE_UPLOAD_SUCCESS
= 'COMPOSE_UPLOAD_SUCCESS';
19 export const COMPOSE_UPLOAD_FAIL
= 'COMPOSE_UPLOAD_FAIL';
20 export const COMPOSE_UPLOAD_PROGRESS
= 'COMPOSE_UPLOAD_PROGRESS';
21 export const COMPOSE_UPLOAD_UNDO
= 'COMPOSE_UPLOAD_UNDO';
23 export const COMPOSE_SUGGESTIONS_CLEAR
= 'COMPOSE_SUGGESTIONS_CLEAR';
24 export const COMPOSE_SUGGESTIONS_READY
= 'COMPOSE_SUGGESTIONS_READY';
25 export const COMPOSE_SUGGESTION_SELECT
= 'COMPOSE_SUGGESTION_SELECT';
27 export const COMPOSE_MOUNT
= 'COMPOSE_MOUNT';
28 export const COMPOSE_UNMOUNT
= 'COMPOSE_UNMOUNT';
30 export const COMPOSE_ADVANCED_OPTIONS_CHANGE
= 'COMPOSE_ADVANCED_OPTIONS_CHANGE';
31 export const COMPOSE_SENSITIVITY_CHANGE
= 'COMPOSE_SENSITIVITY_CHANGE';
32 export const COMPOSE_SPOILERNESS_CHANGE
= 'COMPOSE_SPOILERNESS_CHANGE';
33 export const COMPOSE_SPOILER_TEXT_CHANGE
= 'COMPOSE_SPOILER_TEXT_CHANGE';
34 export const COMPOSE_VISIBILITY_CHANGE
= 'COMPOSE_VISIBILITY_CHANGE';
35 export const COMPOSE_LISTABILITY_CHANGE
= 'COMPOSE_LISTABILITY_CHANGE';
36 export const COMPOSE_COMPOSING_CHANGE
= 'COMPOSE_COMPOSING_CHANGE';
38 export const COMPOSE_EMOJI_INSERT
= 'COMPOSE_EMOJI_INSERT';
40 export function changeCompose(text
) {
47 export function replyCompose(status
, router
) {
48 return (dispatch
, getState
) => {
54 if (!getState().getIn(['compose', 'mounted'])) {
55 router
.push('/statuses/new');
60 export function cancelReplyCompose() {
62 type: COMPOSE_REPLY_CANCEL
,
66 export function mentionCompose(account
, router
) {
67 return (dispatch
, getState
) => {
69 type: COMPOSE_MENTION
,
73 if (!getState().getIn(['compose', 'mounted'])) {
74 router
.push('/statuses/new');
79 export function submitCompose() {
80 return function (dispatch
, getState
) {
81 let status
= getState().getIn(['compose', 'text'], '');
83 if (!status
|| !status
.length
) {
87 dispatch(submitComposeRequest());
88 if (getState().getIn(['compose', 'advanced_options', 'do_not_federate'])) {
89 status
= status
+ ' 👁️';
91 api(getState
).post('/api/v1/statuses', {
93 in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null),
94 media_ids: getState().getIn(['compose', 'media_attachments']).map(item
=> item
.get('id')),
95 sensitive: getState().getIn(['compose', 'sensitive']),
96 spoiler_text: getState().getIn(['compose', 'spoiler_text'], ''),
97 visibility: getState().getIn(['compose', 'privacy']),
100 'Idempotency-Key': getState().getIn(['compose', 'idempotencyKey']),
102 }).then(function (response
) {
103 dispatch(submitComposeSuccess({ ...response
.data
}));
105 // To make the app more responsive, immediately get the status into the columns
107 const insertOrRefresh
= (timelineId
, refreshAction
) => {
108 if (getState().getIn(['timelines', timelineId
, 'online'])) {
109 dispatch(updateTimeline(timelineId
, { ...response
.data
}));
110 } else if (getState().getIn(['timelines', timelineId
, 'loaded'])) {
111 dispatch(refreshAction());
115 insertOrRefresh('home', refreshHomeTimeline
);
117 if (response
.data
.in_reply_to_id
=== null && response
.data
.visibility
=== 'public') {
118 insertOrRefresh('community', refreshCommunityTimeline
);
119 insertOrRefresh('public', refreshPublicTimeline
);
121 }).catch(function (error
) {
122 dispatch(submitComposeFail(error
));
127 export function submitComposeRequest() {
129 type: COMPOSE_SUBMIT_REQUEST
,
133 export function submitComposeSuccess(status
) {
135 type: COMPOSE_SUBMIT_SUCCESS
,
140 export function submitComposeFail(error
) {
142 type: COMPOSE_SUBMIT_FAIL
,
147 export function uploadCompose(files
) {
148 return function (dispatch
, getState
) {
149 if (getState().getIn(['compose', 'media_attachments']).size
> 3) {
153 dispatch(uploadComposeRequest());
155 let data
= new FormData();
156 data
.append('file', files
[0]);
158 api(getState
).post('/api/v1/media', data
, {
159 onUploadProgress: function (e
) {
160 dispatch(uploadComposeProgress(e
.loaded
, e
.total
));
162 }).then(function (response
) {
163 dispatch(uploadComposeSuccess(response
.data
));
164 }).catch(function (error
) {
165 dispatch(uploadComposeFail(error
));
170 export function uploadComposeRequest() {
172 type: COMPOSE_UPLOAD_REQUEST
,
177 export function uploadComposeProgress(loaded
, total
) {
179 type: COMPOSE_UPLOAD_PROGRESS
,
185 export function uploadComposeSuccess(media
) {
187 type: COMPOSE_UPLOAD_SUCCESS
,
193 export function uploadComposeFail(error
) {
195 type: COMPOSE_UPLOAD_FAIL
,
201 export function undoUploadCompose(media_id
) {
203 type: COMPOSE_UPLOAD_UNDO
,
208 export function clearComposeSuggestions() {
210 type: COMPOSE_SUGGESTIONS_CLEAR
,
214 export function fetchComposeSuggestions(token
) {
215 return (dispatch
, getState
) => {
216 api(getState
).get('/api/v1/accounts/search', {
222 }).then(response
=> {
223 dispatch(readyComposeSuggestions(token
, response
.data
));
228 export function readyComposeSuggestions(token
, accounts
) {
230 type: COMPOSE_SUGGESTIONS_READY
,
236 export function selectComposeSuggestion(position
, token
, accountId
) {
237 return (dispatch
, getState
) => {
238 const completion
= getState().getIn(['accounts', accountId
, 'acct']);
241 type: COMPOSE_SUGGESTION_SELECT
,
249 export function mountCompose() {
255 export function unmountCompose() {
257 type: COMPOSE_UNMOUNT
,
261 export function toggleComposeAdvancedOption(option
) {
263 type: COMPOSE_ADVANCED_OPTIONS_CHANGE
,
268 export function changeComposeSensitivity() {
270 type: COMPOSE_SENSITIVITY_CHANGE
,
274 export function changeComposeSpoilerness() {
276 type: COMPOSE_SPOILERNESS_CHANGE
,
280 export function changeComposeSpoilerText(text
) {
282 type: COMPOSE_SPOILER_TEXT_CHANGE
,
287 export function changeComposeVisibility(value
) {
289 type: COMPOSE_VISIBILITY_CHANGE
,
294 export function insertEmojiCompose(position
, emoji
) {
296 type: COMPOSE_EMOJI_INSERT
,
302 export function changeComposing(value
) {
304 type: COMPOSE_COMPOSING_CHANGE
,