2021-02-11 06:12:41 +01:00
|
|
|
// @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';
|
2021-06-19 11:52:17 +02:00
|
|
|
import { parseURI } from 'lbry-redux';
|
2021-02-11 06:12:41 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
2021-06-16 04:27:58 +02:00
|
|
|
claim: ?Claim,
|
2021-03-02 11:12:54 +01:00
|
|
|
clearPlayingUri: () => void,
|
2021-02-11 06:12:41 +01:00
|
|
|
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,
|
|
|
|
linkedComment?: any,
|
|
|
|
isPinned: boolean,
|
|
|
|
pinComment: (string, boolean) => Promise<any>,
|
2021-06-11 22:49:18 +02:00
|
|
|
muteChannel: (string) => void,
|
2021-02-23 03:45:55 +01:00
|
|
|
fetchComments: (string) => void,
|
2021-02-11 06:12:41 +01:00
|
|
|
handleEditComment: () => void,
|
|
|
|
contentChannelPermanentUrl: any,
|
|
|
|
activeChannelClaim: ?ChannelClaim,
|
|
|
|
isTopLevel: boolean,
|
2021-03-03 19:50:16 +01:00
|
|
|
commentModBlock: (string) => void,
|
2021-06-16 04:27:58 +02:00
|
|
|
commentModBlockAsAdmin: (string, string) => void,
|
|
|
|
commentModBlockAsModerator: (string, string, string) => void,
|
2021-06-19 11:52:17 +02:00
|
|
|
commentModAddDelegate: (string, string, ChannelClaim) => void,
|
2021-03-08 19:19:25 +01:00
|
|
|
playingUri: ?PlayingUri,
|
2021-05-04 17:08:36 +02:00
|
|
|
disableEdit?: boolean,
|
|
|
|
disableRemove?: boolean,
|
2021-06-16 04:27:58 +02:00
|
|
|
moderationDelegatorsById: { [string]: { global: boolean, delegators: { name: string, claimId: string } } },
|
2021-02-11 06:12:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function CommentMenuList(props: Props) {
|
|
|
|
const {
|
|
|
|
uri,
|
2021-06-16 04:27:58 +02:00
|
|
|
claim,
|
2021-02-11 06:12:41 +01:00
|
|
|
authorUri,
|
|
|
|
commentIsMine,
|
|
|
|
commentId,
|
|
|
|
deleteComment,
|
2021-06-11 22:49:18 +02:00
|
|
|
muteChannel,
|
2021-02-11 06:12:41 +01:00
|
|
|
pinComment,
|
2021-03-02 11:12:54 +01:00
|
|
|
clearPlayingUri,
|
2021-02-11 06:12:41 +01:00
|
|
|
activeChannelClaim,
|
|
|
|
contentChannelPermanentUrl,
|
|
|
|
isTopLevel,
|
|
|
|
isPinned,
|
|
|
|
handleEditComment,
|
|
|
|
fetchComments,
|
2021-03-03 19:50:16 +01:00
|
|
|
commentModBlock,
|
2021-06-16 04:27:58 +02:00
|
|
|
commentModBlockAsAdmin,
|
|
|
|
commentModBlockAsModerator,
|
2021-06-19 11:52:17 +02:00
|
|
|
commentModAddDelegate,
|
2021-03-02 11:12:54 +01:00
|
|
|
playingUri,
|
2021-05-04 17:08:36 +02:00
|
|
|
disableEdit,
|
|
|
|
disableRemove,
|
2021-06-16 04:27:58 +02:00
|
|
|
moderationDelegatorsById,
|
2021-02-11 06:12:41 +01:00
|
|
|
} = props;
|
2021-06-16 04:27:58 +02:00
|
|
|
|
|
|
|
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];
|
2021-02-11 06:12:41 +01:00
|
|
|
const activeChannelIsCreator = activeChannelClaim && activeChannelClaim.permanent_url === contentChannelPermanentUrl;
|
2021-06-16 04:27:58 +02:00
|
|
|
const activeChannelIsAdmin = activeChannelClaim && activeModeratorInfo && activeModeratorInfo.global;
|
|
|
|
const activeChannelIsModerator =
|
|
|
|
activeChannelClaim &&
|
|
|
|
contentChannelClaim &&
|
|
|
|
activeModeratorInfo &&
|
|
|
|
Object.values(activeModeratorInfo.delegators).includes(contentChannelClaim.claim_id);
|
2021-02-11 06:12:41 +01:00
|
|
|
|
|
|
|
function handlePinComment(commentId, remove) {
|
|
|
|
pinComment(commentId, remove).then(() => fetchComments(uri));
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleDeleteComment() {
|
2021-03-02 11:12:54 +01:00
|
|
|
if (playingUri && playingUri.source === 'comment') {
|
|
|
|
clearPlayingUri();
|
|
|
|
}
|
2021-02-11 06:12:41 +01:00
|
|
|
deleteComment(commentId, commentIsMine ? undefined : contentChannelPermanentUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleCommentBlock() {
|
2021-04-19 21:02:23 +02:00
|
|
|
commentModBlock(authorUri);
|
2021-03-03 19:50:16 +01:00
|
|
|
}
|
2021-02-11 06:12:41 +01:00
|
|
|
|
2021-03-03 19:50:16 +01:00
|
|
|
function handleCommentMute() {
|
2021-06-11 22:49:18 +02:00
|
|
|
muteChannel(authorUri);
|
2021-02-11 06:12:41 +01:00
|
|
|
}
|
|
|
|
|
2021-06-19 11:52:17 +02:00
|
|
|
function assignAsModerator() {
|
|
|
|
if (activeChannelClaim && authorUri) {
|
|
|
|
const { channelName, channelClaimId } = parseURI(authorUri);
|
|
|
|
commentModAddDelegate(channelClaimId, channelName, activeChannelClaim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-16 04:27:58 +02:00
|
|
|
function blockCommentAsModerator() {
|
|
|
|
if (activeChannelClaim && contentChannelClaim) {
|
|
|
|
commentModBlockAsModerator(authorUri, contentChannelClaim.claim_id, activeChannelClaim.claim_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function blockCommentAsAdmin() {
|
|
|
|
if (activeChannelClaim) {
|
|
|
|
commentModBlockAsAdmin(authorUri, activeChannelClaim.claim_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-11 06:12:41 +01:00
|
|
|
return (
|
2021-03-03 19:50:16 +01:00
|
|
|
<MenuList className="menu__list">
|
2021-02-11 06:12:41 +01:00
|
|
|
{activeChannelIsCreator && <div className="comment__menu-title">{__('Creator tools')}</div>}
|
|
|
|
|
|
|
|
{activeChannelIsCreator && isTopLevel && (
|
|
|
|
<MenuItem
|
|
|
|
className="comment__menu-option menu__link"
|
|
|
|
onSelect={isPinned ? () => handlePinComment(commentId, true) : () => handlePinComment(commentId, false)}
|
|
|
|
>
|
|
|
|
<span className={'button__content'}>
|
|
|
|
<Icon aria-hidden icon={ICONS.PIN} className={'icon'} />
|
|
|
|
{isPinned ? __('Unpin') : __('Pin')}
|
|
|
|
</span>
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
2021-06-19 11:52:17 +02:00
|
|
|
{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>
|
|
|
|
)}
|
|
|
|
|
2021-05-04 17:08:36 +02:00
|
|
|
{!disableRemove &&
|
|
|
|
activeChannelClaim &&
|
2021-02-11 06:12:41 +01:00
|
|
|
(activeChannelClaim.permanent_url === authorUri ||
|
|
|
|
activeChannelClaim.permanent_url === contentChannelPermanentUrl) && (
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={handleDeleteComment}>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.DELETE} />
|
|
|
|
{__('Remove')}
|
|
|
|
</div>
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
2021-05-04 17:08:36 +02:00
|
|
|
{commentIsMine && activeChannelClaim && activeChannelClaim.permanent_url === authorUri && !disableEdit && (
|
2021-02-11 06:12:41 +01:00
|
|
|
<MenuItem className="comment__menu-option menu__link" onSelect={handleEditComment}>
|
|
|
|
<Icon aria-hidden icon={ICONS.EDIT} />
|
|
|
|
{__('Edit')}
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{!commentIsMine && (
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={handleCommentBlock}>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.BLOCK} />
|
|
|
|
{__('Block')}
|
|
|
|
</div>
|
2021-03-03 19:50:16 +01:00
|
|
|
{activeChannelIsCreator && (
|
|
|
|
<span className="comment__menu-help">{__('Prevent this channel from interacting with you.')}</span>
|
|
|
|
)}
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{!commentIsMine && (
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={handleCommentMute}>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.MUTE} />
|
|
|
|
{__('Mute')}
|
|
|
|
</div>
|
|
|
|
{activeChannelIsCreator && (
|
|
|
|
<span className="comment__menu-help">{__('Hide this channel for you only.')}</span>
|
|
|
|
)}
|
2021-02-11 06:12:41 +01:00
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
2021-06-16 04:27:58 +02:00
|
|
|
{(activeChannelIsAdmin || activeChannelIsModerator) && (
|
|
|
|
<div className="comment__menu-title">{__('Moderator tools')}</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{!commentIsMine && activeChannelIsAdmin && (
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={blockCommentAsAdmin}>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.GLOBE} />
|
|
|
|
{__('Global Block')}
|
|
|
|
</div>
|
|
|
|
<span className="comment__menu-help">{__('Block this channel as global admin')}</span>
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{!commentIsMine && activeChannelIsModerator && (
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={blockCommentAsModerator}>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.BLOCK} />
|
|
|
|
{__('Moderator Block')}
|
|
|
|
</div>
|
|
|
|
<span className="comment__menu-help">
|
|
|
|
{__('Block this channel on behalf of %creator%', {
|
|
|
|
creator: contentChannelClaim ? contentChannelClaim.name : __('creator'),
|
|
|
|
})}
|
|
|
|
</span>
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
2021-02-11 06:12:41 +01:00
|
|
|
{activeChannelClaim && (
|
|
|
|
<div className="comment__menu-active">
|
|
|
|
<ChannelThumbnail uri={activeChannelClaim.permanent_url} />
|
2021-02-23 03:45:55 +01:00
|
|
|
<div className="comment__menu-channel">
|
|
|
|
{__('Interacting as %channelName%', { channelName: activeChannelClaim.name })}
|
|
|
|
</div>
|
2021-02-11 06:12:41 +01:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</MenuList>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CommentMenuList;
|