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.
This commit is contained in:
infinite-persistence 2021-11-09 22:43:02 +08:00 committed by GitHub
parent 0e2bb350c0
commit bc67379c26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 96 additions and 47 deletions

View file

@ -206,9 +206,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

View file

@ -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;
}

View file

@ -92,7 +92,7 @@ const perform = (dispatch) => ({
doChannelUnmute: (channelUri) => dispatch(doChannelUnmute(channelUri)),
doCommentModBlock: (channelUri) => dispatch(doCommentModBlock(channelUri)),
doCommentModUnBlock: (channelUri) => dispatch(doCommentModUnBlock(channelUri)),
doCommentModBlockAsAdmin: (commenterUri, blockerId) => dispatch(doCommentModBlockAsAdmin(commenterUri, blockerId)),
doCommentModBlockAsAdmin: (a, b, c) => dispatch(doCommentModBlockAsAdmin(a, b, c)),
doCommentModUnBlockAsAdmin: (commenterUri, blockerId) =>
dispatch(doCommentModUnBlockAsAdmin(commenterUri, blockerId)),
doChannelSubscribe: (subscription) => dispatch(doChannelSubscribe(subscription)),

View file

@ -45,7 +45,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,
@ -237,7 +237,7 @@ function ClaimMenuList(props: Props) {
if (channelIsAdminBlocked) {
doCommentModUnBlockAsAdmin(contentChannelUri, '');
} else {
doCommentModBlockAsAdmin(contentChannelUri, '');
doCommentModBlockAsAdmin(contentChannelUri, undefined, undefined);
}
}

View file

@ -218,7 +218,13 @@ function CommentMenuList(props: Props) {
<>
<MenuItem
className="comment__menu-option"
onSelect={() => openModal(MODALS.BLOCK_CHANNEL, { contentUri: uri, commenterUri: authorUri })}
onSelect={() =>
openModal(MODALS.BLOCK_CHANNEL, {
contentUri: uri,
commenterUri: authorUri,
offendingCommentId: commentId,
})
}
>
{getBlockOptionElem()}
</MenuItem>

View file

@ -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);

View file

@ -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 (
<Modal isOpen type="card" onAborted={closeModal}>
<Modal isOpen type="card" onAborted={doHideModal}>
<Card
title={__('Block Channel')}
subtitle={getCommenterPreview(commenterUri)}
@ -301,7 +309,7 @@ export default function ModalBlockChannel(props: Props) {
<div className="block-modal--finalize">
<div className="section__actions">
<Button button="primary" label={__('Block')} onClick={handleBlock} disabled={blockButtonDisabled} />
<Button button="link" label={__('Cancel')} onClick={closeModal} />
<Button button="link" label={__('Cancel')} onClick={doHideModal} />
{getActiveChannelElem()}
</div>
</div>

View file

@ -872,8 +872,9 @@ function doCommentModToggleBlock(
creatorUri: string,
blockerIds: Array<string>, // [] = 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();
@ -972,6 +973,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,
@ -1051,14 +1053,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)
);
};
}
@ -1066,14 +1080,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
)
);
};
}
@ -1083,16 +1112,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(
@ -1102,7 +1133,9 @@ export function doCommentModBlockAsModerator(
creatorUri,
blockerId ? [blockerId] : [],
BLOCK_LEVEL.MODERATOR,
timeoutSec
timeoutSec,
false,
offendingCommentId
)
);
};