fix: render channel links in threads list (#8205)

fixes: https://github.com/mattermost/mattermost/issues/27859

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Abdullahi Abass 2024-10-11 07:55:24 +01:00 committed by GitHub
parent e693431dec
commit 7dcb6ad4ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 3 deletions

View file

@ -9,21 +9,24 @@ import {type StyleProp, Text, type TextStyle} from 'react-native';
import Emoji from '@components/emoji';
import {computeTextStyle} from '@utils/markdown';
import ChannelMention from '../markdown/channel_mention';
import AtMention from './at_mention';
import type {MarkdownBaseRenderer, MarkdownEmojiRenderer, MarkdownTextStyles} from '@typings/global/markdown';
import type {MarkdownBaseRenderer, MarkdownChannelMentionRenderer, MarkdownEmojiRenderer, MarkdownTextStyles} from '@typings/global/markdown';
type Props = {
enableEmoji?: boolean;
enableCodeSpan?: boolean;
enableHardBreak?: boolean;
enableSoftBreak?: boolean;
enableChannelLink?: boolean;
baseStyle?: StyleProp<TextStyle>;
textStyle?: MarkdownTextStyles;
value: string;
};
const RemoveMarkdown = ({enableEmoji, enableHardBreak, enableSoftBreak, enableCodeSpan, baseStyle, textStyle = {}, value}: Props) => {
const RemoveMarkdown = ({enableEmoji, enableChannelLink, enableHardBreak, enableSoftBreak, enableCodeSpan, baseStyle, textStyle = {}, value}: Props) => {
const renderEmoji = useCallback(({emojiName, literal}: MarkdownEmojiRenderer) => {
if (!enableEmoji) {
return renderText({literal});
@ -56,6 +59,16 @@ const RemoveMarkdown = ({enableEmoji, enableHardBreak, enableSoftBreak, enableCo
);
};
const renderChannelLink = ({context, channelName}: MarkdownChannelMentionRenderer) => {
return (
<ChannelMention
linkStyle={textStyle.link}
textStyle={computeTextStyle(textStyle, [], context)}
channelName={channelName}
/>
);
};
const renderCodeSpan = useCallback(({context, literal}: MarkdownBaseRenderer) => {
if (!enableCodeSpan) {
return renderText({literal});
@ -88,7 +101,7 @@ const RemoveMarkdown = ({enableEmoji, enableHardBreak, enableSoftBreak, enableCo
link: Renderer.forwardChildren,
image: renderNull,
atMention: renderAtMention,
channelLink: Renderer.forwardChildren,
channelLink: enableChannelLink ? renderChannelLink : Renderer.forwardChildren,
emoji: renderEmoji,
hashtag: Renderer.forwardChildren,
latexinline: Renderer.forwardChildren,

View file

@ -219,6 +219,7 @@ const Thread = ({author, channel, location, post, teammateNameDisplay, testID, t
<RemoveMarkdown
enableCodeSpan={true}
enableEmoji={true}
enableChannelLink={true}
enableHardBreak={true}
enableSoftBreak={true}
textStyle={textStyles}