2018-07-31 14:36:20 +02:00
|
|
|
// @flow
|
2020-04-29 22:50:06 +02:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2018-10-29 18:23:53 +01:00
|
|
|
import * as MODALS from 'constants/modal_types';
|
2019-03-05 05:46:57 +01:00
|
|
|
// @if TARGET='app'
|
2017-12-28 00:48:11 +01:00
|
|
|
import { ipcRenderer } from 'electron';
|
2019-03-05 05:46:57 +01:00
|
|
|
// @endif
|
2022-02-01 21:29:00 +01:00
|
|
|
import { doOpenModal, doAnalyticsView, doAnaltyicsPurchaseEvent } from 'redux/actions/app';
|
2022-04-20 15:06:30 +02:00
|
|
|
import { makeSelectClaimForUri, selectClaimIsMineForUri, selectClaimWasPurchasedForUri } from 'redux/selectors/claims';
|
2017-04-28 17:14:44 +02:00
|
|
|
import {
|
2017-09-08 05:15:05 +02:00
|
|
|
makeSelectFileInfoForUri,
|
2018-10-15 13:27:56 +02:00
|
|
|
selectFileInfosByOutpoint,
|
2019-08-02 08:28:14 +02:00
|
|
|
makeSelectUriIsStreamable,
|
2019-08-02 23:03:26 +02:00
|
|
|
selectDownloadingByOutpoint,
|
2021-10-17 10:36:14 +02:00
|
|
|
} from 'redux/selectors/file_info';
|
|
|
|
import { makeSelectUrlsForCollectionId } from 'redux/selectors/collections';
|
|
|
|
import { doToast } from 'redux/actions/notifications';
|
2021-10-05 22:57:47 +02:00
|
|
|
import { doPurchaseUri } from 'redux/actions/file';
|
2021-10-17 10:36:14 +02:00
|
|
|
import Lbry from 'lbry';
|
2022-05-24 14:24:04 +02:00
|
|
|
import RecSys from 'recsys';
|
2021-10-17 10:36:14 +02:00
|
|
|
import * as SETTINGS from 'constants/settings';
|
2021-11-19 03:40:01 +01:00
|
|
|
import { selectCostInfoForUri, Lbryio } from 'lbryinc';
|
2021-11-23 05:29:04 +01:00
|
|
|
import { selectClientSetting, selectosNotificationsEnabled, selectDaemonSettings } from 'redux/selectors/settings';
|
2022-02-23 22:13:22 +01:00
|
|
|
import { selectIsActiveLivestreamForUri } from 'redux/selectors/livestream';
|
2022-05-24 14:24:04 +02:00
|
|
|
import { selectRecsysEntries } from 'redux/selectors/content';
|
2017-06-24 18:48:01 +02:00
|
|
|
|
2020-08-24 22:08:14 +02:00
|
|
|
const DOWNLOAD_POLL_INTERVAL = 1000;
|
2017-08-30 18:43:35 +02:00
|
|
|
|
2018-10-15 13:27:56 +02:00
|
|
|
export function doUpdateLoadStatus(uri: string, outpoint: string) {
|
2019-03-13 06:59:07 +01:00
|
|
|
// Updates the loading status for a uri as it's downloading
|
|
|
|
// Calls file_list and checks the written_bytes value to see if the number has increased
|
|
|
|
// Not needed on web as users aren't actually downloading the file
|
|
|
|
// @if TARGET='app'
|
2019-03-18 06:09:50 +01:00
|
|
|
return (dispatch: Dispatch, getState: GetState) => {
|
2018-10-15 13:27:56 +02:00
|
|
|
const setNextStatusUpdate = () =>
|
|
|
|
setTimeout(() => {
|
2018-10-18 14:38:12 +02:00
|
|
|
// We need to check if outpoint still exists first because user are able to delete file (outpoint) while downloading.
|
2018-10-18 17:23:08 +02:00
|
|
|
// If a file is already deleted, no point to still try update load status
|
2018-10-15 13:27:56 +02:00
|
|
|
const byOutpoint = selectFileInfosByOutpoint(getState());
|
|
|
|
if (byOutpoint[outpoint]) {
|
|
|
|
dispatch(doUpdateLoadStatus(uri, outpoint));
|
|
|
|
}
|
|
|
|
}, DOWNLOAD_POLL_INTERVAL);
|
2019-03-13 06:59:07 +01:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.file_list({
|
|
|
|
outpoint,
|
|
|
|
full_status: true,
|
2019-11-05 21:16:41 +01:00
|
|
|
page: 1,
|
|
|
|
page_size: 1,
|
Fill in remaining Recsys fields
## Issue
6366 Recsys Evaluation Telemetry
The recommended list from lighthouse is obtained from `makeSelectRecommendedContentForUri`. This list is further tweaked by the GUI (e.g. move autoplay next item to top, remove blocked content, etc.). Recsys wants the final recommendation list and the clicked index (in exact order), so we need pass these info to the videojs recsys plugin somehow. Also, Recsys wants a recommendation list ID as well as the parent (referrer) ID, we so need to track the clicks and navigation.
## General Approach
- It seems easiest to just spew back the final (displayed) list and all the required info to Redux, and the recsys plugin (or anyone else in the future) can grab it.
- Try to touch few files as possible. The dirty work should all reside in `<RecommendedContent>` only.
## Changes
- `ClaimPreview`: add optional parameters to store an ID of the container that it is in (for this case, it is `ClaimList`) as well as the index within the container.
- When clicked, we store the container ID in the navigation history `state` object.
- For general cases, anyone can check this state from `history.location.state` to know which container referred/navigated to the current page. For the recsys use case, we can use this as the `parentUUID`.
- `ClaimList`: just relay `onClick` and set IDs.
- `RecommendedContent`: now handles the uuid generation (for both parent and child) and stores the data in Redux.
2021-07-28 14:07:49 +02:00
|
|
|
}).then((result) => {
|
2019-11-05 21:16:41 +01:00
|
|
|
const { items: fileInfos } = result;
|
|
|
|
const fileInfo = fileInfos[0];
|
2017-12-21 18:32:51 +01:00
|
|
|
if (!fileInfo || fileInfo.written_bytes === 0) {
|
|
|
|
// download hasn't started yet
|
2018-10-15 13:27:56 +02:00
|
|
|
setNextStatusUpdate();
|
2017-12-21 18:32:51 +01:00
|
|
|
} 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
|
|
|
|
2020-11-06 06:02:21 +01:00
|
|
|
// If notifications are disabled(false) just return
|
|
|
|
if (!selectosNotificationsEnabled(getState()) || !fileInfo.written_bytes) return;
|
2018-10-19 22:38:07 +02:00
|
|
|
|
2020-11-06 06:02:21 +01:00
|
|
|
const notif = new window.Notification(__('LBRY Download Complete'), {
|
|
|
|
body: fileInfo.metadata.title,
|
|
|
|
silent: false,
|
|
|
|
});
|
2019-03-05 05:46:57 +01:00
|
|
|
|
2020-11-06 06:02:21 +01:00
|
|
|
// @if TARGET='app'
|
|
|
|
notif.onclick = () => {
|
|
|
|
ipcRenderer.send('focusWindow', 'main');
|
|
|
|
};
|
|
|
|
// @ENDIF
|
2017-12-21 18:32:51 +01:00
|
|
|
} else {
|
|
|
|
// ready to play
|
|
|
|
const { total_bytes: totalBytes, written_bytes: writtenBytes } = fileInfo;
|
2018-07-12 21:37:01 +02:00
|
|
|
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
|
|
|
|
2018-10-15 13:27:56 +02:00
|
|
|
setNextStatusUpdate();
|
2017-12-21 18:32:51 +01:00
|
|
|
}
|
|
|
|
});
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2019-03-13 06:59:07 +01:00
|
|
|
// @endif
|
2017-04-26 19:08:26 +02:00
|
|
|
}
|
|
|
|
|
2020-10-20 19:10:02 +02:00
|
|
|
export function doSetPrimaryUri(uri: ?string) {
|
2019-03-18 06:09:50 +01:00
|
|
|
return (dispatch: Dispatch) => {
|
2017-12-21 18:32:51 +01:00
|
|
|
dispatch({
|
2020-10-20 19:10:02 +02:00
|
|
|
type: ACTIONS.SET_PRIMARY_URI,
|
2017-12-21 18:32:51 +01:00
|
|
|
data: { uri },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2017-04-26 19:08:26 +02:00
|
|
|
|
2022-02-01 21:11:35 +01:00
|
|
|
export const doClearPlayingUri = () => (dispatch: Dispatch) => dispatch(doSetPlayingUri({ uri: null }));
|
|
|
|
|
2020-10-20 19:10:02 +02:00
|
|
|
export function doSetPlayingUri({
|
|
|
|
uri,
|
|
|
|
source,
|
|
|
|
pathname,
|
|
|
|
commentId,
|
2021-09-02 22:05:32 +02:00
|
|
|
collectionId,
|
2020-10-20 19:10:02 +02:00
|
|
|
}: {
|
|
|
|
uri: ?string,
|
|
|
|
source?: string,
|
|
|
|
commentId?: string,
|
2021-10-05 22:57:47 +02:00
|
|
|
pathname?: string,
|
2022-03-15 17:28:55 +01:00
|
|
|
collectionId?: ?string,
|
2020-10-20 19:10:02 +02:00
|
|
|
}) {
|
2020-04-29 22:50:06 +02:00
|
|
|
return (dispatch: Dispatch) => {
|
|
|
|
dispatch({
|
2020-10-20 19:10:02 +02:00
|
|
|
type: ACTIONS.SET_PLAYING_URI,
|
2021-09-02 22:05:32 +02:00
|
|
|
data: { uri, source, pathname, commentId, collectionId },
|
2020-04-29 22:50:06 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-21 17:38:28 +02:00
|
|
|
export function doPurchaseUriWrapper(uri: string, cost: number, saveFile: boolean, cb: ?(GetResponse) => void) {
|
2019-08-02 08:28:14 +02:00
|
|
|
return (dispatch: Dispatch, getState: () => any) => {
|
|
|
|
function onSuccess(fileInfo) {
|
2019-11-13 16:20:54 +01:00
|
|
|
if (saveFile) {
|
|
|
|
dispatch(doUpdateLoadStatus(uri, fileInfo.outpoint));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cb) {
|
2020-05-21 17:38:28 +02:00
|
|
|
cb(fileInfo);
|
2019-11-13 16:20:54 +01:00
|
|
|
}
|
2019-08-02 08:28:14 +02:00
|
|
|
}
|
|
|
|
|
2021-10-05 22:57:47 +02:00
|
|
|
dispatch(doPurchaseUri(uri, { cost }, saveFile, onSuccess));
|
2019-08-02 08:28:14 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-01 21:11:35 +01:00
|
|
|
export function doDownloadUri(uri: string) {
|
|
|
|
return (dispatch: Dispatch) => dispatch(doPlayUri(uri, false, true, () => dispatch(doAnalyticsView(uri))));
|
|
|
|
}
|
|
|
|
|
2022-03-15 17:28:55 +01:00
|
|
|
export function doUriInitiatePlay(playingOptions: PlayingUri, isPlayable?: boolean, isFloating?: boolean) {
|
2022-02-23 22:13:22 +01:00
|
|
|
return (dispatch: Dispatch, getState: () => any) => {
|
2022-03-15 17:28:55 +01:00
|
|
|
const { uri, source } = playingOptions;
|
|
|
|
|
|
|
|
if (!uri) return;
|
|
|
|
|
2022-02-23 22:13:22 +01:00
|
|
|
const state = getState();
|
|
|
|
const isLive = selectIsActiveLivestreamForUri(state, uri);
|
|
|
|
|
2022-03-15 17:28:55 +01:00
|
|
|
if (!isFloating && !source) dispatch(doSetPrimaryUri(uri));
|
2022-02-01 21:29:00 +01:00
|
|
|
|
2022-03-15 17:28:55 +01:00
|
|
|
if (isPlayable) dispatch(doSetPlayingUri(playingOptions));
|
2022-02-01 21:29:00 +01:00
|
|
|
|
2022-02-23 22:13:22 +01:00
|
|
|
if (!isLive) dispatch(doPlayUri(uri, false, true, (fileInfo) => dispatch(doAnaltyicsPurchaseEvent(fileInfo))));
|
2022-02-01 21:29:00 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-13 16:20:54 +01:00
|
|
|
export function doPlayUri(
|
|
|
|
uri: string,
|
|
|
|
skipCostCheck: boolean = false,
|
|
|
|
saveFileOverride: boolean = false,
|
2021-09-10 19:27:21 +02:00
|
|
|
cb?: () => void,
|
|
|
|
hideFailModal: boolean = false
|
2019-11-13 16:20:54 +01:00
|
|
|
) {
|
2019-08-02 08:28:14 +02:00
|
|
|
return (dispatch: Dispatch, getState: () => any) => {
|
|
|
|
const state = getState();
|
2021-11-10 03:30:03 +01:00
|
|
|
const isMine = selectClaimIsMineForUri(state, uri);
|
2019-08-02 08:28:14 +02:00
|
|
|
const fileInfo = makeSelectFileInfoForUri(uri)(state);
|
2019-08-02 23:03:26 +02:00
|
|
|
const uriIsStreamable = makeSelectUriIsStreamable(uri)(state);
|
|
|
|
const downloadingByOutpoint = selectDownloadingByOutpoint(state);
|
2022-04-20 15:06:30 +02:00
|
|
|
const claimWasPurchased = selectClaimWasPurchasedForUri(state, uri);
|
2019-08-02 23:03:26 +02:00
|
|
|
const alreadyDownloaded = fileInfo && (fileInfo.completed || (fileInfo.blobs_remaining === 0 && uriIsStreamable));
|
|
|
|
const alreadyDownloading = fileInfo && !!downloadingByOutpoint[fileInfo.outpoint];
|
2020-05-21 17:38:28 +02:00
|
|
|
|
|
|
|
if (!IS_WEB && (alreadyDownloading || alreadyDownloaded)) {
|
2019-08-02 23:03:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const daemonSettings = selectDaemonSettings(state);
|
2021-11-19 03:40:01 +01:00
|
|
|
const costInfo = selectCostInfoForUri(state, uri);
|
2019-08-30 01:18:06 +02:00
|
|
|
const cost = (costInfo && Number(costInfo.cost)) || 0;
|
2020-05-21 17:38:28 +02:00
|
|
|
const saveFile = !IS_WEB && (!uriIsStreamable ? true : daemonSettings.save_files || saveFileOverride || cost > 0);
|
2021-11-23 05:29:04 +01:00
|
|
|
const instantPurchaseEnabled = selectClientSetting(state, SETTINGS.INSTANT_PURCHASE_ENABLED);
|
|
|
|
const instantPurchaseMax = selectClientSetting(state, SETTINGS.INSTANT_PURCHASE_MAX);
|
2019-08-02 08:28:14 +02:00
|
|
|
|
2019-08-02 23:03:26 +02:00
|
|
|
function beginGetFile() {
|
2019-11-13 16:20:54 +01:00
|
|
|
dispatch(doPurchaseUriWrapper(uri, cost, saveFile, cb));
|
2019-08-02 23:03:26 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 06:11:10 +02:00
|
|
|
function attemptPlay(instantPurchaseMax = null) {
|
2019-08-02 23:03:26 +02:00
|
|
|
// If you have a file_list entry, you have already purchased the file
|
2020-05-21 17:38:28 +02:00
|
|
|
if (
|
|
|
|
!isMine &&
|
|
|
|
!fileInfo &&
|
|
|
|
!claimWasPurchased &&
|
|
|
|
(!instantPurchaseMax || !instantPurchaseEnabled || cost > instantPurchaseMax)
|
|
|
|
) {
|
2021-09-10 19:27:21 +02:00
|
|
|
if (!hideFailModal) dispatch(doOpenModal(MODALS.AFFIRM_PURCHASE, { uri }));
|
2019-08-02 23:03:26 +02:00
|
|
|
} else {
|
|
|
|
beginGetFile();
|
2019-08-02 08:28:14 +02:00
|
|
|
}
|
2019-08-02 23:03:26 +02:00
|
|
|
}
|
2019-08-02 08:28:14 +02:00
|
|
|
|
2019-08-15 00:27:55 +02:00
|
|
|
if (fileInfo && saveFile && (!fileInfo.download_path || !fileInfo.written_bytes)) {
|
|
|
|
beginGetFile();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-02 23:03:26 +02:00
|
|
|
if (cost === 0 || skipCostCheck) {
|
|
|
|
beginGetFile();
|
2019-08-02 08:28:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-25 00:22:33 +02:00
|
|
|
if (instantPurchaseEnabled) {
|
|
|
|
if (instantPurchaseMax.currency === 'LBC') {
|
|
|
|
attemptPlay(instantPurchaseMax.amount);
|
|
|
|
} else {
|
|
|
|
// Need to convert currency of instant purchase maximum before trying to play
|
|
|
|
Lbryio.getExchangeRates().then(({ LBC_USD }) => {
|
|
|
|
attemptPlay(instantPurchaseMax.amount / LBC_USD);
|
|
|
|
});
|
|
|
|
}
|
2019-08-02 08:28:14 +02:00
|
|
|
} else {
|
2020-04-25 00:22:33 +02:00
|
|
|
attemptPlay();
|
2019-08-02 08:28:14 +02:00
|
|
|
}
|
2017-09-18 04:08:43 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-13 07:35:13 +02:00
|
|
|
export function savePosition(uri: string, position: number) {
|
|
|
|
return (dispatch: Dispatch, getState: () => any) => {
|
|
|
|
const state = getState();
|
|
|
|
const claim = makeSelectClaimForUri(uri)(state);
|
|
|
|
const { claim_id: claimId, txid, nout } = claim;
|
|
|
|
const outpoint = `${txid}:${nout}`;
|
|
|
|
|
2022-02-07 18:51:26 +01:00
|
|
|
try {
|
|
|
|
localStorage.setItem(
|
|
|
|
ACTIONS.SET_CONTENT_POSITION,
|
|
|
|
JSON.stringify({
|
|
|
|
claimId,
|
|
|
|
outpoint,
|
|
|
|
position,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.error('localStorage not available');
|
|
|
|
}
|
|
|
|
|
2018-07-31 14:36:20 +02:00
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.SET_CONTENT_POSITION,
|
|
|
|
data: { claimId, outpoint, position },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2018-07-31 20:07:45 +02:00
|
|
|
|
2020-05-15 03:18:54 +02:00
|
|
|
export function clearPosition(uri: string) {
|
|
|
|
return (dispatch: Dispatch, getState: () => any) => {
|
|
|
|
const state = getState();
|
|
|
|
const claim = makeSelectClaimForUri(uri)(state);
|
|
|
|
const { claim_id: claimId, txid, nout } = claim;
|
|
|
|
const outpoint = `${txid}:${nout}`;
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.CLEAR_CONTENT_POSITION,
|
|
|
|
data: { claimId, outpoint },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-07-31 20:07:45 +02:00
|
|
|
export function doSetContentHistoryItem(uri: string) {
|
2019-03-18 06:09:50 +01:00
|
|
|
return (dispatch: Dispatch) => {
|
2018-07-31 20:07:45 +02:00
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.SET_CONTENT_LAST_VIEWED,
|
|
|
|
data: { uri, lastViewed: Date.now() },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doClearContentHistoryUri(uri: string) {
|
2019-03-18 06:09:50 +01:00
|
|
|
return (dispatch: Dispatch) => {
|
2018-07-31 20:07:45 +02:00
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.CLEAR_CONTENT_HISTORY_URI,
|
|
|
|
data: { uri },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-01 16:06:43 +02:00
|
|
|
export function doClearContentHistoryAll() {
|
2019-03-18 06:09:50 +01:00
|
|
|
return (dispatch: Dispatch) => {
|
2018-07-31 20:07:45 +02:00
|
|
|
dispatch({ type: ACTIONS.CLEAR_CONTENT_HISTORY_ALL });
|
|
|
|
};
|
|
|
|
}
|
Fill in remaining Recsys fields
## Issue
6366 Recsys Evaluation Telemetry
The recommended list from lighthouse is obtained from `makeSelectRecommendedContentForUri`. This list is further tweaked by the GUI (e.g. move autoplay next item to top, remove blocked content, etc.). Recsys wants the final recommendation list and the clicked index (in exact order), so we need pass these info to the videojs recsys plugin somehow. Also, Recsys wants a recommendation list ID as well as the parent (referrer) ID, we so need to track the clicks and navigation.
## General Approach
- It seems easiest to just spew back the final (displayed) list and all the required info to Redux, and the recsys plugin (or anyone else in the future) can grab it.
- Try to touch few files as possible. The dirty work should all reside in `<RecommendedContent>` only.
## Changes
- `ClaimPreview`: add optional parameters to store an ID of the container that it is in (for this case, it is `ClaimList`) as well as the index within the container.
- When clicked, we store the container ID in the navigation history `state` object.
- For general cases, anyone can check this state from `history.location.state` to know which container referred/navigated to the current page. For the recsys use case, we can use this as the `parentUUID`.
- `ClaimList`: just relay `onClick` and set IDs.
- `RecommendedContent`: now handles the uuid generation (for both parent and child) and stores the data in Redux.
2021-07-28 14:07:49 +02:00
|
|
|
|
|
|
|
export const doRecommendationUpdate = (claimId: string, urls: Array<string>, id: string, parentId: string) => (
|
|
|
|
dispatch: Dispatch
|
|
|
|
) => {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.RECOMMENDATION_UPDATED,
|
|
|
|
data: { claimId, urls, id, parentId },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const doRecommendationClicked = (claimId: string, index: number) => (dispatch: Dispatch) => {
|
|
|
|
if (index !== undefined && index !== null) {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.RECOMMENDATION_CLICKED,
|
|
|
|
data: { claimId, index },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2021-09-02 22:05:32 +02:00
|
|
|
|
|
|
|
export function doToggleLoopList(collectionId: string, loop: boolean, hideToast: boolean) {
|
|
|
|
return (dispatch: Dispatch) => {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.TOGGLE_LOOP_LIST,
|
|
|
|
data: { collectionId, loop },
|
|
|
|
});
|
2021-09-10 19:27:21 +02:00
|
|
|
if (!hideToast) {
|
2021-09-02 22:05:32 +02:00
|
|
|
dispatch(
|
|
|
|
doToast({
|
2021-09-10 19:27:21 +02:00
|
|
|
message: loop ? __('Loop is on.') : __('Loop is off.'),
|
2021-09-02 22:05:32 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doToggleShuffleList(currentUri: string, collectionId: string, shuffle: boolean, hideToast: boolean) {
|
|
|
|
return (dispatch: Dispatch, getState: () => any) => {
|
|
|
|
if (shuffle) {
|
|
|
|
const state = getState();
|
|
|
|
const urls = makeSelectUrlsForCollectionId(collectionId)(state);
|
|
|
|
|
|
|
|
let newUrls = urls
|
|
|
|
.map((item) => ({ item, sort: Math.random() }))
|
|
|
|
.sort((a, b) => a.sort - b.sort)
|
|
|
|
.map(({ item }) => item);
|
|
|
|
|
|
|
|
// the currently playing URI should be first in list or else
|
|
|
|
// can get in strange position where it might be in the middle or last
|
|
|
|
// and the shuffled list ends before scrolling through all entries
|
|
|
|
if (currentUri && currentUri !== '') {
|
|
|
|
newUrls.splice(newUrls.indexOf(currentUri), 1);
|
|
|
|
newUrls.splice(0, 0, currentUri);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.TOGGLE_SHUFFLE_LIST,
|
|
|
|
data: { collectionId, newUrls },
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.TOGGLE_SHUFFLE_LIST,
|
|
|
|
data: { collectionId, newUrls: false },
|
|
|
|
});
|
|
|
|
}
|
2021-09-10 19:27:21 +02:00
|
|
|
if (!hideToast) {
|
|
|
|
dispatch(
|
|
|
|
doToast({
|
|
|
|
message: shuffle ? __('Shuffle is on.') : __('Shuffle is off.'),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2021-09-02 22:05:32 +02:00
|
|
|
};
|
|
|
|
}
|
2022-05-18 11:01:25 +02:00
|
|
|
|
|
|
|
export function doSetLastViewedAnnouncement(hash: string) {
|
|
|
|
return (dispatch: Dispatch) => {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.SET_LAST_VIEWED_ANNOUNCEMENT,
|
|
|
|
data: hash,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2022-05-24 14:24:04 +02:00
|
|
|
|
|
|
|
export function doSetRecsysEntries(entries: { [ClaimId]: RecsysEntry }) {
|
|
|
|
return (dispatch: Dispatch) => {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.SET_RECSYS_ENTRIES,
|
|
|
|
data: entries,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends any lingering recsys entries from the previous session and deletes it.
|
|
|
|
*
|
|
|
|
* Should only be called on startup, before a new cycle of recsys data is
|
|
|
|
* collected.
|
|
|
|
*
|
|
|
|
* @returns {(function(Dispatch, GetState): void)|*}
|
|
|
|
*/
|
|
|
|
export function doSendPastRecsysEntries() {
|
|
|
|
return (dispatch: Dispatch, getState: GetState) => {
|
|
|
|
const state = getState();
|
|
|
|
const entries = selectRecsysEntries(state);
|
|
|
|
if (entries) {
|
|
|
|
RecSys.sendEntries(entries, true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|