From 320e4e6bb718f7852489ad9099b328659dec260f Mon Sep 17 00:00:00 2001 From: Franco Montenegro Date: Tue, 9 Aug 2022 18:21:43 -0300 Subject: [PATCH] Perform doFetchModBlockedList in splash. --- ui/component/app/index.js | 3 +- ui/component/app/view.jsx | 3 -- ui/component/splash/index.js | 2 + ui/component/splash/view.jsx | 9 +++- ui/redux/actions/comments.js | 100 +++++++++++++++++------------------ 5 files changed, 58 insertions(+), 59 deletions(-) diff --git a/ui/component/app/index.js b/ui/component/app/index.js index 4726fe72c..f967309a9 100644 --- a/ui/component/app/index.js +++ b/ui/component/app/index.js @@ -30,7 +30,7 @@ import { doSetActiveChannel, doSetIncognito, } from 'redux/actions/app'; -import { doFetchModBlockedList, doFetchCommentModAmIList } from 'redux/actions/comments'; +import { doFetchCommentModAmIList } from 'redux/actions/comments'; import App from './view'; const select = (state) => ({ @@ -67,7 +67,6 @@ const perform = (dispatch) => ({ setReferrer: (referrer, doClaim) => dispatch(doUserSetReferrer(referrer, doClaim)), setActiveChannelIfNotSet: () => dispatch(doSetActiveChannel()), setIncognito: () => dispatch(doSetIncognito()), - fetchModBlockedList: () => dispatch(doFetchModBlockedList()), resolveUris: (uris) => dispatch(doResolveUris(uris)), fetchModAmIList: () => dispatch(doFetchCommentModAmIList()), }); diff --git a/ui/component/app/view.jsx b/ui/component/app/view.jsx index 4c5f5f849..5acc90e94 100644 --- a/ui/component/app/view.jsx +++ b/ui/component/app/view.jsx @@ -73,7 +73,6 @@ type Props = { subscriptions: Array, setActiveChannelIfNotSet: () => void, setIncognito: (boolean) => void, - fetchModBlockedList: () => void, resolveUris: (Array) => void, fetchModAmIList: () => void, isUpdateModalDisplayed: boolean, @@ -108,7 +107,6 @@ function App(props: Props) { activeChannelId, setActiveChannelIfNotSet, setIncognito, - fetchModBlockedList, resolveUris, subscriptions, fetchModAmIList, @@ -233,7 +231,6 @@ function App(props: Props) { } if (hasMyChannels) { - fetchModBlockedList(); fetchModAmIList(); } }, [hasMyChannels, hasNoChannels, hasActiveChannelClaim, setActiveChannelIfNotSet, setIncognito]); diff --git a/ui/component/splash/index.js b/ui/component/splash/index.js index 8fde0e9c2..845e87ad7 100644 --- a/ui/component/splash/index.js +++ b/ui/component/splash/index.js @@ -2,6 +2,7 @@ import * as MODALS from 'constants/modal_types'; import { connect } from 'react-redux'; import { selectDaemonVersionMatched, selectModal, selectSplashAnimationEnabled } from 'redux/selectors/app'; import { doCheckDaemonVersion, doOpenModal, doHideModal, doToggleSplashAnimation } from 'redux/actions/app'; +import { doFetchModBlockedList } from 'redux/actions/comments'; import { doClearDaemonSetting } from 'redux/actions/settings'; import * as DAEMON_SETTINGS from 'constants/daemon_settings'; import { doToast } from 'redux/actions/notifications'; @@ -21,6 +22,7 @@ const perform = (dispatch) => ({ toggleSplashAnimation: () => dispatch(doToggleSplashAnimation()), clearWalletServers: () => dispatch(doClearDaemonSetting(DAEMON_SETTINGS.LBRYUM_SERVERS)), doShowSnackBar: (message) => dispatch(doToast({ isError: true, message })), + fetchModBlockedList: () => dispatch(doFetchModBlockedList()), }); export default connect(select, perform)(SplashScreen); diff --git a/ui/component/splash/view.jsx b/ui/component/splash/view.jsx index 1dc5a2e6f..21f376463 100644 --- a/ui/component/splash/view.jsx +++ b/ui/component/splash/view.jsx @@ -31,6 +31,7 @@ type Props = { toggleSplashAnimation: () => void, clearWalletServers: () => void, doShowSnackBar: (string) => void, + fetchModBlockedList: () => Promise, }; type State = { @@ -197,10 +198,14 @@ export default class SplashScreen extends React.PureComponent { this.setState({ launchWithIncompatibleDaemon: true }, () => this.continueAppLaunch()); } - continueAppLaunch() { + continueAppLaunch = async () => { const { daemonVersionMatched, onReadyToLaunch } = this.props; const { isRunning, launchWithIncompatibleDaemon } = this.state; + try { + await this.props.fetchModBlockedList(); + } catch (e) {} + if (daemonVersionMatched) { onReadyToLaunch(); } else if (launchWithIncompatibleDaemon && isRunning) { @@ -209,7 +214,7 @@ export default class SplashScreen extends React.PureComponent { // If it isn't running, this function will be called after the daemon is started onReadyToLaunch(); } - } + }; timeout: ?TimeoutID; diff --git a/ui/redux/actions/comments.js b/ui/redux/actions/comments.js index 375a96757..2886a1fc3 100644 --- a/ui/redux/actions/comments.js +++ b/ui/redux/actions/comments.js @@ -1186,64 +1186,60 @@ export function doFetchModBlockedList() { const moderatorTimeoutMap = {}; const blockListsPerChannel = res.map((r) => r.value); - blockListsPerChannel - .sort((a, b) => { - return 1; - }) - .forEach((channelBlockLists) => { - const storeList = (fetchedList, blockedList, timeoutMap, blockedByMap) => { - if (fetchedList) { - fetchedList.forEach((blockedChannel) => { - if (blockedChannel.blocked_channel_name) { - const channelUri = buildURI({ - channelName: blockedChannel.blocked_channel_name, - channelClaimId: blockedChannel.blocked_channel_id, - }); + blockListsPerChannel.forEach((channelBlockLists) => { + const storeList = (fetchedList, blockedList, timeoutMap, blockedByMap) => { + if (fetchedList) { + fetchedList.forEach((blockedChannel) => { + if (blockedChannel.blocked_channel_name) { + const channelUri = buildURI({ + channelName: blockedChannel.blocked_channel_name, + channelClaimId: blockedChannel.blocked_channel_id, + }); - if (!blockedList.find((blockedChannel) => isURIEqual(blockedChannel.channelUri, channelUri))) { - blockedList.push({ channelUri, blockedAt: blockedChannel.blocked_at }); + if (!blockedList.find((blockedChannel) => isURIEqual(blockedChannel.channelUri, channelUri))) { + blockedList.push({ channelUri, blockedAt: blockedChannel.blocked_at }); - if (blockedChannel.banned_for) { - timeoutMap[channelUri] = { - blockedAt: blockedChannel.blocked_at, - bannedFor: blockedChannel.banned_for, - banRemaining: blockedChannel.ban_remaining, - }; - } - } - - if (blockedByMap !== undefined) { - const blockedByChannelUri = buildURI({ - channelName: blockedChannel.blocked_by_channel_name, - channelClaimId: blockedChannel.blocked_by_channel_id, - }); - - if (blockedByMap[channelUri]) { - if (!blockedByMap[channelUri].includes(blockedByChannelUri)) { - blockedByMap[channelUri].push(blockedByChannelUri); - } - } else { - blockedByMap[channelUri] = [blockedByChannelUri]; - } + if (blockedChannel.banned_for) { + timeoutMap[channelUri] = { + blockedAt: blockedChannel.blocked_at, + bannedFor: blockedChannel.banned_for, + banRemaining: blockedChannel.ban_remaining, + }; } } - }); - } - }; - const blocked_channels = channelBlockLists && channelBlockLists.blocked_channels; - const globally_blocked_channels = channelBlockLists && channelBlockLists.globally_blocked_channels; - const delegated_blocked_channels = channelBlockLists && channelBlockLists.delegated_blocked_channels; + if (blockedByMap !== undefined) { + const blockedByChannelUri = buildURI({ + channelName: blockedChannel.blocked_by_channel_name, + channelClaimId: blockedChannel.blocked_by_channel_id, + }); - storeList(blocked_channels, personalBlockList, personalTimeoutMap); - storeList(globally_blocked_channels, adminBlockList, adminTimeoutMap); - storeList( - delegated_blocked_channels, - moderatorBlockList, - moderatorTimeoutMap, - moderatorBlockListDelegatorsMap - ); - }); + if (blockedByMap[channelUri]) { + if (!blockedByMap[channelUri].includes(blockedByChannelUri)) { + blockedByMap[channelUri].push(blockedByChannelUri); + } + } else { + blockedByMap[channelUri] = [blockedByChannelUri]; + } + } + } + }); + } + }; + + const blocked_channels = channelBlockLists && channelBlockLists.blocked_channels; + const globally_blocked_channels = channelBlockLists && channelBlockLists.globally_blocked_channels; + const delegated_blocked_channels = channelBlockLists && channelBlockLists.delegated_blocked_channels; + + storeList(blocked_channels, personalBlockList, personalTimeoutMap); + storeList(globally_blocked_channels, adminBlockList, adminTimeoutMap); + storeList( + delegated_blocked_channels, + moderatorBlockList, + moderatorTimeoutMap, + moderatorBlockListDelegatorsMap + ); + }); dispatch({ type: ACTIONS.COMMENT_MODERATION_BLOCK_LIST_COMPLETED,