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:
parent
0b41fc041a
commit
d884f1ea72
7 changed files with 95 additions and 46 deletions
4
flow-typed/Comment.js
vendored
4
flow-typed/Comment.js
vendored
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -197,7 +197,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>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -862,8 +862,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();
|
||||
|
@ -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
|
||||
)
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue