Highlight chat message if your channel is mentioned
This commit is contained in:
parent
60430b5267
commit
cd9dc5cf96
5 changed files with 35 additions and 6 deletions
|
@ -56,6 +56,7 @@ type MarkdownProps = {
|
|||
isMarkdownPost?: boolean,
|
||||
disableTimestamps?: boolean,
|
||||
stakedLevel?: number,
|
||||
setUserMention?: (boolean) => void,
|
||||
};
|
||||
|
||||
// ****************************************************************************
|
||||
|
@ -153,6 +154,7 @@ const MarkdownPreview = (props: MarkdownProps) => {
|
|||
isMarkdownPost,
|
||||
disableTimestamps,
|
||||
stakedLevel,
|
||||
setUserMention,
|
||||
} = props;
|
||||
|
||||
const strippedContent = content
|
||||
|
@ -187,6 +189,7 @@ const MarkdownPreview = (props: MarkdownProps) => {
|
|||
isMarkdownPost={isMarkdownPost}
|
||||
simpleLinks={simpleLinks}
|
||||
allowPreview={isStakeEnoughForPreview(stakedLevel)}
|
||||
setUserMention={setUserMention}
|
||||
/>
|
||||
),
|
||||
// Workaraund of remarkOptions.Fragment
|
||||
|
|
|
@ -45,6 +45,8 @@ function LivestreamComment(props: Props) {
|
|||
isPinned,
|
||||
} = props;
|
||||
|
||||
const [hasUserMention, setUserMention] = React.useState(false);
|
||||
|
||||
const commentByOwnerOfContent = claim && claim.signing_channel && claim.signing_channel.permanent_url === authorUri;
|
||||
const { claimName } = parseURI(authorUri);
|
||||
const stickerFromMessage = parseSticker(message);
|
||||
|
@ -54,6 +56,7 @@ function LivestreamComment(props: Props) {
|
|||
className={classnames('livestream-comment', {
|
||||
'livestream-comment--superchat': supportAmount > 0,
|
||||
'livestream-comment--sticker': Boolean(stickerFromMessage),
|
||||
'livestream-comment--mentioned': hasUserMention,
|
||||
})}
|
||||
>
|
||||
{supportAmount > 0 && (
|
||||
|
@ -117,7 +120,13 @@ function LivestreamComment(props: Props) {
|
|||
</div>
|
||||
) : (
|
||||
<div className="livestream-comment__text">
|
||||
<MarkdownPreview content={message} promptLinks stakedLevel={stakedLevel} disableTimestamps />
|
||||
<MarkdownPreview
|
||||
content={message}
|
||||
promptLinks
|
||||
stakedLevel={stakedLevel}
|
||||
disableTimestamps
|
||||
setUserMention={setUserMention}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { doOpenModal } from 'redux/actions/app';
|
||||
import { selectMyChannelUrls } from 'redux/selectors/claims';
|
||||
import MarkdownLink from './view';
|
||||
|
||||
const select = () => ({});
|
||||
const select = (state, props) => ({
|
||||
myChannelUrls: selectMyChannelUrls(state),
|
||||
});
|
||||
|
||||
const perform = (dispatch) => ({
|
||||
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),
|
||||
});
|
||||
|
|
|
@ -15,6 +15,8 @@ type Props = {
|
|||
parentCommentId?: string,
|
||||
isMarkdownPost?: boolean,
|
||||
simpleLinks?: boolean,
|
||||
myChannelUrls: ?Array<string>,
|
||||
setUserMention?: (boolean) => void,
|
||||
};
|
||||
|
||||
function MarkdownLink(props: Props) {
|
||||
|
@ -27,6 +29,8 @@ function MarkdownLink(props: Props) {
|
|||
parentCommentId,
|
||||
isMarkdownPost,
|
||||
simpleLinks = false,
|
||||
myChannelUrls,
|
||||
setUserMention,
|
||||
} = props;
|
||||
|
||||
let decodedUri;
|
||||
|
@ -34,15 +38,20 @@ function MarkdownLink(props: Props) {
|
|||
decodedUri = decodeURI(href);
|
||||
} catch (e) {}
|
||||
|
||||
if (!href || !decodedUri) {
|
||||
return children || null;
|
||||
}
|
||||
|
||||
let element = <span>{children}</span>;
|
||||
|
||||
// Regex for url protocol
|
||||
const protocolRegex = new RegExp('^(https?|lbry|mailto)+:', 'i');
|
||||
const protocol = href ? protocolRegex.exec(href) : null;
|
||||
const isMention = href.startsWith('lbry://@');
|
||||
const mentionedMyChannel =
|
||||
isMention && (myChannelUrls ? myChannelUrls.some((url) => url.replace('#', ':') === href) : false);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (mentionedMyChannel && setUserMention) setUserMention(true);
|
||||
}, [mentionedMyChannel, setUserMention]);
|
||||
|
||||
if (!href || !decodedUri) return children || null;
|
||||
|
||||
let linkUrlObject;
|
||||
try {
|
||||
|
|
|
@ -104,6 +104,10 @@ $recent-msg-button__height: 2rem;
|
|||
}
|
||||
}
|
||||
|
||||
.livestream-comment--mentioned {
|
||||
background-color: var(--color-card-background-highlighted);
|
||||
}
|
||||
|
||||
.livestream-comment__info {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue