Allow creators to assign moderators from a comment context-menu.

This commit is contained in:
infinite-persistence 2021-06-19 17:52:17 +08:00
parent 9f9d0a651b
commit 3db845b9bf
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
3 changed files with 53 additions and 9 deletions

View file

@ -7,6 +7,7 @@ import {
doCommentModBlock,
doCommentModBlockAsAdmin,
doCommentModBlockAsModerator,
doCommentModAddDelegate,
} from 'redux/actions/comments';
import { doChannelMute } from 'redux/actions/blocked';
// import { doSetActiveChannel } from 'redux/actions/app';
@ -36,6 +37,8 @@ const perform = (dispatch) => ({
commentModBlockAsAdmin: (commenterUri, blockerId) => dispatch(doCommentModBlockAsAdmin(commenterUri, blockerId)),
commentModBlockAsModerator: (commenterUri, creatorId, blockerId) =>
dispatch(doCommentModBlockAsModerator(commenterUri, creatorId, blockerId)),
commentModAddDelegate: (modChanId, modChanName, creatorChannelClaim) =>
dispatch(doCommentModAddDelegate(modChanId, modChanName, creatorChannelClaim, true)),
});
export default connect(select, perform)(CommentMenuList);

View file

@ -4,6 +4,7 @@ import React from 'react';
import { MenuList, MenuItem } from '@reach/menu-button';
import ChannelThumbnail from 'component/channelThumbnail';
import Icon from 'component/common/icon';
import { parseURI } from 'lbry-redux';
type Props = {
uri: string,
@ -25,6 +26,7 @@ type Props = {
commentModBlock: (string) => void,
commentModBlockAsAdmin: (string, string) => void,
commentModBlockAsModerator: (string, string, string) => void,
commentModAddDelegate: (string, string, ChannelClaim) => void,
playingUri: ?PlayingUri,
disableEdit?: boolean,
disableRemove?: boolean,
@ -51,6 +53,7 @@ function CommentMenuList(props: Props) {
commentModBlock,
commentModBlockAsAdmin,
commentModBlockAsModerator,
commentModAddDelegate,
playingUri,
disableEdit,
disableRemove,
@ -93,6 +96,13 @@ function CommentMenuList(props: Props) {
muteChannel(authorUri);
}
function assignAsModerator() {
if (activeChannelClaim && authorUri) {
const { channelName, channelClaimId } = parseURI(authorUri);
commentModAddDelegate(channelClaimId, channelName, activeChannelClaim);
}
}
function blockCommentAsModerator() {
if (activeChannelClaim && contentChannelClaim) {
commentModBlockAsModerator(authorUri, contentChannelClaim.claim_id, activeChannelClaim.claim_id);
@ -121,6 +131,20 @@ function CommentMenuList(props: Props) {
</MenuItem>
)}
{activeChannelIsCreator && (
<MenuItem className="comment__menu-option" onSelect={assignAsModerator}>
<div className="menu__link">
<Icon aria-hidden icon={ICONS.ADD} />
{__('Add as moderator')}
</div>
<span className="comment__menu-help">
{__('Assign this user to moderate %channel%', {
channel: activeChannelClaim ? activeChannelClaim.name : __('your channel'),
})}
</span>
</MenuItem>
)}
{!disableRemove &&
activeChannelClaim &&
(activeChannelClaim.permanent_url === authorUri ||

View file

@ -1,6 +1,7 @@
// @flow
import * as ACTIONS from 'constants/action_types';
import * as REACTION_TYPES from 'constants/reactions';
import * as PAGES from 'constants/pages';
import { BLOCK_LEVEL } from 'constants/comment';
import { Lbry, parseURI, buildURI, selectClaimsById, selectClaimsByUri, selectMyChannelClaims } from 'lbry-redux';
import { doToast, doSeeNotifications } from 'redux/actions/notifications';
@ -941,7 +942,8 @@ export const doUpdateBlockListForPublishedChannel = (channelClaim: ChannelClaim)
export function doCommentModAddDelegate(
modChannelId: string,
modChannelName: string,
creatorChannelClaim: ChannelClaim
creatorChannelClaim: ChannelClaim,
showToast: boolean = false
) {
return async (dispatch: Dispatch, getState: GetState) => {
let signature: ?{
@ -966,7 +968,22 @@ export function doCommentModAddDelegate(
creator_channel_name: creatorChannelClaim.name,
signature: signature.signature,
signing_ts: signature.signing_ts,
}).catch((err) => {
})
.then(() => {
if (showToast) {
dispatch(
doToast({
message: __('Added %user% as moderator for %myChannel%', {
user: modChannelName,
myChannel: creatorChannelClaim.name,
}),
linkText: __('Manage'),
linkTarget: `/${PAGES.SETTINGS_CREATOR}`,
})
);
}
})
.catch((err) => {
dispatch(
doToast({
message: err.message,