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
0e2bb350c0
commit
bc67379c26
8 changed files with 96 additions and 47 deletions
4
flow-typed/Comment.js
vendored
4
flow-typed/Comment.js
vendored
|
@ -206,9 +206,11 @@ declare type ModerationBlockParams = {
|
||||||
// Creator that Moderator is delegated from. Used for delegated moderation
|
// Creator that Moderator is delegated from. Used for delegated moderation
|
||||||
creator_channel_id?: string,
|
creator_channel_id?: string,
|
||||||
creator_channel_name?: 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
|
// Blocks identity from comment universally, requires Admin rights on commentron instance
|
||||||
block_all?: boolean,
|
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
|
// If true will delete all comments of the offender, requires Admin rights on commentron for universal delete
|
||||||
delete_all?: boolean,
|
delete_all?: boolean,
|
||||||
// The usual signature stuff
|
// The usual signature stuff
|
||||||
|
|
|
@ -11,11 +11,11 @@ type Props = {
|
||||||
isBlockingOrUnBlocking: boolean,
|
isBlockingOrUnBlocking: boolean,
|
||||||
isToggling: boolean,
|
isToggling: boolean,
|
||||||
doCommentModUnBlock: (string, boolean) => void,
|
doCommentModUnBlock: (string, boolean) => void,
|
||||||
doCommentModBlock: (string, ?Number, boolean) => void,
|
doCommentModBlock: (string, ?string, ?Number, boolean) => void,
|
||||||
doCommentModUnBlockAsAdmin: (string, string) => void,
|
doCommentModUnBlockAsAdmin: (string, string) => void,
|
||||||
doCommentModBlockAsAdmin: (string, string) => void,
|
doCommentModBlockAsAdmin: (string, ?string, ?string) => void,
|
||||||
doCommentModUnBlockAsModerator: (string, string, string) => void,
|
doCommentModUnBlockAsModerator: (string, string, string) => void,
|
||||||
doCommentModBlockAsModerator: (string, string, string) => void,
|
doCommentModBlockAsModerator: (string, ?string, string, ?string) => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
function ChannelBlockButton(props: Props) {
|
function ChannelBlockButton(props: Props) {
|
||||||
|
@ -41,7 +41,7 @@ function ChannelBlockButton(props: Props) {
|
||||||
if (isBlocked) {
|
if (isBlocked) {
|
||||||
doCommentModUnBlock(uri, false);
|
doCommentModUnBlock(uri, false);
|
||||||
} else {
|
} else {
|
||||||
doCommentModBlock(uri, undefined, false);
|
doCommentModBlock(uri, undefined, undefined, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ function ChannelBlockButton(props: Props) {
|
||||||
if (isBlocked) {
|
if (isBlocked) {
|
||||||
doCommentModUnBlockAsModerator(uri, creatorUri, '');
|
doCommentModUnBlockAsModerator(uri, creatorUri, '');
|
||||||
} else {
|
} else {
|
||||||
doCommentModBlockAsModerator(uri, creatorUri, '');
|
doCommentModBlockAsModerator(uri, undefined, creatorUri, undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -59,7 +59,7 @@ function ChannelBlockButton(props: Props) {
|
||||||
if (isBlocked) {
|
if (isBlocked) {
|
||||||
doCommentModUnBlockAsAdmin(uri, '');
|
doCommentModUnBlockAsAdmin(uri, '');
|
||||||
} else {
|
} else {
|
||||||
doCommentModBlockAsAdmin(uri, '');
|
doCommentModBlockAsAdmin(uri, undefined, undefined);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ const perform = (dispatch) => ({
|
||||||
doChannelUnmute: (channelUri) => dispatch(doChannelUnmute(channelUri)),
|
doChannelUnmute: (channelUri) => dispatch(doChannelUnmute(channelUri)),
|
||||||
doCommentModBlock: (channelUri) => dispatch(doCommentModBlock(channelUri)),
|
doCommentModBlock: (channelUri) => dispatch(doCommentModBlock(channelUri)),
|
||||||
doCommentModUnBlock: (channelUri) => dispatch(doCommentModUnBlock(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) =>
|
doCommentModUnBlockAsAdmin: (commenterUri, blockerId) =>
|
||||||
dispatch(doCommentModUnBlockAsAdmin(commenterUri, blockerId)),
|
dispatch(doCommentModUnBlockAsAdmin(commenterUri, blockerId)),
|
||||||
doChannelSubscribe: (subscription) => dispatch(doChannelSubscribe(subscription)),
|
doChannelSubscribe: (subscription) => dispatch(doChannelSubscribe(subscription)),
|
||||||
|
|
|
@ -45,7 +45,7 @@ type Props = {
|
||||||
doChannelUnmute: (string) => void,
|
doChannelUnmute: (string) => void,
|
||||||
doCommentModBlock: (string) => void,
|
doCommentModBlock: (string) => void,
|
||||||
doCommentModUnBlock: (string) => void,
|
doCommentModUnBlock: (string) => void,
|
||||||
doCommentModBlockAsAdmin: (string, string) => void,
|
doCommentModBlockAsAdmin: (commenterUri: string, offendingCommentId: ?string, blockerId: ?string) => void,
|
||||||
doCommentModUnBlockAsAdmin: (string, string) => void,
|
doCommentModUnBlockAsAdmin: (string, string) => void,
|
||||||
doCollectionEdit: (string, any) => void,
|
doCollectionEdit: (string, any) => void,
|
||||||
hasClaimInWatchLater: boolean,
|
hasClaimInWatchLater: boolean,
|
||||||
|
@ -237,7 +237,7 @@ function ClaimMenuList(props: Props) {
|
||||||
if (channelIsAdminBlocked) {
|
if (channelIsAdminBlocked) {
|
||||||
doCommentModUnBlockAsAdmin(contentChannelUri, '');
|
doCommentModUnBlockAsAdmin(contentChannelUri, '');
|
||||||
} else {
|
} else {
|
||||||
doCommentModBlockAsAdmin(contentChannelUri, '');
|
doCommentModBlockAsAdmin(contentChannelUri, undefined, undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,13 @@ function CommentMenuList(props: Props) {
|
||||||
<>
|
<>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
className="comment__menu-option"
|
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()}
|
{getBlockOptionElem()}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
|
@ -13,11 +13,11 @@ const select = (state, props) => ({
|
||||||
moderationDelegatorsById: selectModerationDelegatorsById(state),
|
moderationDelegatorsById: selectModerationDelegatorsById(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = (dispatch) => ({
|
const perform = {
|
||||||
closeModal: () => dispatch(doHideModal()),
|
doHideModal,
|
||||||
commentModBlock: (a, b) => dispatch(doCommentModBlock(a, b)),
|
doCommentModBlock,
|
||||||
commentModBlockAsAdmin: (a, b, c) => dispatch(doCommentModBlockAsAdmin(a, b, c)),
|
doCommentModBlockAsAdmin,
|
||||||
commentModBlockAsModerator: (a, b, c, d) => dispatch(doCommentModBlockAsModerator(a, b, c, d)),
|
doCommentModBlockAsModerator,
|
||||||
});
|
};
|
||||||
|
|
||||||
export default connect(select, perform)(ModalBlockChannel);
|
export default connect(select, perform)(ModalBlockChannel);
|
||||||
|
|
|
@ -27,18 +27,24 @@ const BLOCK = {
|
||||||
type Props = {
|
type Props = {
|
||||||
contentUri: string,
|
contentUri: string,
|
||||||
commenterUri: string,
|
commenterUri: string,
|
||||||
// --- select ---
|
offendingCommentId?: string,
|
||||||
|
// --- redux ---
|
||||||
activeChannelClaim: ?ChannelClaim,
|
activeChannelClaim: ?ChannelClaim,
|
||||||
contentClaim: ?Claim,
|
contentClaim: ?Claim,
|
||||||
moderationDelegatorsById: { [string]: { global: boolean, delegators: { name: string, claimId: string } } },
|
moderationDelegatorsById: { [string]: { global: boolean, delegators: { name: string, claimId: string } } },
|
||||||
// --- perform ---
|
doHideModal: () => void,
|
||||||
closeModal: () => void,
|
doCommentModBlock: (commenterUri: string, offendingCommentId: ?string, timeoutSec: ?number) => void,
|
||||||
commentModBlock: (commenterUri: string, timeoutSec: ?number) => void,
|
doCommentModBlockAsAdmin: (
|
||||||
commentModBlockAsAdmin: (commenterUri: string, blockerId: string, timeoutSec: ?number) => void,
|
|
||||||
commentModBlockAsModerator: (
|
|
||||||
commenterUri: string,
|
commenterUri: string,
|
||||||
|
offendingCommentId: ?string,
|
||||||
|
blockerId: ?string,
|
||||||
|
timeoutSec: ?number
|
||||||
|
) => void,
|
||||||
|
doCommentModBlockAsModerator: (
|
||||||
|
commenterUri: string,
|
||||||
|
offendingCommentId: ?string,
|
||||||
creatorUri: string,
|
creatorUri: string,
|
||||||
blockerId: string,
|
blockerId: ?string,
|
||||||
timeoutSec: ?number
|
timeoutSec: ?number
|
||||||
) => void,
|
) => void,
|
||||||
};
|
};
|
||||||
|
@ -46,13 +52,14 @@ type Props = {
|
||||||
export default function ModalBlockChannel(props: Props) {
|
export default function ModalBlockChannel(props: Props) {
|
||||||
const {
|
const {
|
||||||
commenterUri,
|
commenterUri,
|
||||||
|
offendingCommentId,
|
||||||
activeChannelClaim,
|
activeChannelClaim,
|
||||||
contentClaim,
|
contentClaim,
|
||||||
moderationDelegatorsById,
|
moderationDelegatorsById,
|
||||||
closeModal,
|
doHideModal,
|
||||||
commentModBlock,
|
doCommentModBlock,
|
||||||
commentModBlockAsAdmin,
|
doCommentModBlockAsAdmin,
|
||||||
commentModBlockAsModerator,
|
doCommentModBlockAsModerator,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const contentChannelClaim = getChannelFromClaim(contentClaim);
|
const contentChannelClaim = getChannelFromClaim(contentClaim);
|
||||||
|
@ -227,13 +234,14 @@ export default function ModalBlockChannel(props: Props) {
|
||||||
|
|
||||||
switch (tab) {
|
switch (tab) {
|
||||||
case TAB.PERSONAL:
|
case TAB.PERSONAL:
|
||||||
commentModBlock(commenterUri, duration);
|
doCommentModBlock(commenterUri, offendingCommentId, duration);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TAB.MODERATOR:
|
case TAB.MODERATOR:
|
||||||
if (activeChannelClaim && contentChannelClaim) {
|
if (activeChannelClaim && contentChannelClaim) {
|
||||||
commentModBlockAsModerator(
|
doCommentModBlockAsModerator(
|
||||||
commenterUri,
|
commenterUri,
|
||||||
|
offendingCommentId,
|
||||||
contentChannelClaim.permanent_url,
|
contentChannelClaim.permanent_url,
|
||||||
activeChannelClaim.claim_id,
|
activeChannelClaim.claim_id,
|
||||||
duration
|
duration
|
||||||
|
@ -243,12 +251,12 @@ export default function ModalBlockChannel(props: Props) {
|
||||||
|
|
||||||
case TAB.ADMIN:
|
case TAB.ADMIN:
|
||||||
if (activeChannelClaim) {
|
if (activeChannelClaim) {
|
||||||
commentModBlockAsAdmin(commenterUri, activeChannelClaim.claim_id, duration);
|
doCommentModBlockAsAdmin(commenterUri, offendingCommentId, activeChannelClaim.claim_id, duration);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
closeModal();
|
doHideModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
@ -256,13 +264,13 @@ export default function ModalBlockChannel(props: Props) {
|
||||||
|
|
||||||
if (isPersonalTheOnlyTab && !isTimeoutAvail) {
|
if (isPersonalTheOnlyTab && !isTimeoutAvail) {
|
||||||
// There's only 1 option. Just execute it and don't show the modal.
|
// There's only 1 option. Just execute it and don't show the modal.
|
||||||
commentModBlock(commenterUri);
|
doCommentModBlock(commenterUri, offendingCommentId);
|
||||||
closeModal();
|
doHideModal();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal isOpen type="card" onAborted={closeModal}>
|
<Modal isOpen type="card" onAborted={doHideModal}>
|
||||||
<Card
|
<Card
|
||||||
title={__('Block Channel')}
|
title={__('Block Channel')}
|
||||||
subtitle={getCommenterPreview(commenterUri)}
|
subtitle={getCommenterPreview(commenterUri)}
|
||||||
|
@ -301,7 +309,7 @@ export default function ModalBlockChannel(props: Props) {
|
||||||
<div className="block-modal--finalize">
|
<div className="block-modal--finalize">
|
||||||
<div className="section__actions">
|
<div className="section__actions">
|
||||||
<Button button="primary" label={__('Block')} onClick={handleBlock} disabled={blockButtonDisabled} />
|
<Button button="primary" label={__('Block')} onClick={handleBlock} disabled={blockButtonDisabled} />
|
||||||
<Button button="link" label={__('Cancel')} onClick={closeModal} />
|
<Button button="link" label={__('Cancel')} onClick={doHideModal} />
|
||||||
{getActiveChannelElem()}
|
{getActiveChannelElem()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -872,8 +872,9 @@ function doCommentModToggleBlock(
|
||||||
creatorUri: string,
|
creatorUri: string,
|
||||||
blockerIds: Array<string>, // [] = use all my channels
|
blockerIds: Array<string>, // [] = use all my channels
|
||||||
blockLevel: string,
|
blockLevel: string,
|
||||||
timeoutSec?: number,
|
timeoutSec: ?number,
|
||||||
showLink: boolean = false
|
showLink: boolean = false,
|
||||||
|
offendingCommentId: ?string = undefined
|
||||||
) {
|
) {
|
||||||
return async (dispatch: Dispatch, getState: GetState) => {
|
return async (dispatch: Dispatch, getState: GetState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
@ -972,6 +973,7 @@ function doCommentModToggleBlock(
|
||||||
signing_ts: signatureData.signing_ts,
|
signing_ts: signatureData.signing_ts,
|
||||||
creator_channel_id: creatorUri ? creatorId : undefined,
|
creator_channel_id: creatorUri ? creatorId : undefined,
|
||||||
creator_channel_name: creatorUri ? creatorName : undefined,
|
creator_channel_name: creatorUri ? creatorName : undefined,
|
||||||
|
offending_comment_id: offendingCommentId && !unblock ? offendingCommentId : undefined,
|
||||||
block_all: unblock ? undefined : blockLevel === BLOCK_LEVEL.ADMIN,
|
block_all: unblock ? undefined : blockLevel === BLOCK_LEVEL.ADMIN,
|
||||||
global_un_block: unblock ? blockLevel === BLOCK_LEVEL.ADMIN : undefined,
|
global_un_block: unblock ? blockLevel === BLOCK_LEVEL.ADMIN : undefined,
|
||||||
...sharedModBlockParams,
|
...sharedModBlockParams,
|
||||||
|
@ -1051,14 +1053,26 @@ function doCommentModToggleBlock(
|
||||||
/**
|
/**
|
||||||
* Blocks the commenter for all channels that I own.
|
* 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 commenterUri
|
||||||
|
* @param offendingCommentId
|
||||||
* @param timeoutSec
|
* @param timeoutSec
|
||||||
* @param showLink
|
* @param showLink
|
||||||
* @returns {function(Dispatch): *}
|
* @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: 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.
|
* Blocks the commenter using the given channel that has Global privileges.
|
||||||
*
|
*
|
||||||
* @param commenterUri
|
* @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
|
* @param timeoutSec
|
||||||
* @returns {function(Dispatch): *}
|
* @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: Dispatch) => {
|
||||||
return 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.
|
* moderation rights by the creator.
|
||||||
*
|
*
|
||||||
* @param commenterUri
|
* @param commenterUri
|
||||||
|
* @param offendingCommentId
|
||||||
* @param creatorUri
|
* @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
|
* @param timeoutSec
|
||||||
* @returns {function(Dispatch): *}
|
* @returns {function(Dispatch): *}
|
||||||
*/
|
*/
|
||||||
export function doCommentModBlockAsModerator(
|
export function doCommentModBlockAsModerator(
|
||||||
commenterUri: string,
|
commenterUri: string,
|
||||||
|
offendingCommentId: ?string,
|
||||||
creatorUri: string,
|
creatorUri: string,
|
||||||
blockerId: string,
|
blockerId: ?string,
|
||||||
timeoutSec?: number
|
timeoutSec: ?number
|
||||||
) {
|
) {
|
||||||
return (dispatch: Dispatch) => {
|
return (dispatch: Dispatch) => {
|
||||||
return dispatch(
|
return dispatch(
|
||||||
|
@ -1102,7 +1133,9 @@ export function doCommentModBlockAsModerator(
|
||||||
creatorUri,
|
creatorUri,
|
||||||
blockerId ? [blockerId] : [],
|
blockerId ? [blockerId] : [],
|
||||||
BLOCK_LEVEL.MODERATOR,
|
BLOCK_LEVEL.MODERATOR,
|
||||||
timeoutSec
|
timeoutSec,
|
||||||
|
false,
|
||||||
|
offendingCommentId
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue