2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2018-10-29 18:23:53 +01:00
|
|
|
import * as MODALS from 'constants/modal_types';
|
2018-05-25 20:05:30 +02:00
|
|
|
import {
|
2018-06-08 06:05:45 +02:00
|
|
|
batchActions,
|
2019-07-12 16:58:24 +02:00
|
|
|
// selectPendingById,
|
2018-11-29 06:12:34 +01:00
|
|
|
doError,
|
2019-07-03 04:30:34 +02:00
|
|
|
selectMyClaimsWithoutChannels,
|
2019-07-12 16:58:24 +02:00
|
|
|
doPublish,
|
|
|
|
// doCheckPendingPublishes,
|
2018-05-25 20:05:30 +02:00
|
|
|
} from 'lbry-redux';
|
2019-07-12 16:58:24 +02:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
|
|
|
// import { selectosNotificationsEnabled } from 'redux/selectors/settings';
|
|
|
|
// import { push } from 'connected-react-router';
|
2019-07-03 04:30:34 +02:00
|
|
|
// import analytics from 'analytics';
|
2019-07-12 16:58:24 +02:00
|
|
|
// import { formatLbryUriForWeb } from 'util/uri';
|
2019-07-03 04:30:34 +02:00
|
|
|
import analytics from '../../analytics';
|
|
|
|
import { doOpenModal } from './app';
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2019-07-12 16:58:24 +02:00
|
|
|
export const doPublishDesktop = () => (dispatch: Dispatch, getState: () => {}) => {
|
|
|
|
const publishSuccess = successResponse => {
|
|
|
|
const state = getState();
|
2019-02-05 19:36:40 +01:00
|
|
|
analytics.apiLogPublish();
|
2019-07-12 16:58:24 +02:00
|
|
|
const myClaims = selectMyClaimsWithoutChannels(state);
|
2019-04-24 16:02:08 +02:00
|
|
|
const pendingClaim = successResponse.outputs[0];
|
2019-07-12 16:58:24 +02:00
|
|
|
const uri = pendingClaim.permanent_url;
|
2018-11-02 19:33:00 +01:00
|
|
|
const actions = [];
|
|
|
|
|
|
|
|
actions.push({
|
2018-04-06 08:00:36 +02:00
|
|
|
type: ACTIONS.PUBLISH_SUCCESS,
|
|
|
|
});
|
2018-11-02 19:33:00 +01:00
|
|
|
// We have to fake a temp claim until the new pending one is returned by claim_list_mine
|
|
|
|
// We can't rely on claim_list_mine because there might be some delay before the new claims are returned
|
|
|
|
// Doing this allows us to show the pending claim immediately, it will get overwritten by the real one
|
|
|
|
const isMatch = claim => claim.claim_id === pendingClaim.claim_id;
|
|
|
|
const isEdit = myClaims.some(isMatch);
|
2019-06-25 06:05:46 +02:00
|
|
|
|
2018-11-02 19:33:00 +01:00
|
|
|
const myNewClaims = isEdit
|
2019-04-24 16:02:08 +02:00
|
|
|
? myClaims.map(claim => (isMatch(claim) ? pendingClaim : claim))
|
|
|
|
: myClaims.concat(pendingClaim);
|
2019-06-26 03:18:05 +02:00
|
|
|
actions.push(doOpenModal(MODALS.PUBLISH, { uri, isEdit }));
|
2018-11-02 19:33:00 +01:00
|
|
|
actions.push({
|
|
|
|
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
|
|
|
|
data: {
|
|
|
|
claims: myNewClaims,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
dispatch(batchActions(...actions));
|
2018-04-06 08:00:36 +02:00
|
|
|
};
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2019-07-12 16:58:24 +02:00
|
|
|
const publishFail = error => {
|
|
|
|
const actions = [];
|
|
|
|
actions.push({ type: ACTIONS.PUBLISH_FAIL });
|
|
|
|
actions.push(doError(error.message));
|
|
|
|
dispatch(batchActions(...actions));
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
2019-07-09 08:02:08 +02:00
|
|
|
|
2019-07-12 16:58:24 +02:00
|
|
|
return dispatch(doPublish(publishSuccess, publishFail));
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Calls claim_list_mine until any pending publishes are confirmed
|
2019-07-12 16:58:24 +02:00
|
|
|
export const doCheckPendingPublishesApp = () => (dispatch: Dispatch, getState: GetState) => {};
|
|
|
|
|
|
|
|
// export const doCheckPendingPublishes = () => (dispatch: Dispatch, getState: GetState) => {
|
|
|
|
// const state = getState();
|
|
|
|
// const pendingById = selectPendingById(state);
|
|
|
|
//
|
|
|
|
// if (!Object.keys(pendingById).length) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// let publishCheckInterval;
|
|
|
|
//
|
|
|
|
// const checkFileList = () => {
|
|
|
|
// Lbry.claim_list().then(claims => {
|
|
|
|
// if (claims) {
|
|
|
|
// claims.forEach(claim => {
|
|
|
|
// // If it's confirmed, check if it was pending previously
|
|
|
|
// if (claim.confirmations > 0 && pendingById[claim.claim_id]) {
|
|
|
|
// delete pendingById[claim.claim_id];
|
|
|
|
//
|
|
|
|
// // If it's confirmed, check if we should notify the user
|
|
|
|
// if (selectosNotificationsEnabled(getState())) {
|
|
|
|
// const notif = new window.Notification('LBRY Publish Complete', {
|
|
|
|
// body: `${claim.value.title} has been published to lbry://${claim.name}. Click here to view it`,
|
|
|
|
// silent: false,
|
|
|
|
// });
|
|
|
|
// notif.onclick = () => {
|
|
|
|
// dispatch(push(formatLbryUriForWeb(claim.permanent_url)));
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// dispatch({
|
|
|
|
// type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
|
|
|
|
// data: {
|
|
|
|
// claims,
|
|
|
|
// },
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// if (!Object.keys(pendingById).length) {
|
|
|
|
// clearInterval(publishCheckInterval);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// publishCheckInterval = setInterval(() => {
|
|
|
|
// checkFileList();
|
|
|
|
// }, 30000);
|
|
|
|
// };
|