Highlight chat message if your channel is mentioned

This commit is contained in:
Rafael 2021-12-29 17:04:02 -03:00 committed by Thomas Zarebczan
parent 60430b5267
commit cd9dc5cf96
5 changed files with 35 additions and 6 deletions

View file

@ -56,6 +56,7 @@ type MarkdownProps = {
isMarkdownPost?: boolean, isMarkdownPost?: boolean,
disableTimestamps?: boolean, disableTimestamps?: boolean,
stakedLevel?: number, stakedLevel?: number,
setUserMention?: (boolean) => void,
}; };
// **************************************************************************** // ****************************************************************************
@ -153,6 +154,7 @@ const MarkdownPreview = (props: MarkdownProps) => {
isMarkdownPost, isMarkdownPost,
disableTimestamps, disableTimestamps,
stakedLevel, stakedLevel,
setUserMention,
} = props; } = props;
const strippedContent = content const strippedContent = content
@ -187,6 +189,7 @@ const MarkdownPreview = (props: MarkdownProps) => {
isMarkdownPost={isMarkdownPost} isMarkdownPost={isMarkdownPost}
simpleLinks={simpleLinks} simpleLinks={simpleLinks}
allowPreview={isStakeEnoughForPreview(stakedLevel)} allowPreview={isStakeEnoughForPreview(stakedLevel)}
setUserMention={setUserMention}
/> />
), ),
// Workaraund of remarkOptions.Fragment // Workaraund of remarkOptions.Fragment

View file

@ -45,6 +45,8 @@ function LivestreamComment(props: Props) {
isPinned, isPinned,
} = props; } = props;
const [hasUserMention, setUserMention] = React.useState(false);
const commentByOwnerOfContent = claim && claim.signing_channel && claim.signing_channel.permanent_url === authorUri; const commentByOwnerOfContent = claim && claim.signing_channel && claim.signing_channel.permanent_url === authorUri;
const { claimName } = parseURI(authorUri); const { claimName } = parseURI(authorUri);
const stickerFromMessage = parseSticker(message); const stickerFromMessage = parseSticker(message);
@ -54,6 +56,7 @@ function LivestreamComment(props: Props) {
className={classnames('livestream-comment', { className={classnames('livestream-comment', {
'livestream-comment--superchat': supportAmount > 0, 'livestream-comment--superchat': supportAmount > 0,
'livestream-comment--sticker': Boolean(stickerFromMessage), 'livestream-comment--sticker': Boolean(stickerFromMessage),
'livestream-comment--mentioned': hasUserMention,
})} })}
> >
{supportAmount > 0 && ( {supportAmount > 0 && (
@ -117,7 +120,13 @@ function LivestreamComment(props: Props) {
</div> </div>
) : ( ) : (
<div className="livestream-comment__text"> <div className="livestream-comment__text">
<MarkdownPreview content={message} promptLinks stakedLevel={stakedLevel} disableTimestamps /> <MarkdownPreview
content={message}
promptLinks
stakedLevel={stakedLevel}
disableTimestamps
setUserMention={setUserMention}
/>
</div> </div>
)} )}
</div> </div>

View file

@ -1,8 +1,12 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { doOpenModal } from 'redux/actions/app'; import { doOpenModal } from 'redux/actions/app';
import { selectMyChannelUrls } from 'redux/selectors/claims';
import MarkdownLink from './view'; import MarkdownLink from './view';
const select = () => ({}); const select = (state, props) => ({
myChannelUrls: selectMyChannelUrls(state),
});
const perform = (dispatch) => ({ const perform = (dispatch) => ({
openModal: (modal, props) => dispatch(doOpenModal(modal, props)), openModal: (modal, props) => dispatch(doOpenModal(modal, props)),
}); });

View file

@ -15,6 +15,8 @@ type Props = {
parentCommentId?: string, parentCommentId?: string,
isMarkdownPost?: boolean, isMarkdownPost?: boolean,
simpleLinks?: boolean, simpleLinks?: boolean,
myChannelUrls: ?Array<string>,
setUserMention?: (boolean) => void,
}; };
function MarkdownLink(props: Props) { function MarkdownLink(props: Props) {
@ -27,6 +29,8 @@ function MarkdownLink(props: Props) {
parentCommentId, parentCommentId,
isMarkdownPost, isMarkdownPost,
simpleLinks = false, simpleLinks = false,
myChannelUrls,
setUserMention,
} = props; } = props;
let decodedUri; let decodedUri;
@ -34,15 +38,20 @@ function MarkdownLink(props: Props) {
decodedUri = decodeURI(href); decodedUri = decodeURI(href);
} catch (e) {} } catch (e) {}
if (!href || !decodedUri) {
return children || null;
}
let element = <span>{children}</span>; let element = <span>{children}</span>;
// Regex for url protocol // Regex for url protocol
const protocolRegex = new RegExp('^(https?|lbry|mailto)+:', 'i'); const protocolRegex = new RegExp('^(https?|lbry|mailto)+:', 'i');
const protocol = href ? protocolRegex.exec(href) : null; 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; let linkUrlObject;
try { try {

View file

@ -104,6 +104,10 @@ $recent-msg-button__height: 2rem;
} }
} }
.livestream-comment--mentioned {
background-color: var(--color-card-background-highlighted);
}
.livestream-comment__info { .livestream-comment__info {
overflow: hidden; overflow: hidden;
} }