Fix: Can't unblock if delegator deleted their channel
## Issue 7003 Can't unblock if delegator deleted their channel ## Changes - Changed the function parameter from 'creatorId' to 'creatorUri' - It got short-circuited because we don't resolve deleted channels. But the client already have the full creator URI (containing the needed 'name' and 'id'), so there is no need to actually look at the resolved list -- just pass the uri like all the other functions.
This commit is contained in:
parent
40a82838b6
commit
af4ff29b23
4 changed files with 55 additions and 53 deletions
|
@ -2,7 +2,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
import { BLOCK_LEVEL } from 'constants/comment';
|
import { BLOCK_LEVEL } from 'constants/comment';
|
||||||
import { parseURI } from 'lbry-redux';
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
uri: string,
|
uri: string,
|
||||||
|
@ -48,11 +47,10 @@ function ChannelBlockButton(props: Props) {
|
||||||
|
|
||||||
case BLOCK_LEVEL.MODERATOR:
|
case BLOCK_LEVEL.MODERATOR:
|
||||||
if (creatorUri) {
|
if (creatorUri) {
|
||||||
const { channelClaimId } = parseURI(creatorUri);
|
|
||||||
if (isBlocked) {
|
if (isBlocked) {
|
||||||
doCommentModUnBlockAsModerator(uri, channelClaimId, '');
|
doCommentModUnBlockAsModerator(uri, creatorUri, '');
|
||||||
} else {
|
} else {
|
||||||
doCommentModBlockAsModerator(uri, channelClaimId, '');
|
doCommentModBlockAsModerator(uri, creatorUri, '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -15,11 +15,9 @@ const select = (state, props) => ({
|
||||||
|
|
||||||
const perform = (dispatch) => ({
|
const perform = (dispatch) => ({
|
||||||
closeModal: () => dispatch(doHideModal()),
|
closeModal: () => dispatch(doHideModal()),
|
||||||
commentModBlock: (commenterUri, timeoutHours) => dispatch(doCommentModBlock(commenterUri, timeoutHours)),
|
commentModBlock: (a, b) => dispatch(doCommentModBlock(a, b)),
|
||||||
commentModBlockAsAdmin: (commenterUri, blockerId, timeoutHours) =>
|
commentModBlockAsAdmin: (a, b, c) => dispatch(doCommentModBlockAsAdmin(a, b, c)),
|
||||||
dispatch(doCommentModBlockAsAdmin(commenterUri, blockerId, timeoutHours)),
|
commentModBlockAsModerator: (a, b, c, d) => dispatch(doCommentModBlockAsModerator(a, b, c, d)),
|
||||||
commentModBlockAsModerator: (commenterUri, creatorId, blockerId, timeoutHours) =>
|
|
||||||
dispatch(doCommentModBlockAsModerator(commenterUri, creatorId, blockerId, timeoutHours)),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(select, perform)(ModalBlockChannel);
|
export default connect(select, perform)(ModalBlockChannel);
|
||||||
|
|
|
@ -33,9 +33,14 @@ type Props = {
|
||||||
moderationDelegatorsById: { [string]: { global: boolean, delegators: { name: string, claimId: string } } },
|
moderationDelegatorsById: { [string]: { global: boolean, delegators: { name: string, claimId: string } } },
|
||||||
// --- perform ---
|
// --- perform ---
|
||||||
closeModal: () => void,
|
closeModal: () => void,
|
||||||
commentModBlock: (string, ?number) => void,
|
commentModBlock: (commenterUri: string, timeoutSec: ?number) => void,
|
||||||
commentModBlockAsAdmin: (string, string, ?number) => void,
|
commentModBlockAsAdmin: (commenterUri: string, blockerId: string, timeoutSec: ?number) => void,
|
||||||
commentModBlockAsModerator: (string, string, string, ?number) => void,
|
commentModBlockAsModerator: (
|
||||||
|
commenterUri: string,
|
||||||
|
creatorUri: string,
|
||||||
|
blockerId: string,
|
||||||
|
timeoutSec: ?number
|
||||||
|
) => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ModalBlockChannel(props: Props) {
|
export default function ModalBlockChannel(props: Props) {
|
||||||
|
@ -227,7 +232,12 @@ export default function ModalBlockChannel(props: Props) {
|
||||||
|
|
||||||
case TAB.MODERATOR:
|
case TAB.MODERATOR:
|
||||||
if (activeChannelClaim && contentChannelClaim) {
|
if (activeChannelClaim && contentChannelClaim) {
|
||||||
commentModBlockAsModerator(commenterUri, contentChannelClaim.claim_id, activeChannelClaim.claim_id, duration);
|
commentModBlockAsModerator(
|
||||||
|
commenterUri,
|
||||||
|
contentChannelClaim.permanent_url,
|
||||||
|
activeChannelClaim.claim_id,
|
||||||
|
duration
|
||||||
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,7 @@ import * as ACTIONS from 'constants/action_types';
|
||||||
import * as REACTION_TYPES from 'constants/reactions';
|
import * as REACTION_TYPES from 'constants/reactions';
|
||||||
import * as PAGES from 'constants/pages';
|
import * as PAGES from 'constants/pages';
|
||||||
import { SORT_BY, BLOCK_LEVEL } from 'constants/comment';
|
import { SORT_BY, BLOCK_LEVEL } from 'constants/comment';
|
||||||
import {
|
import { Lbry, parseURI, buildURI, selectClaimsByUri, selectMyChannelClaims, isURIEqual } from 'lbry-redux';
|
||||||
Lbry,
|
|
||||||
parseURI,
|
|
||||||
buildURI,
|
|
||||||
selectClaimsById,
|
|
||||||
selectClaimsByUri,
|
|
||||||
selectMyChannelClaims,
|
|
||||||
isURIEqual,
|
|
||||||
} from 'lbry-redux';
|
|
||||||
import { doToast, doSeeNotifications } from 'redux/actions/notifications';
|
import { doToast, doSeeNotifications } from 'redux/actions/notifications';
|
||||||
import {
|
import {
|
||||||
makeSelectMyReactionsForComment,
|
makeSelectMyReactionsForComment,
|
||||||
|
@ -731,11 +723,19 @@ async function channelSignData(channelClaimId: string, data: string) {
|
||||||
return signedObject;
|
return signedObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function safeParseURI(uri) {
|
||||||
|
try {
|
||||||
|
return parseURI(uri);
|
||||||
|
} catch {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Hides a users comments from all creator's claims and prevent them from commenting in the future
|
// Hides a users comments from all creator's claims and prevent them from commenting in the future
|
||||||
function doCommentModToggleBlock(
|
function doCommentModToggleBlock(
|
||||||
unblock: boolean,
|
unblock: boolean,
|
||||||
commenterUri: string,
|
commenterUri: string,
|
||||||
creatorId: 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,
|
||||||
|
@ -759,6 +759,9 @@ function doCommentModToggleBlock(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { channelName, channelClaimId } = parseURI(commenterUri);
|
||||||
|
const { channelName: creatorName, channelClaimId: creatorId } = safeParseURI(creatorUri);
|
||||||
|
|
||||||
if (blockerIds.length === 0) {
|
if (blockerIds.length === 0) {
|
||||||
// Specific blockers not provided, so find one based on block-level.
|
// Specific blockers not provided, so find one based on block-level.
|
||||||
switch (blockLevel) {
|
switch (blockLevel) {
|
||||||
|
@ -786,22 +789,15 @@ function doCommentModToggleBlock(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Client wants to block for specific channels only. Ensure we own those channels.
|
||||||
blockerChannelClaims = blockerChannelClaims.filter((x) => blockerIds.includes(x.claim_id));
|
blockerChannelClaims = blockerChannelClaims.filter((x) => blockerIds.includes(x.claim_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
const { channelName, channelClaimId } = parseURI(commenterUri);
|
|
||||||
|
|
||||||
const creatorClaim = selectClaimsById(state)[creatorId];
|
|
||||||
if (creatorId && !creatorClaim) {
|
|
||||||
console.error("Can't find creator claim"); // eslint-disable-line
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_STARTED : ACTIONS.COMMENT_MODERATION_BLOCK_STARTED,
|
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_STARTED : ACTIONS.COMMENT_MODERATION_BLOCK_STARTED,
|
||||||
data: {
|
data: {
|
||||||
blockedUri: commenterUri,
|
blockedUri: commenterUri,
|
||||||
creatorUri: creatorClaim ? creatorClaim.permanent_url : undefined,
|
creatorUri: creatorUri || undefined,
|
||||||
blockLevel: blockLevel,
|
blockLevel: blockLevel,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -840,8 +836,8 @@ function doCommentModToggleBlock(
|
||||||
signature: signatureData.signature,
|
signature: signatureData.signature,
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
signing_ts: signatureData.signing_ts,
|
signing_ts: signatureData.signing_ts,
|
||||||
creator_channel_id: creatorClaim ? creatorClaim.claim_id : undefined,
|
creator_channel_id: creatorUri ? creatorId : undefined,
|
||||||
creator_channel_name: creatorClaim ? creatorClaim.name : undefined,
|
creator_channel_name: creatorUri ? creatorName : 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,
|
||||||
|
@ -868,7 +864,7 @@ function doCommentModToggleBlock(
|
||||||
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_FAILED : ACTIONS.COMMENT_MODERATION_BLOCK_FAILED,
|
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_FAILED : ACTIONS.COMMENT_MODERATION_BLOCK_FAILED,
|
||||||
data: {
|
data: {
|
||||||
blockedUri: commenterUri,
|
blockedUri: commenterUri,
|
||||||
creatorUri: creatorClaim ? creatorClaim.permanent_url : undefined,
|
creatorUri: creatorUri || undefined,
|
||||||
blockLevel: blockLevel,
|
blockLevel: blockLevel,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -879,7 +875,7 @@ function doCommentModToggleBlock(
|
||||||
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_COMPLETE : ACTIONS.COMMENT_MODERATION_BLOCK_COMPLETE,
|
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_COMPLETE : ACTIONS.COMMENT_MODERATION_BLOCK_COMPLETE,
|
||||||
data: {
|
data: {
|
||||||
blockedUri: commenterUri,
|
blockedUri: commenterUri,
|
||||||
creatorUri: creatorClaim ? creatorClaim.permanent_url : undefined,
|
creatorUri: creatorUri || undefined,
|
||||||
blockLevel: blockLevel,
|
blockLevel: blockLevel,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -899,7 +895,7 @@ function doCommentModToggleBlock(
|
||||||
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_FAILED : ACTIONS.COMMENT_MODERATION_BLOCK_FAILED,
|
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_FAILED : ACTIONS.COMMENT_MODERATION_BLOCK_FAILED,
|
||||||
data: {
|
data: {
|
||||||
blockedUri: commenterUri,
|
blockedUri: commenterUri,
|
||||||
creatorUri: creatorClaim ? creatorClaim.permanent_url : undefined,
|
creatorUri: creatorUri || undefined,
|
||||||
blockLevel: blockLevel,
|
blockLevel: blockLevel,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -910,7 +906,7 @@ function doCommentModToggleBlock(
|
||||||
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_FAILED : ACTIONS.COMMENT_MODERATION_BLOCK_FAILED,
|
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_FAILED : ACTIONS.COMMENT_MODERATION_BLOCK_FAILED,
|
||||||
data: {
|
data: {
|
||||||
blockedUri: commenterUri,
|
blockedUri: commenterUri,
|
||||||
creatorUri: creatorClaim ? creatorClaim.permanent_url : undefined,
|
creatorUri: creatorUri || undefined,
|
||||||
blockLevel: blockLevel,
|
blockLevel: blockLevel,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -922,13 +918,13 @@ function doCommentModToggleBlock(
|
||||||
* Blocks the commenter for all channels that I own.
|
* Blocks the commenter for all channels that I own.
|
||||||
*
|
*
|
||||||
* @param commenterUri
|
* @param commenterUri
|
||||||
* @param timeoutHours
|
* @param timeoutSec
|
||||||
* @param showLink
|
* @param showLink
|
||||||
* @returns {function(Dispatch): *}
|
* @returns {function(Dispatch): *}
|
||||||
*/
|
*/
|
||||||
export function doCommentModBlock(commenterUri: string, timeoutHours?: number, showLink: boolean = true) {
|
export function doCommentModBlock(commenterUri: string, timeoutSec?: number, showLink: boolean = true) {
|
||||||
return (dispatch: Dispatch) => {
|
return (dispatch: Dispatch) => {
|
||||||
return dispatch(doCommentModToggleBlock(false, commenterUri, '', [], BLOCK_LEVEL.SELF, timeoutHours, showLink));
|
return dispatch(doCommentModToggleBlock(false, commenterUri, '', [], BLOCK_LEVEL.SELF, timeoutSec, showLink));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -937,13 +933,13 @@ export function doCommentModBlock(commenterUri: string, timeoutHours?: number, s
|
||||||
*
|
*
|
||||||
* @param commenterUri
|
* @param commenterUri
|
||||||
* @param blockerId
|
* @param blockerId
|
||||||
* @param timeoutHours
|
* @param timeoutSec
|
||||||
* @returns {function(Dispatch): *}
|
* @returns {function(Dispatch): *}
|
||||||
*/
|
*/
|
||||||
export function doCommentModBlockAsAdmin(commenterUri: string, blockerId: string, timeoutHours?: number) {
|
export function doCommentModBlockAsAdmin(commenterUri: string, blockerId: string, timeoutSec?: number) {
|
||||||
return (dispatch: Dispatch) => {
|
return (dispatch: Dispatch) => {
|
||||||
return dispatch(
|
return dispatch(
|
||||||
doCommentModToggleBlock(false, commenterUri, '', blockerId ? [blockerId] : [], BLOCK_LEVEL.ADMIN, timeoutHours)
|
doCommentModToggleBlock(false, commenterUri, '', blockerId ? [blockerId] : [], BLOCK_LEVEL.ADMIN, timeoutSec)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -953,26 +949,26 @@ export function doCommentModBlockAsAdmin(commenterUri: string, blockerId: string
|
||||||
* moderation rights by the creator.
|
* moderation rights by the creator.
|
||||||
*
|
*
|
||||||
* @param commenterUri
|
* @param commenterUri
|
||||||
* @param creatorId
|
* @param creatorUri
|
||||||
* @param blockerId
|
* @param blockerId
|
||||||
* @param timeoutHours
|
* @param timeoutSec
|
||||||
* @returns {function(Dispatch): *}
|
* @returns {function(Dispatch): *}
|
||||||
*/
|
*/
|
||||||
export function doCommentModBlockAsModerator(
|
export function doCommentModBlockAsModerator(
|
||||||
commenterUri: string,
|
commenterUri: string,
|
||||||
creatorId: string,
|
creatorUri: string,
|
||||||
blockerId: string,
|
blockerId: string,
|
||||||
timeoutHours?: number
|
timeoutSec?: number
|
||||||
) {
|
) {
|
||||||
return (dispatch: Dispatch) => {
|
return (dispatch: Dispatch) => {
|
||||||
return dispatch(
|
return dispatch(
|
||||||
doCommentModToggleBlock(
|
doCommentModToggleBlock(
|
||||||
false,
|
false,
|
||||||
commenterUri,
|
commenterUri,
|
||||||
creatorId,
|
creatorUri,
|
||||||
blockerId ? [blockerId] : [],
|
blockerId ? [blockerId] : [],
|
||||||
BLOCK_LEVEL.MODERATOR,
|
BLOCK_LEVEL.MODERATOR,
|
||||||
timeoutHours
|
timeoutSec
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1009,14 +1005,14 @@ export function doCommentModUnBlockAsAdmin(commenterUri: string, blockerId: stri
|
||||||
* moderation rights by the creator.
|
* moderation rights by the creator.
|
||||||
*
|
*
|
||||||
* @param commenterUri
|
* @param commenterUri
|
||||||
* @param creatorId
|
* @param creatorUri
|
||||||
* @param blockerId
|
* @param blockerId
|
||||||
* @returns {function(Dispatch): *}
|
* @returns {function(Dispatch): *}
|
||||||
*/
|
*/
|
||||||
export function doCommentModUnBlockAsModerator(commenterUri: string, creatorId: string, blockerId: string) {
|
export function doCommentModUnBlockAsModerator(commenterUri: string, creatorUri: string, blockerId: string) {
|
||||||
return (dispatch: Dispatch) => {
|
return (dispatch: Dispatch) => {
|
||||||
return dispatch(
|
return dispatch(
|
||||||
doCommentModToggleBlock(true, commenterUri, creatorId, blockerId ? [blockerId] : [], BLOCK_LEVEL.MODERATOR)
|
doCommentModToggleBlock(true, commenterUri, creatorUri, blockerId ? [blockerId] : [], BLOCK_LEVEL.MODERATOR)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue