2021-02-11 06:12:41 +01:00
|
|
|
// @flow
|
2021-10-04 15:20:37 +02:00
|
|
|
import { getChannelFromClaim } from 'util/claim';
|
|
|
|
import { MenuList, MenuItem } from '@reach/menu-button';
|
2021-10-17 10:36:14 +02:00
|
|
|
import { parseURI } from 'util/lbryURI';
|
2021-10-04 15:20:37 +02:00
|
|
|
import { URL } from 'config';
|
|
|
|
import { useHistory } from 'react-router';
|
2021-02-11 06:12:41 +01:00
|
|
|
import * as ICONS from 'constants/icons';
|
2021-07-19 23:22:39 +02:00
|
|
|
import * as MODALS from 'constants/modal_types';
|
2021-02-11 06:12:41 +01:00
|
|
|
import ChannelThumbnail from 'component/channelThumbnail';
|
|
|
|
import Icon from 'component/common/icon';
|
2021-10-04 15:20:37 +02:00
|
|
|
import React from 'react';
|
2022-02-04 21:59:11 +01:00
|
|
|
import { useIsMobile } from 'effects/use-screensize';
|
2021-02-11 06:12:41 +01:00
|
|
|
|
|
|
|
type Props = {
|
2021-08-12 09:10:44 +02:00
|
|
|
uri: ?string,
|
2021-02-11 06:12:41 +01:00
|
|
|
authorUri: string, // full LBRY Channel URI: lbry://@channel#123...
|
|
|
|
commentId: string, // sha256 digest identifying the comment
|
2021-08-25 07:32:38 +02:00
|
|
|
isTopLevel: boolean,
|
2021-02-11 06:12:41 +01:00
|
|
|
isPinned: boolean,
|
2021-08-25 07:32:38 +02:00
|
|
|
commentIsMine: boolean, // if this comment was signed by an owned channel
|
|
|
|
disableEdit?: boolean,
|
|
|
|
disableRemove?: boolean,
|
|
|
|
supportAmount?: any,
|
2021-10-12 23:06:20 +02:00
|
|
|
isLiveComment: boolean,
|
2021-08-25 07:32:38 +02:00
|
|
|
// --- select ---
|
|
|
|
claim: ?Claim,
|
|
|
|
claimIsMine: boolean,
|
2021-02-11 06:12:41 +01:00
|
|
|
activeChannelClaim: ?ChannelClaim,
|
2021-08-25 07:32:38 +02:00
|
|
|
playingUri: ?PlayingUri,
|
2021-09-08 18:31:45 +02:00
|
|
|
moderationDelegatorsById: { [string]: { global: boolean, delegators: { name: string, claimId: string } } },
|
2021-08-25 07:32:38 +02:00
|
|
|
// --- perform ---
|
2021-10-04 15:20:37 +02:00
|
|
|
doToast: ({ message: string }) => void,
|
|
|
|
handleEditComment: () => void,
|
2021-08-25 07:32:38 +02:00
|
|
|
openModal: (id: string, {}) => void,
|
|
|
|
clearPlayingUri: () => void,
|
|
|
|
muteChannel: (string) => void,
|
|
|
|
pinComment: (string, string, boolean) => Promise<any>,
|
2021-06-19 11:52:17 +02:00
|
|
|
commentModAddDelegate: (string, string, ChannelClaim) => void,
|
2021-08-27 12:29:58 +02:00
|
|
|
setQuickReply: (any) => void,
|
2022-02-02 13:45:16 +01:00
|
|
|
handleDismissPin?: () => void,
|
2021-02-11 06:12:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function CommentMenuList(props: Props) {
|
|
|
|
const {
|
2021-08-12 09:10:44 +02:00
|
|
|
uri,
|
2021-06-16 04:27:58 +02:00
|
|
|
claim,
|
2021-11-24 15:33:34 +01:00
|
|
|
claimIsMine,
|
2021-02-11 06:12:41 +01:00
|
|
|
authorUri,
|
|
|
|
commentIsMine,
|
|
|
|
commentId,
|
|
|
|
activeChannelClaim,
|
|
|
|
isTopLevel,
|
|
|
|
isPinned,
|
2021-03-02 11:12:54 +01:00
|
|
|
playingUri,
|
2021-09-08 18:31:45 +02:00
|
|
|
moderationDelegatorsById,
|
2021-05-04 17:08:36 +02:00
|
|
|
disableEdit,
|
|
|
|
disableRemove,
|
2021-07-19 23:22:39 +02:00
|
|
|
supportAmount,
|
2021-10-12 23:06:20 +02:00
|
|
|
isLiveComment,
|
2021-10-04 15:20:37 +02:00
|
|
|
doToast,
|
|
|
|
handleEditComment,
|
|
|
|
openModal,
|
|
|
|
clearPlayingUri,
|
|
|
|
muteChannel,
|
|
|
|
pinComment,
|
|
|
|
commentModAddDelegate,
|
2021-08-27 12:29:58 +02:00
|
|
|
setQuickReply,
|
2022-02-02 13:45:16 +01:00
|
|
|
handleDismissPin,
|
2021-02-11 06:12:41 +01:00
|
|
|
} = props;
|
2021-06-16 04:27:58 +02:00
|
|
|
|
2022-02-04 21:59:11 +01:00
|
|
|
const isMobile = useIsMobile();
|
|
|
|
|
2021-10-04 15:20:37 +02:00
|
|
|
const {
|
|
|
|
location: { pathname, search },
|
|
|
|
} = useHistory();
|
|
|
|
|
2021-09-08 18:31:45 +02:00
|
|
|
const contentChannelClaim = getChannelFromClaim(claim);
|
2021-11-08 18:22:40 +01:00
|
|
|
const contentChannelPermanentUrl = contentChannelClaim && contentChannelClaim.permanent_url;
|
|
|
|
|
2021-09-08 18:31:45 +02:00
|
|
|
const activeModeratorInfo = activeChannelClaim && moderationDelegatorsById[activeChannelClaim.claim_id];
|
2021-02-11 06:12:41 +01:00
|
|
|
const activeChannelIsCreator = activeChannelClaim && activeChannelClaim.permanent_url === contentChannelPermanentUrl;
|
2021-09-08 18:31:45 +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 handleDeleteComment() {
|
2021-03-02 11:12:54 +01:00
|
|
|
if (playingUri && playingUri.source === 'comment') {
|
|
|
|
clearPlayingUri();
|
|
|
|
}
|
2021-11-08 18:22:40 +01:00
|
|
|
|
2021-08-27 12:29:58 +02:00
|
|
|
openModal(MODALS.CONFIRM_REMOVE_COMMENT, {
|
|
|
|
commentId,
|
2021-11-08 18:22:40 +01:00
|
|
|
deleterClaim: activeChannelClaim,
|
|
|
|
deleterIsModOrAdmin: activeChannelIsAdmin || activeChannelIsModerator,
|
|
|
|
creatorClaim: commentIsMine ? undefined : contentChannelClaim,
|
2021-08-27 12:29:58 +02:00
|
|
|
supportAmount,
|
|
|
|
setQuickReply,
|
|
|
|
});
|
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);
|
2021-10-17 10:36:14 +02:00
|
|
|
if (channelName && channelClaimId) commentModAddDelegate(channelClaimId, channelName, activeChannelClaim);
|
2021-06-19 11:52:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-08 18:31:45 +02:00
|
|
|
function getBlockOptionElem() {
|
|
|
|
const isPersonalBlockTheOnlyOption = !activeChannelIsModerator && !activeChannelIsAdmin;
|
2021-11-24 15:33:34 +01:00
|
|
|
const isTimeoutBlockAvailable = claimIsMine || activeChannelIsModerator;
|
2021-09-08 18:31:45 +02:00
|
|
|
const personalPermanentBlockOnly = isPersonalBlockTheOnlyOption && !isTimeoutBlockAvailable;
|
|
|
|
|
|
|
|
function getSubtitle() {
|
|
|
|
if (personalPermanentBlockOnly) {
|
|
|
|
return {
|
|
|
|
line1: __('Prevent this channel from interacting with you.'),
|
|
|
|
line2: null,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
if (activeChannelIsModerator && activeChannelIsAdmin) {
|
|
|
|
return {
|
|
|
|
line1: __('Personal | Moderator | Admin'),
|
|
|
|
line2: __('Choose a permanent or temporary ban.'),
|
|
|
|
};
|
|
|
|
} else if (activeChannelIsModerator && !activeChannelIsAdmin) {
|
|
|
|
return {
|
|
|
|
line1: __('Personal | Moderator'),
|
|
|
|
line2: __('Choose a permanent or temporary ban.'),
|
|
|
|
};
|
|
|
|
} else if (!activeChannelIsModerator && activeChannelIsAdmin) {
|
|
|
|
return {
|
|
|
|
line1: __('Personal | Admin'),
|
|
|
|
line2: __('Choose a permanent or temporary ban.'),
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
line1: null,
|
|
|
|
line2: __('Choose a permanent or temporary ban.'),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const subtitle = getSubtitle();
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.BLOCK} />
|
|
|
|
{__('Block')}
|
|
|
|
</div>
|
|
|
|
{subtitle.line1 && <span className="comment__menu-help">{subtitle.line1}</span>}
|
|
|
|
{subtitle.line2 && (
|
|
|
|
<span className="comment__menu-help">
|
|
|
|
{subtitle.line2} {!personalPermanentBlockOnly && <Icon aria-hidden icon={ICONS.EXTERNAL} />}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-04 15:20:37 +02:00
|
|
|
function handleCopyCommentLink() {
|
|
|
|
const urlParams = new URLSearchParams(search);
|
|
|
|
urlParams.delete('lc');
|
|
|
|
urlParams.append('lc', commentId);
|
|
|
|
navigator.clipboard
|
|
|
|
.writeText(`${URL}${pathname}?${urlParams.toString()}`)
|
|
|
|
.then(() => doToast({ message: __('Link copied.') }));
|
|
|
|
}
|
|
|
|
|
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"
|
2021-10-04 15:20:37 +02:00
|
|
|
onSelect={() => pinComment(commentId, claim ? claim.claim_id : '', isPinned)}
|
2021-02-11 06:12:41 +01:00
|
|
|
>
|
|
|
|
<span className={'button__content'}>
|
|
|
|
<Icon aria-hidden icon={ICONS.PIN} className={'icon'} />
|
|
|
|
{isPinned ? __('Unpin') : __('Pin')}
|
|
|
|
</span>
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
2021-09-24 03:57:24 +02:00
|
|
|
{activeChannelIsCreator && activeChannelClaim && activeChannelClaim.permanent_url !== authorUri && (
|
2021-06-19 11:52:17 +02:00
|
|
|
<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">
|
2021-09-24 03:57:24 +02:00
|
|
|
{activeChannelClaim
|
|
|
|
? __('Assign this user to moderate %channel%.', { channel: activeChannelClaim.name })
|
|
|
|
: __('Assign this user to moderate your channel.')}
|
2021-06-19 11:52:17 +02:00
|
|
|
</span>
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
2021-09-24 04:00:37 +02:00
|
|
|
{commentIsMine && activeChannelClaim && activeChannelClaim.permanent_url === authorUri && !disableEdit && (
|
|
|
|
<MenuItem className="comment__menu-option menu__link" onSelect={handleEditComment}>
|
|
|
|
<Icon aria-hidden icon={ICONS.EDIT} />
|
|
|
|
{__('Edit')}
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
2021-05-04 17:08:36 +02:00
|
|
|
{!disableRemove &&
|
|
|
|
activeChannelClaim &&
|
2021-11-08 18:22:40 +01:00
|
|
|
(activeChannelIsModerator ||
|
2021-11-09 15:47:49 +01:00
|
|
|
activeChannelIsAdmin ||
|
2021-11-08 18:22:40 +01:00
|
|
|
activeChannelClaim.permanent_url === authorUri ||
|
2021-02-11 06:12:41 +01:00
|
|
|
activeChannelClaim.permanent_url === contentChannelPermanentUrl) && (
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={handleDeleteComment}>
|
|
|
|
<div className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.DELETE} />
|
|
|
|
{__('Remove')}
|
|
|
|
</div>
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{!commentIsMine && (
|
2021-10-04 15:20:37 +02:00
|
|
|
<>
|
|
|
|
<MenuItem
|
|
|
|
className="comment__menu-option"
|
2021-11-09 15:43:02 +01:00
|
|
|
onSelect={() =>
|
|
|
|
openModal(MODALS.BLOCK_CHANNEL, {
|
|
|
|
contentUri: uri,
|
|
|
|
commenterUri: authorUri,
|
|
|
|
offendingCommentId: commentId,
|
|
|
|
})
|
|
|
|
}
|
2021-10-04 15:20:37 +02:00
|
|
|
>
|
|
|
|
{getBlockOptionElem()}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={() => muteChannel(authorUri)}>
|
|
|
|
<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>
|
|
|
|
)}
|
|
|
|
</MenuItem>
|
|
|
|
</>
|
2021-03-03 19:50:16 +01:00
|
|
|
)}
|
|
|
|
|
2021-10-12 23:06:20 +02:00
|
|
|
{IS_WEB && !isLiveComment && (
|
2021-10-04 15:20:37 +02:00
|
|
|
<MenuItem className="comment__menu-option" onSelect={handleCopyCommentLink}>
|
2021-03-03 19:50:16 +01:00
|
|
|
<div className="menu__link">
|
2021-10-04 15:20:37 +02:00
|
|
|
<Icon aria-hidden icon={ICONS.COPY_LINK} />
|
|
|
|
{__('Copy Link')}
|
2021-03-03 19:50:16 +01:00
|
|
|
</div>
|
2021-02-11 06:12:41 +01:00
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
2022-02-04 21:59:11 +01:00
|
|
|
{isPinned && isLiveComment && isMobile && (
|
2022-02-02 13:45:16 +01:00
|
|
|
<MenuItem className="comment__menu-option menu__link" onSelect={handleDismissPin}>
|
|
|
|
<Icon aria-hidden icon={ICONS.DISMISS_ALL} />
|
|
|
|
{__('Dismiss Pin')}
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
|
2021-02-11 06:12:41 +01:00
|
|
|
{activeChannelClaim && (
|
|
|
|
<div className="comment__menu-active">
|
ChannelThumbnail improvements
- [x] (6332) The IntersectionObserver method of lazy-loading loads cached images visibly late on slower devices. Previously, it was also showing the "broken image" icon briefly, which we mended by placing a dummy transparent image as the initial src.
- Reverted that ugly transparent image fix.
- Use the browser's built-in `loading="lazy"` instead. Sorry, Safari.
- [x] Size-optimization did not take "device pixel ratio" into account.
- When resizing an image through the CDN, we can't just take the dimensions of the tag in pixels directly -- we need to take zooming into account, otherwise the image ends up blurry.
- Previously, we quickly disabled optimization for the channel avatar in the Channel Page because of this. Now that we know the root-cause, the change was reverted and we now go through the CDN with appropriate sizes. This also improves our Web Vital scores.
- [x] Size-optimization wasn't really implemented for all ChannelThumbnail instances.
- The CDN-optimized size was hardcoded to the largest instance, so small images like sidebar thumbnails are still loading images that are unnecessarily larger.
- There's a little-bit of hardcoding of values from CSS here, but I think it's a ok compromise (not something we change often). It also doesn't need to be exact -- the "device pixel ratio" calculate will ensure it's slightly larger than what we need.
- [x] Set `width` and `height` of `<img>` to improve CLS.
- Addresses Ligthhouse complaints, although technically the shifting was addressed at the `ClaimPreviewTile` level (sub-container dimensions are well defined).
- Notes: the values don't need to be the final CSS-adjusted sizes. It just needs to be in the right aspect ratio to help the browser pre-allocate space to avoid shifts.
- [x] Add option to disable lazy-load Channel Thumbnails
- The guidelines mentioned that items that are already in the viewport should not enable `loading="lazy"`.
- We have a few areas where it doesn't make sense to lazy-load (e.g. thumbnail in Header, channel selector dropdown, publish preview, etc.).
2021-07-05 07:20:40 +02:00
|
|
|
<ChannelThumbnail xsmall noLazyLoad 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;
|