2021-04-23 21:59:48 +02:00
|
|
|
// @flow
|
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import React from 'react';
|
2021-10-17 10:36:14 +02:00
|
|
|
import { parseURI } from 'util/lbryURI';
|
2021-12-30 04:43:53 +01:00
|
|
|
import Empty from 'component/common/empty';
|
2021-04-23 21:59:48 +02:00
|
|
|
import MarkdownPreview from 'component/common/markdown-preview';
|
2021-07-23 12:26:16 +02:00
|
|
|
import Tooltip from 'component/common/tooltip';
|
2021-04-23 21:59:48 +02:00
|
|
|
import ChannelThumbnail from 'component/channelThumbnail';
|
|
|
|
import { Menu, MenuButton } from '@reach/menu-button';
|
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import CommentMenuList from 'component/commentMenuList';
|
2021-04-29 21:30:45 +02:00
|
|
|
import Button from 'component/button';
|
2021-04-23 21:59:48 +02:00
|
|
|
import CreditAmount from 'component/common/credit-amount';
|
2022-01-04 16:18:40 +01:00
|
|
|
import DateTime from 'component/dateTime';
|
2021-10-28 22:25:34 +02:00
|
|
|
import OptimizedImage from 'component/optimizedImage';
|
|
|
|
import { parseSticker } from 'util/comments';
|
2021-04-23 21:59:48 +02:00
|
|
|
|
|
|
|
type Props = {
|
2021-12-30 04:40:51 +01:00
|
|
|
comment: Comment,
|
2022-01-04 16:56:12 +01:00
|
|
|
forceUpdate?: any,
|
2021-04-23 21:59:48 +02:00
|
|
|
uri: string,
|
2021-12-30 04:40:51 +01:00
|
|
|
// --- redux:
|
2021-04-23 21:59:48 +02:00
|
|
|
claim: StreamClaim,
|
|
|
|
stakedLevel: number,
|
2021-12-30 04:40:51 +01:00
|
|
|
myChannelIds: ?Array<string>,
|
2021-04-23 21:59:48 +02:00
|
|
|
};
|
|
|
|
|
2021-07-06 03:29:46 +02:00
|
|
|
function LivestreamComment(props: Props) {
|
2022-01-04 16:56:12 +01:00
|
|
|
const { comment, forceUpdate, uri, claim, stakedLevel, myChannelIds } = props;
|
2022-01-04 16:18:40 +01:00
|
|
|
const { channel_url: authorUri, comment: message, support_amount: supportAmount, timestamp } = comment;
|
2021-09-01 07:58:48 +02:00
|
|
|
|
2021-12-29 21:04:02 +01:00
|
|
|
const [hasUserMention, setUserMention] = React.useState(false);
|
2021-12-30 04:40:51 +01:00
|
|
|
const commentIsMine = comment.channel_id && isMyComment(comment.channel_id);
|
2021-12-29 21:04:02 +01:00
|
|
|
|
2021-04-23 21:59:48 +02:00
|
|
|
const commentByOwnerOfContent = claim && claim.signing_channel && claim.signing_channel.permanent_url === authorUri;
|
2021-12-30 04:40:51 +01:00
|
|
|
const { claimName } = parseURI(authorUri || '');
|
2021-10-28 22:25:34 +02:00
|
|
|
const stickerFromMessage = parseSticker(message);
|
2022-01-04 16:18:40 +01:00
|
|
|
const timePosted = timestamp * 1000;
|
2021-04-23 21:59:48 +02:00
|
|
|
|
2021-12-30 04:40:51 +01:00
|
|
|
// todo: implement comment_list --mine in SDK so redux can grab with selectCommentIsMine
|
|
|
|
function isMyComment(channelId: string) {
|
|
|
|
return myChannelIds ? myChannelIds.includes(channelId) : false;
|
|
|
|
}
|
|
|
|
|
2021-04-23 21:59:48 +02:00
|
|
|
return (
|
|
|
|
<li
|
|
|
|
className={classnames('livestream-comment', {
|
|
|
|
'livestream-comment--superchat': supportAmount > 0,
|
2021-10-28 22:25:34 +02:00
|
|
|
'livestream-comment--sticker': Boolean(stickerFromMessage),
|
2021-12-29 21:04:02 +01:00
|
|
|
'livestream-comment--mentioned': hasUserMention,
|
2021-04-23 21:59:48 +02:00
|
|
|
})}
|
|
|
|
>
|
|
|
|
{supportAmount > 0 && (
|
|
|
|
<div className="super-chat livestream-superchat__banner">
|
|
|
|
<div className="livestream-superchat__banner-corner" />
|
2021-12-30 04:40:51 +01:00
|
|
|
<CreditAmount
|
|
|
|
isFiat={comment.is_fiat}
|
|
|
|
amount={supportAmount}
|
|
|
|
superChat
|
|
|
|
className="livestream-superchat__amount"
|
|
|
|
/>
|
2021-04-23 21:59:48 +02:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<div className="livestream-comment__body">
|
2021-11-05 20:31:51 +01:00
|
|
|
{supportAmount > 0 && <ChannelThumbnail uri={authorUri} xsmall />}
|
2021-12-31 13:25:47 +01:00
|
|
|
<div className="livestream-comment__info">
|
2021-12-30 04:40:51 +01:00
|
|
|
{comment.is_global_mod && (
|
2021-12-20 13:38:12 +01:00
|
|
|
<Tooltip title={__('Admin')}>
|
2021-07-23 12:26:16 +02:00
|
|
|
<span className="comment__badge comment__badge--global-mod">
|
|
|
|
<Icon icon={ICONS.BADGE_MOD} size={16} />
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
|
2021-12-30 04:40:51 +01:00
|
|
|
{comment.is_moderator && (
|
2021-12-20 13:38:12 +01:00
|
|
|
<Tooltip title={__('Moderator')}>
|
2021-07-23 12:26:16 +02:00
|
|
|
<span className="comment__badge comment__badge--mod">
|
|
|
|
<Icon icon={ICONS.BADGE_MOD} size={16} />
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
|
2021-09-02 14:50:03 +02:00
|
|
|
{commentByOwnerOfContent && (
|
2021-12-20 13:38:12 +01:00
|
|
|
<Tooltip title={__('Streamer')}>
|
2021-09-02 14:50:03 +02:00
|
|
|
<span className="comment__badge">
|
|
|
|
<Icon icon={ICONS.BADGE_STREAMER} size={16} />
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
|
2021-04-29 21:30:45 +02:00
|
|
|
<Button
|
|
|
|
className={classnames('button--uri-indicator comment__author', {
|
2021-04-23 21:59:48 +02:00
|
|
|
'comment__author--creator': commentByOwnerOfContent,
|
|
|
|
})}
|
2021-04-29 21:30:45 +02:00
|
|
|
target="_blank"
|
|
|
|
navigate={authorUri}
|
|
|
|
>
|
|
|
|
{claimName}
|
|
|
|
</Button>
|
2021-04-23 21:59:48 +02:00
|
|
|
|
2021-12-30 04:40:51 +01:00
|
|
|
{comment.is_pinned && (
|
2021-08-09 08:26:03 +02:00
|
|
|
<span className="comment__pin">
|
|
|
|
<Icon icon={ICONS.PIN} size={14} />
|
|
|
|
{__('Pinned')}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
|
2022-01-04 16:56:12 +01:00
|
|
|
{/* Use key to force timestamp update */}
|
|
|
|
<DateTime date={timePosted} timeAgo key={forceUpdate} />
|
2022-01-04 16:18:40 +01:00
|
|
|
|
2021-12-30 04:43:53 +01:00
|
|
|
{comment.removed ? (
|
|
|
|
<div className="livestream-comment__text">
|
|
|
|
<Empty text={__('[Removed]')} />
|
|
|
|
</div>
|
|
|
|
) : stickerFromMessage ? (
|
2021-10-28 22:25:34 +02:00
|
|
|
<div className="sticker__comment">
|
2021-11-05 20:31:51 +01:00
|
|
|
<OptimizedImage src={stickerFromMessage.url} waitLoad loading="lazy" />
|
2021-10-28 22:25:34 +02:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="livestream-comment__text">
|
2021-12-29 21:04:02 +01:00
|
|
|
<MarkdownPreview
|
|
|
|
content={message}
|
|
|
|
promptLinks
|
|
|
|
stakedLevel={stakedLevel}
|
|
|
|
disableTimestamps
|
|
|
|
setUserMention={setUserMention}
|
|
|
|
/>
|
2021-10-28 22:25:34 +02:00
|
|
|
</div>
|
|
|
|
)}
|
2021-04-23 21:59:48 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="livestream-comment__menu">
|
|
|
|
<Menu>
|
|
|
|
<MenuButton className="menu__button">
|
2021-09-01 07:58:48 +02:00
|
|
|
<Icon size={18} icon={ICONS.MORE_VERTICAL} />
|
2021-04-23 21:59:48 +02:00
|
|
|
</MenuButton>
|
2021-05-04 17:08:36 +02:00
|
|
|
<CommentMenuList
|
|
|
|
uri={uri}
|
2021-12-30 04:40:51 +01:00
|
|
|
commentId={comment.comment_id}
|
2021-05-04 17:08:36 +02:00
|
|
|
authorUri={authorUri}
|
|
|
|
commentIsMine={commentIsMine}
|
2021-12-30 04:40:51 +01:00
|
|
|
isPinned={comment.is_pinned}
|
2021-10-12 23:06:20 +02:00
|
|
|
isTopLevel
|
|
|
|
disableEdit
|
|
|
|
isLiveComment
|
2021-05-04 17:08:36 +02:00
|
|
|
/>
|
2021-04-23 21:59:48 +02:00
|
|
|
</Menu>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-06 03:29:46 +02:00
|
|
|
export default LivestreamComment;
|