2018-03-26 09:31:52 +02:00
|
|
|
import * as NOTIFICATION_TYPES from 'constants/notification_types';
|
2017-12-28 00:48:11 +01:00
|
|
|
import { ipcRenderer } from 'electron';
|
2017-12-21 18:32:51 +01:00
|
|
|
import Lbryio from 'lbryio';
|
2018-04-19 18:51:18 +02:00
|
|
|
import { doAlertError } from 'redux/actions/app';
|
2017-12-28 00:48:11 +01:00
|
|
|
import { doClaimEligiblePurchaseRewards } from 'redux/actions/rewards';
|
2018-03-26 09:31:52 +02:00
|
|
|
import { doNavigate } from 'redux/actions/navigation';
|
|
|
|
import {
|
|
|
|
setSubscriptionLatest,
|
|
|
|
setSubscriptionNotification,
|
|
|
|
setSubscriptionNotifications,
|
|
|
|
} from 'redux/actions/subscriptions';
|
|
|
|
import { selectNotifications } from 'redux/selectors/subscriptions';
|
2017-12-28 00:48:11 +01:00
|
|
|
import { selectBadgeNumber } from 'redux/selectors/app';
|
2017-04-28 17:14:44 +02:00
|
|
|
import {
|
2018-04-18 06:03:01 +02:00
|
|
|
ACTIONS,
|
|
|
|
SETTINGS,
|
|
|
|
Lbry,
|
|
|
|
Lbryapi,
|
|
|
|
buildURI,
|
|
|
|
batchActions,
|
|
|
|
doResolveUris,
|
|
|
|
doFetchClaimListMine,
|
|
|
|
makeSelectCostInfoForUri,
|
2017-09-08 05:15:05 +02:00
|
|
|
makeSelectFileInfoForUri,
|
2017-07-21 10:02:29 +02:00
|
|
|
selectDownloadingByOutpoint,
|
2017-12-21 18:32:51 +01:00
|
|
|
selectTotalDownloadProgress,
|
2018-04-18 06:03:01 +02:00
|
|
|
selectBalance,
|
2018-05-05 21:04:47 +02:00
|
|
|
MODALS,
|
|
|
|
doNotify,
|
2018-04-18 06:03:01 +02:00
|
|
|
} from 'lbry-redux';
|
2017-12-28 00:48:11 +01:00
|
|
|
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
2017-12-21 18:32:51 +01:00
|
|
|
import setBadge from 'util/setBadge';
|
|
|
|
import setProgressBar from 'util/setProgressBar';
|
2018-03-08 04:56:58 +01:00
|
|
|
import analytics from 'analytics';
|
2017-06-24 18:48:01 +02:00
|
|
|
|
2017-08-30 18:43:35 +02:00
|
|
|
const DOWNLOAD_POLL_INTERVAL = 250;
|
|
|
|
|
2017-05-04 05:44:08 +02:00
|
|
|
export function doFetchFeaturedUris() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-04-23 11:56:50 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FETCH_FEATURED_CONTENT_STARTED,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-04-23 11:56:50 +02:00
|
|
|
|
2017-11-07 18:43:31 +01:00
|
|
|
const success = ({ Uris }) => {
|
2018-05-23 06:35:34 +02:00
|
|
|
const urisToResolve = Object.keys(Uris).reduce(
|
|
|
|
(resolve, category) => [...resolve, ...Uris[category]],
|
|
|
|
[]
|
|
|
|
);
|
2017-05-04 05:44:08 +02:00
|
|
|
|
2017-10-09 08:23:44 +02:00
|
|
|
const actions = [
|
|
|
|
doResolveUris(urisToResolve),
|
|
|
|
{
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED,
|
2017-10-09 08:23:44 +02:00
|
|
|
data: {
|
2017-11-07 18:43:31 +01:00
|
|
|
uris: Uris,
|
2017-10-09 08:23:44 +02:00
|
|
|
success: true,
|
|
|
|
},
|
2017-06-06 23:19:12 +02:00
|
|
|
},
|
2017-10-09 08:23:44 +02:00
|
|
|
];
|
2017-06-08 07:10:58 +02:00
|
|
|
dispatch(batchActions(...actions));
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-23 11:56:50 +02:00
|
|
|
|
|
|
|
const failure = () => {
|
2017-05-04 05:44:08 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED,
|
2017-05-04 05:44:08 +02:00
|
|
|
data: {
|
2017-06-06 23:19:12 +02:00
|
|
|
uris: {},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbryio.call('file', 'list_homepage').then(success, failure);
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-23 11:56:50 +02:00
|
|
|
}
|
2017-04-24 09:25:27 +02:00
|
|
|
|
2017-07-30 00:56:08 +02:00
|
|
|
export function doFetchRewardedContent() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-07-25 09:07:54 +02:00
|
|
|
const success = nameToClaimId => {
|
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FETCH_REWARD_CONTENT_COMPLETED,
|
2017-07-25 09:07:54 +02:00
|
|
|
data: {
|
|
|
|
claimIds: Object.values(nameToClaimId),
|
|
|
|
success: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const failure = () => {
|
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FETCH_REWARD_CONTENT_COMPLETED,
|
2017-07-25 09:07:54 +02:00
|
|
|
data: {
|
|
|
|
claimIds: [],
|
|
|
|
success: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbryio.call('reward', 'list_featured').then(success, failure);
|
2017-07-25 09:07:54 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-04-26 19:08:26 +02:00
|
|
|
export function doUpdateLoadStatus(uri, outpoint) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return (dispatch, getState) => {
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.file_list({
|
|
|
|
outpoint,
|
|
|
|
full_status: true,
|
|
|
|
}).then(([fileInfo]) => {
|
|
|
|
if (!fileInfo || fileInfo.written_bytes === 0) {
|
|
|
|
// download hasn't started yet
|
|
|
|
setTimeout(() => {
|
|
|
|
dispatch(doUpdateLoadStatus(uri, outpoint));
|
|
|
|
}, DOWNLOAD_POLL_INTERVAL);
|
|
|
|
} else if (fileInfo.completed) {
|
|
|
|
// TODO this isn't going to get called if they reload the client before
|
|
|
|
// the download finished
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.DOWNLOADING_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
outpoint,
|
|
|
|
fileInfo,
|
|
|
|
},
|
|
|
|
});
|
2017-06-24 10:57:37 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
const badgeNumber = selectBadgeNumber(getState());
|
|
|
|
setBadge(badgeNumber === 0 ? '' : `${badgeNumber}`);
|
2017-06-24 18:48:01 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
const totalProgress = selectTotalDownloadProgress(getState());
|
|
|
|
setProgressBar(totalProgress);
|
2017-06-24 18:48:01 +02:00
|
|
|
|
2018-03-26 09:31:52 +02:00
|
|
|
const notifications = selectNotifications(getState());
|
|
|
|
if (notifications[uri] && notifications[uri].type === NOTIFICATION_TYPES.DOWNLOADING) {
|
|
|
|
const count = Object.keys(notifications).reduce(
|
|
|
|
(acc, cur) =>
|
|
|
|
notifications[cur].subscription.channelName ===
|
|
|
|
notifications[uri].subscription.channelName
|
|
|
|
? acc + 1
|
|
|
|
: acc,
|
|
|
|
0
|
|
|
|
);
|
2018-05-07 06:50:55 +02:00
|
|
|
|
2018-03-26 09:31:52 +02:00
|
|
|
const notif = new window.Notification(notifications[uri].subscription.channelName, {
|
|
|
|
body: `Posted ${fileInfo.metadata.title}${
|
|
|
|
count > 1 && count < 10 ? ` and ${count - 1} other new items` : ''
|
|
|
|
}${count > 9 ? ' and 9+ other new items' : ''}`,
|
|
|
|
silent: false,
|
|
|
|
});
|
|
|
|
notif.onclick = () => {
|
|
|
|
dispatch(
|
|
|
|
doNavigate('/show', {
|
|
|
|
uri,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
|
|
|
dispatch(
|
|
|
|
setSubscriptionNotification(
|
|
|
|
notifications[uri].subscription,
|
|
|
|
uri,
|
|
|
|
NOTIFICATION_TYPES.DOWNLOADED
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
const notif = new window.Notification('LBRY Download Complete', {
|
|
|
|
body: fileInfo.metadata.title,
|
|
|
|
silent: false,
|
|
|
|
});
|
|
|
|
notif.onclick = () => {
|
|
|
|
ipcRenderer.send('focusWindow', 'main');
|
|
|
|
};
|
|
|
|
}
|
2017-12-21 18:32:51 +01:00
|
|
|
} else {
|
|
|
|
// ready to play
|
|
|
|
const { total_bytes: totalBytes, written_bytes: writtenBytes } = fileInfo;
|
|
|
|
const progress = writtenBytes / totalBytes * 100;
|
2017-06-06 23:19:12 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.DOWNLOADING_PROGRESSED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
outpoint,
|
|
|
|
fileInfo,
|
|
|
|
progress,
|
|
|
|
},
|
|
|
|
});
|
2017-06-24 10:57:37 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
const totalProgress = selectTotalDownloadProgress(getState());
|
|
|
|
setProgressBar(totalProgress);
|
2017-06-24 10:57:37 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
dispatch(doUpdateLoadStatus(uri, outpoint));
|
|
|
|
}, DOWNLOAD_POLL_INTERVAL);
|
|
|
|
}
|
|
|
|
});
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-26 19:08:26 +02:00
|
|
|
}
|
|
|
|
|
2017-07-25 10:43:44 +02:00
|
|
|
export function doStartDownload(uri, outpoint) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return (dispatch, getState) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
2017-05-31 09:31:08 +02:00
|
|
|
|
2017-08-08 11:36:14 +02:00
|
|
|
if (!outpoint) {
|
2017-12-21 18:32:51 +01:00
|
|
|
throw new Error('outpoint is required to begin a download');
|
2017-08-08 11:36:14 +02:00
|
|
|
}
|
2017-07-30 21:20:36 +02:00
|
|
|
|
2017-07-25 10:43:44 +02:00
|
|
|
const { downloadingByOutpoint = {} } = state.fileInfo;
|
2017-04-26 19:08:26 +02:00
|
|
|
|
2017-07-25 10:43:44 +02:00
|
|
|
if (downloadingByOutpoint[outpoint]) return;
|
2017-04-26 19:08:26 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.file_list({ outpoint, full_status: true }).then(([fileInfo]) => {
|
2017-07-25 10:43:44 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.DOWNLOADING_STARTED,
|
2017-07-25 10:43:44 +02:00
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
outpoint,
|
|
|
|
fileInfo,
|
|
|
|
},
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-05-26 17:58:56 +02:00
|
|
|
|
2017-07-25 10:43:44 +02:00
|
|
|
dispatch(doUpdateLoadStatus(uri, outpoint));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doDownloadFile(uri, streamInfo) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-07-25 10:43:44 +02:00
|
|
|
dispatch(doStartDownload(uri, streamInfo.outpoint));
|
|
|
|
|
2018-06-05 19:22:32 +02:00
|
|
|
analytics.apiLogView(
|
|
|
|
`${streamInfo.claim_name}#${streamInfo.claim_id}`,
|
|
|
|
streamInfo.outpoint,
|
|
|
|
streamInfo.claim_id
|
|
|
|
);
|
2017-05-26 20:19:41 +02:00
|
|
|
|
2017-06-08 23:15:34 +02:00
|
|
|
dispatch(doClaimEligiblePurchaseRewards());
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-26 19:08:26 +02:00
|
|
|
}
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export function doSetPlayingUri(uri) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-12-21 18:32:51 +01:00
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.SET_PLAYING_URI,
|
|
|
|
data: { uri },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2017-04-26 19:08:26 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export function doLoadVideo(uri) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-04-26 19:08:26 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.LOADING_VIDEO_STARTED,
|
2017-04-26 19:08:26 +02:00
|
|
|
data: {
|
2017-06-06 23:19:12 +02:00
|
|
|
uri,
|
|
|
|
},
|
|
|
|
});
|
2017-04-26 19:08:26 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.get({ uri })
|
2017-08-08 11:36:14 +02:00
|
|
|
.then(streamInfo => {
|
|
|
|
const timeout =
|
2017-12-21 18:32:51 +01:00
|
|
|
streamInfo === null || typeof streamInfo !== 'object' || streamInfo.error === 'Timeout';
|
2017-08-08 11:36:14 +02:00
|
|
|
|
|
|
|
if (timeout) {
|
2017-10-01 07:39:00 +02:00
|
|
|
dispatch(doSetPlayingUri(null));
|
2017-08-08 11:36:14 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.LOADING_VIDEO_FAILED,
|
2017-08-08 11:36:14 +02:00
|
|
|
data: { uri },
|
|
|
|
});
|
2017-05-02 09:07:13 +02:00
|
|
|
|
2018-04-19 18:51:18 +02:00
|
|
|
dispatch(doNotify({ id: MODALS.FILE_TIMEOUT }, { uri }));
|
2017-08-08 11:36:14 +02:00
|
|
|
} else {
|
|
|
|
dispatch(doDownloadFile(uri, streamInfo));
|
|
|
|
}
|
|
|
|
})
|
2017-12-06 21:38:07 +01:00
|
|
|
.catch(() => {
|
2017-10-01 07:39:00 +02:00
|
|
|
dispatch(doSetPlayingUri(null));
|
2017-04-26 19:08:26 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.LOADING_VIDEO_FAILED,
|
2017-06-06 23:19:12 +02:00
|
|
|
data: { uri },
|
|
|
|
});
|
2017-12-06 21:38:07 +01:00
|
|
|
dispatch(
|
|
|
|
doAlertError(
|
2018-03-09 08:06:15 +01:00
|
|
|
`Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`
|
2017-12-06 21:38:07 +01:00
|
|
|
)
|
|
|
|
);
|
2017-07-30 21:57:42 +02:00
|
|
|
});
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-26 19:08:26 +02:00
|
|
|
}
|
|
|
|
|
2018-03-06 08:44:36 +01:00
|
|
|
export function doPurchaseUri(uri, specificCostInfo) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return (dispatch, getState) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
|
|
|
const balance = selectBalance(state);
|
2017-09-08 05:15:05 +02:00
|
|
|
const fileInfo = makeSelectFileInfoForUri(uri)(state);
|
2017-07-21 10:02:29 +02:00
|
|
|
const downloadingByOutpoint = selectDownloadingByOutpoint(state);
|
2017-12-21 18:32:51 +01:00
|
|
|
const alreadyDownloading = fileInfo && !!downloadingByOutpoint[fileInfo.outpoint];
|
2017-05-26 20:36:18 +02:00
|
|
|
|
2017-09-08 07:03:37 +02:00
|
|
|
function attemptPlay(cost, instantPurchaseMax = null) {
|
2017-09-29 02:32:59 +02:00
|
|
|
if (cost > 0 && (!instantPurchaseMax || cost > instantPurchaseMax)) {
|
2018-04-19 18:51:18 +02:00
|
|
|
dispatch(doNotify({ id: MODALS.AFFIRM_PURCHASE }, { uri }));
|
2017-09-08 07:03:37 +02:00
|
|
|
} else {
|
|
|
|
dispatch(doLoadVideo(uri));
|
|
|
|
}
|
2017-09-18 04:08:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// we already fully downloaded the file.
|
2017-09-08 07:03:37 +02:00
|
|
|
if (fileInfo && fileInfo.completed) {
|
|
|
|
// If written_bytes is false that means the user has deleted/moved the
|
|
|
|
// file manually on their file system, so we need to dispatch a
|
|
|
|
// doLoadVideo action to reconstruct the file from the blobs
|
|
|
|
if (!fileInfo.written_bytes) dispatch(doLoadVideo(uri));
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
Promise.resolve();
|
|
|
|
return;
|
2017-09-08 07:03:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// we are already downloading the file
|
|
|
|
if (alreadyDownloading) {
|
2017-12-21 18:32:51 +01:00
|
|
|
Promise.resolve();
|
|
|
|
return;
|
2017-04-27 17:10:39 +02:00
|
|
|
}
|
|
|
|
|
2018-03-06 08:44:36 +01:00
|
|
|
const costInfo = makeSelectCostInfoForUri(uri)(state) || specificCostInfo;
|
2017-09-08 07:03:37 +02:00
|
|
|
const { cost } = costInfo;
|
|
|
|
|
2017-04-27 09:05:41 +02:00
|
|
|
if (cost > balance) {
|
2017-10-01 04:50:32 +02:00
|
|
|
dispatch(doSetPlayingUri(null));
|
2018-04-19 18:51:18 +02:00
|
|
|
dispatch(doNotify({ id: MODALS.INSUFFICIENT_CREDITS }));
|
2017-12-21 18:32:51 +01:00
|
|
|
Promise.resolve();
|
|
|
|
return;
|
2017-09-08 07:03:37 +02:00
|
|
|
}
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
if (cost === 0 || !makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state)) {
|
2017-09-08 07:03:37 +02:00
|
|
|
attemptPlay(cost);
|
|
|
|
} else {
|
2017-12-21 18:32:51 +01:00
|
|
|
const instantPurchaseMax = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state);
|
|
|
|
if (instantPurchaseMax.currency === 'LBC') {
|
2017-09-08 07:03:37 +02:00
|
|
|
attemptPlay(cost, instantPurchaseMax.amount);
|
|
|
|
} else {
|
|
|
|
// Need to convert currency of instant purchase maximum before trying to play
|
2018-04-18 06:03:01 +02:00
|
|
|
Lbryapi.getExchangeRates().then(({ LBC_USD }) => {
|
2017-12-21 18:32:51 +01:00
|
|
|
attemptPlay(cost, instantPurchaseMax.amount / LBC_USD);
|
2017-09-08 07:03:37 +02:00
|
|
|
});
|
|
|
|
}
|
2017-04-26 19:08:26 +02:00
|
|
|
}
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-26 19:08:26 +02:00
|
|
|
}
|
2017-05-13 00:50:51 +02:00
|
|
|
|
2017-07-17 08:06:04 +02:00
|
|
|
export function doFetchClaimsByChannel(uri, page) {
|
2018-03-26 09:31:52 +02:00
|
|
|
return (dispatch, getState) => {
|
2017-05-13 00:50:51 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FETCH_CHANNEL_CLAIMS_STARTED,
|
2017-07-17 08:06:04 +02:00
|
|
|
data: { uri, page },
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-05-13 00:50:51 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.claim_list_by_channel({ uri, page: page || 1 }).then(result => {
|
2017-09-30 01:15:14 +02:00
|
|
|
const claimResult = result[uri] || {};
|
2017-12-21 18:32:51 +01:00
|
|
|
const { claims_in_channel: claimsInChannel, returned_page: returnedPage } = claimResult;
|
2017-05-13 00:50:51 +02:00
|
|
|
|
2018-03-06 09:36:04 +01:00
|
|
|
if (claimsInChannel && claimsInChannel.length) {
|
2018-03-07 20:41:14 +01:00
|
|
|
const latest = claimsInChannel[0];
|
2018-03-06 09:36:04 +01:00
|
|
|
dispatch(
|
|
|
|
setSubscriptionLatest(
|
|
|
|
{
|
|
|
|
channelName: latest.channel_name,
|
2018-03-07 20:19:45 +01:00
|
|
|
uri: buildURI(
|
|
|
|
{
|
|
|
|
contentName: latest.channel_name,
|
|
|
|
claimId: latest.value.publisherSignature.certificateId,
|
|
|
|
},
|
|
|
|
false
|
|
|
|
),
|
2018-03-06 09:36:04 +01:00
|
|
|
},
|
2018-03-06 10:37:53 +01:00
|
|
|
buildURI({ contentName: latest.name, claimId: latest.claim_id }, false)
|
2018-03-06 09:36:04 +01:00
|
|
|
)
|
|
|
|
);
|
2018-03-26 09:31:52 +02:00
|
|
|
const notifications = selectNotifications(getState());
|
|
|
|
const newNotifications = {};
|
|
|
|
Object.keys(notifications).forEach(cur => {
|
|
|
|
if (
|
|
|
|
notifications[cur].subscription.channelName !== latest.channel_name ||
|
|
|
|
notifications[cur].type === NOTIFICATION_TYPES.DOWNLOADING
|
|
|
|
) {
|
|
|
|
newNotifications[cur] = { ...notifications[cur] };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dispatch(setSubscriptionNotifications(newNotifications));
|
2018-03-06 01:28:11 +01:00
|
|
|
}
|
|
|
|
|
2017-05-13 00:50:51 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED,
|
2017-05-13 00:50:51 +02:00
|
|
|
data: {
|
|
|
|
uri,
|
2017-12-21 18:32:51 +01:00
|
|
|
claims: claimsInChannel || [],
|
|
|
|
page: returnedPage || undefined,
|
2017-06-06 23:19:12 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-05-19 01:14:26 +02:00
|
|
|
}
|
|
|
|
|
2017-08-24 23:12:23 +02:00
|
|
|
export function doFetchClaimCountByChannel(uri) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-08-24 23:12:23 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_STARTED,
|
2017-08-24 23:12:23 +02:00
|
|
|
data: { uri },
|
|
|
|
});
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.claim_list_by_channel({ uri }).then(result => {
|
|
|
|
const claimResult = result[uri];
|
|
|
|
const totalClaims = claimResult ? claimResult.claims_in_channel : 0;
|
2017-08-24 23:12:23 +02:00
|
|
|
|
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED,
|
2017-08-24 23:12:23 +02:00
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
totalClaims,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-18 04:08:43 +02:00
|
|
|
export function doPlayUri(uri) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-09-18 04:08:43 +02:00
|
|
|
dispatch(doSetPlayingUri(uri));
|
|
|
|
dispatch(doPurchaseUri(uri));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-07-10 16:49:12 +02:00
|
|
|
export function doFetchChannelListMine() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-07-10 16:49:12 +02:00
|
|
|
dispatch({
|
2018-02-21 06:41:30 +01:00
|
|
|
type: ACTIONS.FETCH_CHANNEL_LIST_STARTED,
|
2017-07-10 16:49:12 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const callback = channels => {
|
|
|
|
dispatch({
|
2018-02-21 06:41:30 +01:00
|
|
|
type: ACTIONS.FETCH_CHANNEL_LIST_COMPLETED,
|
2017-07-10 16:49:12 +02:00
|
|
|
data: { claims: channels },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-02-21 06:41:30 +01:00
|
|
|
Lbry.channel_list().then(callback);
|
2017-07-10 16:49:12 +02:00
|
|
|
};
|
|
|
|
}
|
2017-06-17 19:59:18 +02:00
|
|
|
|
|
|
|
export function doCreateChannel(name, amount) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-06-17 19:59:18 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.CREATE_CHANNEL_STARTED,
|
2017-06-17 19:59:18 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.channel_new({
|
|
|
|
channel_name: name,
|
|
|
|
amount: parseFloat(amount),
|
|
|
|
}).then(
|
2018-01-02 20:54:57 +01:00
|
|
|
newChannelClaim => {
|
|
|
|
const channelClaim = newChannelClaim;
|
|
|
|
channelClaim.name = name;
|
2017-12-21 18:32:51 +01:00
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.CREATE_CHANNEL_COMPLETED,
|
2018-01-02 20:54:57 +01:00
|
|
|
data: { channelClaim },
|
2017-12-21 18:32:51 +01:00
|
|
|
});
|
2018-01-02 20:54:57 +01:00
|
|
|
resolve(channelClaim);
|
2017-12-21 18:32:51 +01:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
);
|
2017-06-17 19:59:18 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-18 06:03:01 +02:00
|
|
|
export function doPublish(params) {
|
|
|
|
return dispatch =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
const success = claim => {
|
|
|
|
resolve(claim);
|
2017-10-30 17:25:56 +01:00
|
|
|
|
2018-04-18 06:03:01 +02:00
|
|
|
if (claim === true) dispatch(doFetchClaimListMine());
|
|
|
|
else
|
|
|
|
setTimeout(() => dispatch(doFetchClaimListMine()), 20000, {
|
|
|
|
once: true,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
const failure = err => reject(err);
|
2017-10-24 15:10:27 +02:00
|
|
|
|
2018-04-18 06:03:01 +02:00
|
|
|
Lbry.publishDeprecated(params, null, success, failure);
|
|
|
|
});
|
2017-10-24 15:10:27 +02:00
|
|
|
}
|