From d884f1ea72d92b0d82cbfdeefb93929a0359813d Mon Sep 17 00:00:00 2001 From: infinite-persistence <64950861+infinite-persistence@users.noreply.github.com> Date: Tue, 9 Nov 2021 22:43:02 +0800 Subject: [PATCH] Block: pass comment ID for deletion when being blocked. (#255) * Simplify dispatch map Since none of dispatches are doing any custom transformation, just use a direct map. The number of arguments for the comment function are getting crazy. * Block: pass comment ID for deletion when being blocked. --- flow-typed/Comment.js | 4 +- ui/component/channelBlockButton/view.jsx | 12 +++--- ui/component/claimMenuList/view.jsx | 4 +- ui/component/commentMenuList/view.jsx | 8 +++- ui/modal/modalBlockChannel/index.js | 12 +++--- ui/modal/modalBlockChannel/view.jsx | 46 ++++++++++++-------- ui/redux/actions/comments.js | 55 +++++++++++++++++++----- 7 files changed, 95 insertions(+), 46 deletions(-) diff --git a/flow-typed/Comment.js b/flow-typed/Comment.js index 0a497a324..d64efc738 100644 --- a/flow-typed/Comment.js +++ b/flow-typed/Comment.js @@ -204,9 +204,11 @@ declare type ModerationBlockParams = { // Creator that Moderator is delegated from. Used for delegated moderation creator_channel_id?: string, creator_channel_name?: string, + // ID of comment to remove as part of this block + offending_comment_id?: string, // Blocks identity from comment universally, requires Admin rights on commentron instance block_all?: boolean, - time_out?: number, + time_out?: ?number, // If true will delete all comments of the offender, requires Admin rights on commentron for universal delete delete_all?: boolean, // The usual signature stuff diff --git a/ui/component/channelBlockButton/view.jsx b/ui/component/channelBlockButton/view.jsx index 6a659228b..277fc10f1 100644 --- a/ui/component/channelBlockButton/view.jsx +++ b/ui/component/channelBlockButton/view.jsx @@ -11,11 +11,11 @@ type Props = { isBlockingOrUnBlocking: boolean, isToggling: boolean, doCommentModUnBlock: (string, boolean) => void, - doCommentModBlock: (string, ?Number, boolean) => void, + doCommentModBlock: (string, ?string, ?Number, boolean) => void, doCommentModUnBlockAsAdmin: (string, string) => void, - doCommentModBlockAsAdmin: (string, string) => void, + doCommentModBlockAsAdmin: (string, ?string, ?string) => void, doCommentModUnBlockAsModerator: (string, string, string) => void, - doCommentModBlockAsModerator: (string, string, string) => void, + doCommentModBlockAsModerator: (string, ?string, string, ?string) => void, }; function ChannelBlockButton(props: Props) { @@ -41,7 +41,7 @@ function ChannelBlockButton(props: Props) { if (isBlocked) { doCommentModUnBlock(uri, false); } else { - doCommentModBlock(uri, undefined, false); + doCommentModBlock(uri, undefined, undefined, false); } break; @@ -50,7 +50,7 @@ function ChannelBlockButton(props: Props) { if (isBlocked) { doCommentModUnBlockAsModerator(uri, creatorUri, ''); } else { - doCommentModBlockAsModerator(uri, creatorUri, ''); + doCommentModBlockAsModerator(uri, undefined, creatorUri, undefined); } } break; @@ -59,7 +59,7 @@ function ChannelBlockButton(props: Props) { if (isBlocked) { doCommentModUnBlockAsAdmin(uri, ''); } else { - doCommentModBlockAsAdmin(uri, ''); + doCommentModBlockAsAdmin(uri, undefined, undefined); } break; } diff --git a/ui/component/claimMenuList/view.jsx b/ui/component/claimMenuList/view.jsx index f4b458841..a5d105f72 100644 --- a/ui/component/claimMenuList/view.jsx +++ b/ui/component/claimMenuList/view.jsx @@ -39,7 +39,7 @@ type Props = { doChannelUnmute: (string) => void, doCommentModBlock: (string) => void, doCommentModUnBlock: (string) => void, - doCommentModBlockAsAdmin: (string, string) => void, + doCommentModBlockAsAdmin: (commenterUri: string, offendingCommentId: ?string, blockerId: ?string) => void, doCommentModUnBlockAsAdmin: (string, string) => void, doCollectionEdit: (string, any) => void, hasClaimInWatchLater: boolean, @@ -228,7 +228,7 @@ function ClaimMenuList(props: Props) { if (channelIsAdminBlocked) { doCommentModUnBlockAsAdmin(contentChannelUri, ''); } else { - doCommentModBlockAsAdmin(contentChannelUri, ''); + doCommentModBlockAsAdmin(contentChannelUri, undefined, undefined); } } diff --git a/ui/component/commentMenuList/view.jsx b/ui/component/commentMenuList/view.jsx index 83994eb0a..ca8d389cd 100644 --- a/ui/component/commentMenuList/view.jsx +++ b/ui/component/commentMenuList/view.jsx @@ -197,7 +197,13 @@ function CommentMenuList(props: Props) { <> openModal(MODALS.BLOCK_CHANNEL, { contentUri: uri, commenterUri: authorUri })} + onSelect={() => + openModal(MODALS.BLOCK_CHANNEL, { + contentUri: uri, + commenterUri: authorUri, + offendingCommentId: commentId, + }) + } > {getBlockOptionElem()} diff --git a/ui/modal/modalBlockChannel/index.js b/ui/modal/modalBlockChannel/index.js index 242a94e84..9e02ceb5a 100644 --- a/ui/modal/modalBlockChannel/index.js +++ b/ui/modal/modalBlockChannel/index.js @@ -13,11 +13,11 @@ const select = (state, props) => ({ moderationDelegatorsById: selectModerationDelegatorsById(state), }); -const perform = (dispatch) => ({ - closeModal: () => dispatch(doHideModal()), - commentModBlock: (a, b) => dispatch(doCommentModBlock(a, b)), - commentModBlockAsAdmin: (a, b, c) => dispatch(doCommentModBlockAsAdmin(a, b, c)), - commentModBlockAsModerator: (a, b, c, d) => dispatch(doCommentModBlockAsModerator(a, b, c, d)), -}); +const perform = { + doHideModal, + doCommentModBlock, + doCommentModBlockAsAdmin, + doCommentModBlockAsModerator, +}; export default connect(select, perform)(ModalBlockChannel); diff --git a/ui/modal/modalBlockChannel/view.jsx b/ui/modal/modalBlockChannel/view.jsx index 934a6e1aa..be24b7dee 100644 --- a/ui/modal/modalBlockChannel/view.jsx +++ b/ui/modal/modalBlockChannel/view.jsx @@ -27,18 +27,24 @@ const BLOCK = { type Props = { contentUri: string, commenterUri: string, - // --- select --- + offendingCommentId?: string, + // --- redux --- activeChannelClaim: ?ChannelClaim, contentClaim: ?Claim, moderationDelegatorsById: { [string]: { global: boolean, delegators: { name: string, claimId: string } } }, - // --- perform --- - closeModal: () => void, - commentModBlock: (commenterUri: string, timeoutSec: ?number) => void, - commentModBlockAsAdmin: (commenterUri: string, blockerId: string, timeoutSec: ?number) => void, - commentModBlockAsModerator: ( + doHideModal: () => void, + doCommentModBlock: (commenterUri: string, offendingCommentId: ?string, timeoutSec: ?number) => void, + doCommentModBlockAsAdmin: ( commenterUri: string, + offendingCommentId: ?string, + blockerId: ?string, + timeoutSec: ?number + ) => void, + doCommentModBlockAsModerator: ( + commenterUri: string, + offendingCommentId: ?string, creatorUri: string, - blockerId: string, + blockerId: ?string, timeoutSec: ?number ) => void, }; @@ -46,13 +52,14 @@ type Props = { export default function ModalBlockChannel(props: Props) { const { commenterUri, + offendingCommentId, activeChannelClaim, contentClaim, moderationDelegatorsById, - closeModal, - commentModBlock, - commentModBlockAsAdmin, - commentModBlockAsModerator, + doHideModal, + doCommentModBlock, + doCommentModBlockAsAdmin, + doCommentModBlockAsModerator, } = props; const contentChannelClaim = getChannelFromClaim(contentClaim); @@ -227,13 +234,14 @@ export default function ModalBlockChannel(props: Props) { switch (tab) { case TAB.PERSONAL: - commentModBlock(commenterUri, duration); + doCommentModBlock(commenterUri, offendingCommentId, duration); break; case TAB.MODERATOR: if (activeChannelClaim && contentChannelClaim) { - commentModBlockAsModerator( + doCommentModBlockAsModerator( commenterUri, + offendingCommentId, contentChannelClaim.permanent_url, activeChannelClaim.claim_id, duration @@ -243,12 +251,12 @@ export default function ModalBlockChannel(props: Props) { case TAB.ADMIN: if (activeChannelClaim) { - commentModBlockAsAdmin(commenterUri, activeChannelClaim.claim_id, duration); + doCommentModBlockAsAdmin(commenterUri, offendingCommentId, activeChannelClaim.claim_id, duration); } break; } - closeModal(); + doHideModal(); } // ************************************************************************** @@ -256,13 +264,13 @@ export default function ModalBlockChannel(props: Props) { if (isPersonalTheOnlyTab && !isTimeoutAvail) { // There's only 1 option. Just execute it and don't show the modal. - commentModBlock(commenterUri); - closeModal(); + doCommentModBlock(commenterUri, offendingCommentId); + doHideModal(); return null; } return ( - +
diff --git a/ui/redux/actions/comments.js b/ui/redux/actions/comments.js index 009b0c244..a2408c31f 100644 --- a/ui/redux/actions/comments.js +++ b/ui/redux/actions/comments.js @@ -862,8 +862,9 @@ function doCommentModToggleBlock( creatorUri: string, blockerIds: Array, // [] = use all my channels blockLevel: string, - timeoutSec?: number, - showLink: boolean = false + timeoutSec: ?number, + showLink: boolean = false, + offendingCommentId: ?string = undefined ) { return async (dispatch: Dispatch, getState: GetState) => { const state = getState(); @@ -962,6 +963,7 @@ function doCommentModToggleBlock( signing_ts: signatureData.signing_ts, creator_channel_id: creatorUri ? creatorId : undefined, creator_channel_name: creatorUri ? creatorName : undefined, + offending_comment_id: offendingCommentId && !unblock ? offendingCommentId : undefined, block_all: unblock ? undefined : blockLevel === BLOCK_LEVEL.ADMIN, global_un_block: unblock ? blockLevel === BLOCK_LEVEL.ADMIN : undefined, ...sharedModBlockParams, @@ -1041,14 +1043,26 @@ function doCommentModToggleBlock( /** * Blocks the commenter for all channels that I own. * + * Update: the above it not entirely true now. A blocked channel's comment won't + * appear for you anywhere since we now filter the comments at the app-side + * before showing it. + * * @param commenterUri + * @param offendingCommentId * @param timeoutSec * @param showLink * @returns {function(Dispatch): *} */ -export function doCommentModBlock(commenterUri: string, timeoutSec?: number, showLink: boolean = true) { +export function doCommentModBlock( + commenterUri: string, + offendingCommentId: ?string, + timeoutSec: ?number, + showLink: boolean = true +) { return (dispatch: Dispatch) => { - return dispatch(doCommentModToggleBlock(false, commenterUri, '', [], BLOCK_LEVEL.SELF, timeoutSec, showLink)); + return dispatch( + doCommentModToggleBlock(false, commenterUri, '', [], BLOCK_LEVEL.SELF, timeoutSec, showLink, offendingCommentId) + ); }; } @@ -1056,14 +1070,29 @@ export function doCommentModBlock(commenterUri: string, timeoutSec?: number, sho * Blocks the commenter using the given channel that has Global privileges. * * @param commenterUri - * @param blockerId + * @param offendingCommentId + * @param blockerId Your specific channel ID to block with, or pass 'undefined' to block it for all of your channels. * @param timeoutSec * @returns {function(Dispatch): *} */ -export function doCommentModBlockAsAdmin(commenterUri: string, blockerId: string, timeoutSec?: number) { +export function doCommentModBlockAsAdmin( + commenterUri: string, + offendingCommentId: ?string, + blockerId: ?string, + timeoutSec: ?number +) { return (dispatch: Dispatch) => { return dispatch( - doCommentModToggleBlock(false, commenterUri, '', blockerId ? [blockerId] : [], BLOCK_LEVEL.ADMIN, timeoutSec) + doCommentModToggleBlock( + false, + commenterUri, + '', + blockerId ? [blockerId] : [], + BLOCK_LEVEL.ADMIN, + timeoutSec, + false, + offendingCommentId + ) ); }; } @@ -1073,16 +1102,18 @@ export function doCommentModBlockAsAdmin(commenterUri: string, blockerId: string * moderation rights by the creator. * * @param commenterUri + * @param offendingCommentId * @param creatorUri - * @param blockerId + * @param blockerId Your specific channel ID to block with, or pass 'undefined' to block it for all of your channels. * @param timeoutSec * @returns {function(Dispatch): *} */ export function doCommentModBlockAsModerator( commenterUri: string, + offendingCommentId: ?string, creatorUri: string, - blockerId: string, - timeoutSec?: number + blockerId: ?string, + timeoutSec: ?number ) { return (dispatch: Dispatch) => { return dispatch( @@ -1092,7 +1123,9 @@ export function doCommentModBlockAsModerator( creatorUri, blockerId ? [blockerId] : [], BLOCK_LEVEL.MODERATOR, - timeoutSec + timeoutSec, + false, + offendingCommentId ) ); };