From 26efe9fd45a4e250fc14fa28f42fd32efd9a4e49 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Wed, 7 Jul 2021 21:33:22 +0800 Subject: [PATCH] Enable 'slow mode' in comments ## Issue Sub item in <6119 Creator Settings: beyond "Muted Words"> ## Changes - Removed the existing 5s min gap on livestreams. - Enabled the 'slow mode min gap' in Creator Settings This change now affects both comments in claims and livestream comments. --- static/app-strings.json | 3 ++- ui/component/commentCreate/index.js | 2 -- ui/component/commentCreate/view.jsx | 14 -------------- ui/page/settingsCreator/view.jsx | 22 ++++++++++------------ ui/redux/actions/comments.js | 3 +++ 5 files changed, 15 insertions(+), 29 deletions(-) diff --git a/static/app-strings.json b/static/app-strings.json index 14b5f41c4..a0eff0434 100644 --- a/static/app-strings.json +++ b/static/app-strings.json @@ -1445,6 +1445,7 @@ "Unable to comment. This channel has blocked you.": "Unable to comment. This channel has blocked you.", "Unable to comment. Your channel has been blocked by an admin.": "Unable to comment. Your channel has been blocked by an admin.", "Unable to comment. The content owner has disabled comments.": "Unable to comment. The content owner has disabled comments.", + "The creator has set a minimum time gap between comments. Try again later.": "The creator has set a minimum time gap between comments. Try again later.", "The comment contains contents that are blocked by %author%": "The comment contains contents that are blocked by %author%", "Your channel is still being setup, try again in a few moments.": "Your channel is still being setup, try again in a few moments.", "Unable to delete this comment, please try again later.": "Unable to delete this comment, please try again later.", @@ -1916,7 +1917,7 @@ "Suggestions": "Suggestions", "Add words to block": "Add words to block", "Enable comments for channel.": "Enable comments for channel.", - "Minimum time gap in seconds for Slow Mode in livestream chat.": "Minimum time gap in seconds for Slow Mode in livestream chat.", + "Minimum time gap in seconds between comments (affects livestream chat as well).": "Minimum time gap in seconds between comments (affects livestream chat as well).", "Minimum %lbc% tip amount for comments": "Minimum %lbc% tip amount for comments", "Enabling a minimum amount to comment will force all comments, including livestreams, to have tips associated with them. This can help prevent spam.": "Enabling a minimum amount to comment will force all comments, including livestreams, to have tips associated with them. This can help prevent spam.", "Minimum %lbc% tip amount for hyperchats": "Minimum %lbc% tip amount for hyperchats", diff --git a/ui/component/commentCreate/index.js b/ui/component/commentCreate/index.js index 33fb66833..adcf4e2f9 100644 --- a/ui/component/commentCreate/index.js +++ b/ui/component/commentCreate/index.js @@ -11,7 +11,6 @@ import { doCommentCreate } from 'redux/actions/comments'; import { selectUserVerifiedEmail } from 'redux/selectors/user'; import { selectActiveChannelClaim } from 'redux/selectors/app'; import { makeSelectCommentsDisabledForUri } from 'redux/selectors/comments'; -import { doToast } from 'redux/actions/notifications'; import { CommentCreate } from './view'; const select = (state, props) => ({ @@ -29,7 +28,6 @@ const perform = (dispatch, ownProps) => ({ dispatch(doCommentCreate(comment, claimId, parentId, ownProps.uri, ownProps.livestream, txid)), openModal: (modal, props) => dispatch(doOpenModal(modal, props)), setActiveChannel: (claimId) => dispatch(doSetActiveChannel(claimId)), - toast: (message) => dispatch(doToast({ message, isError: true })), sendTip: (params, callback, errorCallback) => dispatch(doSendTip(params, false, callback, errorCallback, false)), }); diff --git a/ui/component/commentCreate/view.jsx b/ui/component/commentCreate/view.jsx index aa5443cbc..e683d9b20 100644 --- a/ui/component/commentCreate/view.jsx +++ b/ui/component/commentCreate/view.jsx @@ -17,8 +17,6 @@ import ChannelThumbnail from 'component/channelThumbnail'; import UriIndicator from 'component/uriIndicator'; import Empty from 'component/common/empty'; -const COMMENT_SLOW_MODE_SECONDS = 5; - type Props = { uri: string, claim: StreamClaim, @@ -54,7 +52,6 @@ export function CommentCreate(props: Props) { parentId, activeChannelClaim, livestream, - toast, claimIsMine, sendTip, justCommented, @@ -72,7 +69,6 @@ export function CommentCreate(props: Props) { const [isReviewingSupportComment, setIsReviewingSupportComment] = React.useState(); const [tipAmount, setTipAmount] = React.useState(1); const [commentValue, setCommentValue] = React.useState(''); - const [lastCommentTime, setLastCommentTime] = React.useState(); const [advancedEditor, setAdvancedEditor] = usePersistedState('comment-editor-mode', false); const hasChannels = channels && channels.length; const disabled = isSubmitting || !activeChannelClaim || !commentValue.length; @@ -107,15 +103,6 @@ export function CommentCreate(props: Props) { function handleSubmit() { if (activeChannelClaim && commentValue.length) { - const timeUntilCanComment = !lastCommentTime - ? 0 - : (lastCommentTime - Date.now()) / 1000 + COMMENT_SLOW_MODE_SECONDS; - - if (livestream && !claimIsMine && timeUntilCanComment > 0) { - toast(__('Slowmode is on. You can comment again in %time% seconds.', { time: Math.ceil(timeUntilCanComment) })); - return; - } - handleCreateComment(); } } @@ -163,7 +150,6 @@ export function CommentCreate(props: Props) { if (res && res.signature) { setCommentValue(''); - setLastCommentTime(Date.now()); setIsReviewingSupportComment(false); setIsSupportComment(false); setCommentFailure(false); diff --git a/ui/page/settingsCreator/view.jsx b/ui/page/settingsCreator/view.jsx index c89a662b2..09c30cc5c 100644 --- a/ui/page/settingsCreator/view.jsx +++ b/ui/page/settingsCreator/view.jsx @@ -265,18 +265,16 @@ export default function SettingsCreatorPage(props: Props) { checked={commentsEnabled} onChange={() => setSettings({ comments_enabled: !commentsEnabled })} /> - {FEATURE_IS_READY && ( - setSettings({ slow_mode_min_gap: e.target.value })} - /> - )} + setSettings({ slow_mode_min_gap: parseInt(e.target.value) })} + /> } /> diff --git a/ui/redux/actions/comments.js b/ui/redux/actions/comments.js index bd14bf9c3..4661f3278 100644 --- a/ui/redux/actions/comments.js +++ b/ui/redux/actions/comments.js @@ -340,6 +340,9 @@ export function doCommentCreate( case 'comments are disabled by the creator': toastMessage = __('Unable to comment. The content owner has disabled comments.'); break; + case 'the creator has a min gap between comments set.': + toastMessage = __('The creator has set a minimum time gap between comments. Try again later.'); + break; default: const BLOCKED_WORDS_ERR_MSG = 'the comment contents are blocked by'; if (error.message.startsWith(BLOCKED_WORDS_ERR_MSG)) {