// @flow import * as ICONS from 'constants/icons'; 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 = { claim: ?Claim, clearPlayingUri: () => void, authorUri: string, // full LBRY Channel URI: lbry://@channel#123... commentId: string, // sha256 digest identifying the comment commentIsMine: boolean, // if this comment was signed by an owned channel deleteComment: (string, ?string) => void, isPinned: boolean, pinComment: (string, string, boolean) => Promise, muteChannel: (string) => void, handleEditComment: () => void, contentChannelPermanentUrl: any, activeChannelClaim: ?ChannelClaim, isTopLevel: boolean, commentModBlock: (string) => void, commentModBlockAsAdmin: (string, string) => void, commentModBlockAsModerator: (string, string, string) => void, commentModAddDelegate: (string, string, ChannelClaim) => void, playingUri: ?PlayingUri, disableEdit?: boolean, disableRemove?: boolean, moderationDelegatorsById: { [string]: { global: boolean, delegators: { name: string, claimId: string } } }, }; function CommentMenuList(props: Props) { const { claim, authorUri, commentIsMine, commentId, deleteComment, muteChannel, pinComment, clearPlayingUri, activeChannelClaim, contentChannelPermanentUrl, isTopLevel, isPinned, handleEditComment, commentModBlock, commentModBlockAsAdmin, commentModBlockAsModerator, commentModAddDelegate, playingUri, disableEdit, disableRemove, moderationDelegatorsById, } = props; const contentChannelClaim = !claim ? null : claim.value_type === 'channel' ? claim : claim.signing_channel && claim.is_channel_signature_valid ? claim.signing_channel : null; const activeModeratorInfo = activeChannelClaim && moderationDelegatorsById[activeChannelClaim.claim_id]; const activeChannelIsCreator = activeChannelClaim && activeChannelClaim.permanent_url === contentChannelPermanentUrl; const activeChannelIsAdmin = activeChannelClaim && activeModeratorInfo && activeModeratorInfo.global; const activeChannelIsModerator = activeChannelClaim && contentChannelClaim && activeModeratorInfo && Object.values(activeModeratorInfo.delegators).includes(contentChannelClaim.claim_id); function handlePinComment(commentId, claimId, remove) { pinComment(commentId, claimId, remove); } function handleDeleteComment() { if (playingUri && playingUri.source === 'comment') { clearPlayingUri(); } deleteComment(commentId, commentIsMine ? undefined : contentChannelPermanentUrl); } function handleCommentBlock() { commentModBlock(authorUri); } function handleCommentMute() { 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); } } function blockCommentAsAdmin() { if (activeChannelClaim) { commentModBlockAsAdmin(authorUri, activeChannelClaim.claim_id); } } return ( {activeChannelIsCreator &&
{__('Creator tools')}
} {activeChannelIsCreator && isTopLevel && ( handlePinComment(commentId, claim ? claim.claim_id : '', isPinned)} > {isPinned ? __('Unpin') : __('Pin')} )} {activeChannelIsCreator && (
{__('Add as moderator')}
{__('Assign this user to moderate %channel%', { channel: activeChannelClaim ? activeChannelClaim.name : __('your channel'), })}
)} {!disableRemove && activeChannelClaim && (activeChannelClaim.permanent_url === authorUri || activeChannelClaim.permanent_url === contentChannelPermanentUrl) && (
{__('Remove')}
)} {commentIsMine && activeChannelClaim && activeChannelClaim.permanent_url === authorUri && !disableEdit && ( {__('Edit')} )} {!commentIsMine && (
{__('Block')}
{activeChannelIsCreator && ( {__('Prevent this channel from interacting with you.')} )}
)} {!commentIsMine && (
{__('Mute')}
{activeChannelIsCreator && ( {__('Hide this channel for you only.')} )}
)} {(activeChannelIsAdmin || activeChannelIsModerator) && (
{__('Moderator tools')}
)} {!commentIsMine && activeChannelIsAdmin && (
{__('Global Block')}
{__('Block this channel as global admin')}
)} {!commentIsMine && activeChannelIsModerator && (
{__('Moderator Block')}
{__('Block this channel on behalf of %creator%', { creator: contentChannelClaim ? contentChannelClaim.name : __('creator'), })}
)} {activeChannelClaim && (
{__('Interacting as %channelName%', { channelName: activeChannelClaim.name })}
)}
); } export default CommentMenuList;