2021-04-23 21:59:48 +02:00
|
|
|
// @flow
|
2022-01-14 21:24:16 +01:00
|
|
|
import 'scss/component/_livestream-comment.scss';
|
|
|
|
|
|
|
|
import { getStickerUrl } from 'util/comments';
|
|
|
|
import { Menu, MenuButton } from '@reach/menu-button';
|
2021-10-17 10:36:14 +02:00
|
|
|
import { parseURI } from 'util/lbryURI';
|
2022-01-14 21:24:16 +01:00
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import Button from 'component/button';
|
2021-04-23 21:59:48 +02:00
|
|
|
import ChannelThumbnail from 'component/channelThumbnail';
|
|
|
|
import classnames from 'classnames';
|
2022-01-14 21:24:16 +01:00
|
|
|
import CommentBadge from 'component/common/comment-badge';
|
2021-04-23 21:59:48 +02:00
|
|
|
import CommentMenuList from 'component/commentMenuList';
|
|
|
|
import CreditAmount from 'component/common/credit-amount';
|
2022-01-04 16:18:40 +01:00
|
|
|
import DateTime from 'component/dateTime';
|
2022-01-14 21:24:16 +01:00
|
|
|
import Empty from 'component/common/empty';
|
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
import MarkdownPreview from 'component/common/markdown-preview';
|
2021-10-28 22:25:34 +02:00
|
|
|
import OptimizedImage from 'component/optimizedImage';
|
2022-01-14 21:24:16 +01:00
|
|
|
import React from 'react';
|
2022-07-01 21:40:06 +02:00
|
|
|
import PremiumBadge from 'component/premiumBadge';
|
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,
|
2021-12-30 04:40:51 +01:00
|
|
|
myChannelIds: ?Array<string>,
|
2022-01-14 21:24:16 +01:00
|
|
|
stakedLevel: number,
|
2022-02-02 13:48:24 +01:00
|
|
|
isMobile?: boolean,
|
2022-03-09 19:05:37 +01:00
|
|
|
odyseeMembership: string,
|
2022-02-02 13:45:16 +01:00
|
|
|
handleDismissPin?: () => void,
|
2022-02-05 02:44:54 +01:00
|
|
|
restoreScrollPos?: () => void,
|
2022-03-09 19:05:37 +01:00
|
|
|
claimsByUri: { [string]: any },
|
2021-04-23 21:59:48 +02:00
|
|
|
};
|
|
|
|
|
2022-01-14 21:24:16 +01:00
|
|
|
export default function LivestreamComment(props: Props) {
|
2022-02-05 02:44:54 +01:00
|
|
|
const {
|
|
|
|
comment,
|
|
|
|
forceUpdate,
|
|
|
|
uri,
|
|
|
|
claim,
|
|
|
|
myChannelIds,
|
|
|
|
stakedLevel,
|
|
|
|
isMobile,
|
|
|
|
handleDismissPin,
|
|
|
|
restoreScrollPos,
|
2022-03-09 19:05:37 +01:00
|
|
|
odyseeMembership,
|
2022-02-05 02:44:54 +01:00
|
|
|
} = props;
|
2022-01-14 21:24:16 +01:00
|
|
|
|
|
|
|
const {
|
|
|
|
channel_url: authorUri,
|
|
|
|
comment_id: commentId,
|
|
|
|
comment: message,
|
|
|
|
is_fiat: isFiat,
|
|
|
|
is_global_mod: isGlobalMod,
|
|
|
|
is_moderator: isModerator,
|
|
|
|
is_pinned: isPinned,
|
|
|
|
removed,
|
|
|
|
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);
|
|
|
|
|
2022-01-14 21:24:16 +01:00
|
|
|
const isStreamer = claim && claim.signing_channel && claim.signing_channel.permanent_url === authorUri;
|
2021-12-30 04:40:51 +01:00
|
|
|
const { claimName } = parseURI(authorUri || '');
|
2022-01-14 21:24:16 +01:00
|
|
|
const stickerUrlFromMessage = getStickerUrl(message);
|
|
|
|
const isSticker = Boolean(stickerUrlFromMessage);
|
2022-01-04 16:18:40 +01:00
|
|
|
const timePosted = timestamp * 1000;
|
2022-01-14 21:24:16 +01:00
|
|
|
const commentIsMine = comment.channel_id && isMyComment(comment.channel_id);
|
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;
|
|
|
|
}
|
|
|
|
|
2022-02-04 21:59:11 +01:00
|
|
|
// For every new <LivestreamComment /> component that is rendered on mobile view,
|
|
|
|
// keep the scroll at the bottom (newest)
|
|
|
|
React.useEffect(() => {
|
2022-02-05 02:44:54 +01:00
|
|
|
if (isMobile && restoreScrollPos) {
|
|
|
|
restoreScrollPos();
|
2022-02-04 21:59:11 +01:00
|
|
|
}
|
2022-02-05 02:44:54 +01:00
|
|
|
}, [isMobile, restoreScrollPos]);
|
2022-02-04 21:59:11 +01:00
|
|
|
|
2021-04-23 21:59:48 +02:00
|
|
|
return (
|
|
|
|
<li
|
2022-01-14 21:24:16 +01:00
|
|
|
className={classnames('livestream__comment', {
|
|
|
|
'livestream__comment--superchat': supportAmount > 0,
|
|
|
|
'livestream__comment--sticker': isSticker,
|
|
|
|
'livestream__comment--mentioned': hasUserMention,
|
2022-02-02 13:48:24 +01:00
|
|
|
'livestream__comment--mobile': isMobile,
|
2021-04-23 21:59:48 +02:00
|
|
|
})}
|
|
|
|
>
|
|
|
|
{supportAmount > 0 && (
|
2022-01-14 21:24:16 +01:00
|
|
|
<div className="livestreamComment__superchatBanner">
|
|
|
|
<CreditAmount isFiat={isFiat} amount={supportAmount} superChat />
|
2021-04-23 21:59:48 +02:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2022-01-14 21:24:16 +01:00
|
|
|
<div className="livestreamComment__body">
|
2021-11-05 20:31:51 +01:00
|
|
|
{supportAmount > 0 && <ChannelThumbnail uri={authorUri} xsmall />}
|
2021-07-23 12:26:16 +02:00
|
|
|
|
2022-01-14 21:24:16 +01:00
|
|
|
<div className="livestreamComment__info">
|
2021-04-29 21:30:45 +02:00
|
|
|
<Button
|
2022-01-14 21:24:16 +01:00
|
|
|
className={classnames('button--uri-indicator comment__author', { 'comment__author--creator': isStreamer })}
|
2021-04-29 21:30:45 +02:00
|
|
|
target="_blank"
|
|
|
|
navigate={authorUri}
|
|
|
|
>
|
|
|
|
{claimName}
|
|
|
|
</Button>
|
2021-04-23 21:59:48 +02:00
|
|
|
|
2022-01-14 21:24:16 +01:00
|
|
|
{isPinned && (
|
2021-08-09 08:26:03 +02:00
|
|
|
<span className="comment__pin">
|
|
|
|
<Icon icon={ICONS.PIN} size={14} />
|
|
|
|
{__('Pinned')}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
|
2022-03-15 14:48:25 +01:00
|
|
|
{isGlobalMod && <CommentBadge label={__('Admin')} icon={ICONS.BADGE_ADMIN} size={16} />}
|
|
|
|
{isModerator && <CommentBadge label={__('Moderator')} icon={ICONS.BADGE_MOD} size={16} />}
|
2022-03-09 19:05:37 +01:00
|
|
|
{isStreamer && <CommentBadge label={__('Streamer')} icon={ICONS.BADGE_STREAMER} size={16} />}
|
2022-03-28 15:21:53 +02:00
|
|
|
<PremiumBadge membership={odyseeMembership} linkPage />
|
2022-03-09 19:05:37 +01:00
|
|
|
|
2022-01-04 16:56:12 +01:00
|
|
|
{/* Use key to force timestamp update */}
|
2022-01-04 21:33:55 +01:00
|
|
|
<DateTime date={timePosted} timeAgo key={forceUpdate} genericSeconds />
|
2022-01-04 16:18:40 +01:00
|
|
|
|
2022-01-14 21:24:16 +01:00
|
|
|
{isSticker ? (
|
2021-10-28 22:25:34 +02:00
|
|
|
<div className="sticker__comment">
|
2022-01-14 21:24:16 +01:00
|
|
|
<OptimizedImage src={stickerUrlFromMessage} waitLoad loading="lazy" />
|
2021-10-28 22:25:34 +02:00
|
|
|
</div>
|
|
|
|
) : (
|
2022-01-14 21:24:16 +01:00
|
|
|
<div className="livestreamComment__text">
|
|
|
|
{removed ? (
|
|
|
|
<Empty text={__('[Removed]')} />
|
|
|
|
) : (
|
|
|
|
<MarkdownPreview
|
|
|
|
content={message}
|
|
|
|
promptLinks
|
|
|
|
stakedLevel={stakedLevel}
|
|
|
|
disableTimestamps
|
|
|
|
setUserMention={setUserMention}
|
2022-06-28 07:14:06 +02:00
|
|
|
hasMembership={Boolean(odyseeMembership)}
|
2022-01-14 21:24:16 +01:00
|
|
|
/>
|
|
|
|
)}
|
2021-10-28 22:25:34 +02:00
|
|
|
</div>
|
|
|
|
)}
|
2021-04-23 21:59:48 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2022-01-14 21:24:16 +01:00
|
|
|
<div className="livestreamComment__menu">
|
2021-04-23 21:59:48 +02:00
|
|
|
<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>
|
2022-01-14 21:24:16 +01:00
|
|
|
|
2021-05-04 17:08:36 +02:00
|
|
|
<CommentMenuList
|
|
|
|
uri={uri}
|
2022-01-14 21:24:16 +01:00
|
|
|
commentId={commentId}
|
2021-05-04 17:08:36 +02:00
|
|
|
authorUri={authorUri}
|
|
|
|
commentIsMine={commentIsMine}
|
2022-01-14 21:24:16 +01:00
|
|
|
isPinned={isPinned}
|
2021-10-12 23:06:20 +02:00
|
|
|
isTopLevel
|
|
|
|
disableEdit
|
2022-01-19 14:42:39 +01:00
|
|
|
disableRemove={comment.removed}
|
2021-10-12 23:06:20 +02:00
|
|
|
isLiveComment
|
2022-02-02 13:45:16 +01:00
|
|
|
handleDismissPin={handleDismissPin}
|
2021-05-04 17:08:36 +02:00
|
|
|
/>
|
2021-04-23 21:59:48 +02:00
|
|
|
</Menu>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|