diff --git a/app/containers/markdown/MessageBody/Code.js b/app/containers/markdown/MessageBody/Code.js index 3e8414f81..2d93c429c 100644 --- a/app/containers/markdown/MessageBody/Code.js +++ b/app/containers/markdown/MessageBody/Code.js @@ -1,18 +1,24 @@ +/* eslint-disable react/no-array-index-key */ import React from 'react'; import { Text } from 'react-native'; import PropTypes from 'prop-types'; + +import CodeLine from './CodeLine'; +import styles from '../styles'; + import { themes } from '../../../constants/colors'; import { useTheme } from '../../../theme'; const Code = ({ - type, styles, style, literal + value, style }) => { - const theme = useTheme(); + const { theme } = useTheme(); + return ( - {literal} + {value.map((block, index) => { + switch (block.type) { + case 'CODE_LINE': + return ; + default: + return null; + } + })} ); }; Code.propTypes = { - type: PropTypes.string, - literal: PropTypes.string, - styles: PropTypes.object, + value: PropTypes.array, style: PropTypes.object }; diff --git a/app/containers/markdown/MessageBody/CodeLine.js b/app/containers/markdown/MessageBody/CodeLine.js new file mode 100644 index 000000000..15c74c6c5 --- /dev/null +++ b/app/containers/markdown/MessageBody/CodeLine.js @@ -0,0 +1,13 @@ +import React from 'react'; +import { Text } from 'react-native'; +import PropTypes from 'prop-types'; + +const CodeLine = ({ value }) => ( + {value.type === 'PLAIN_TEXT' && value.value} +); + +CodeLine.propTypes = { + value: PropTypes.object +}; + +export default CodeLine; diff --git a/app/containers/markdown/MessageBody/Inline.js b/app/containers/markdown/MessageBody/Inline.js index ca84f4cfe..ade8eb2a1 100644 --- a/app/containers/markdown/MessageBody/Inline.js +++ b/app/containers/markdown/MessageBody/Inline.js @@ -4,13 +4,16 @@ import PropTypes from 'prop-types'; import Link from './Link'; import Plain from './Plain'; -import Code from './Code'; import Bold from './Bold'; import Strike from './Strike'; import Italic from './Italic'; import Emoji from './Emoji'; +import Mention from './Mention'; +import InlineCode from './InlineCode'; -const Inline = ({ value }) => ( +const Inline = ({ + value, mentions, navToRoomInfo, style +}) => ( {value.map((block) => { switch (block.type) { @@ -25,15 +28,15 @@ const Inline = ({ value }) => ( case 'LINK': // eslint-disable-next-line jsx-a11y/anchor-is-valid return ; - // case 'MENTION_USER': - // return ; + case 'MENTION_USER': + return ; case 'EMOJI': return ; - // case 'MENTION_CHANNEL': - // // case 'COLOR': - // return ; + case 'MENTION_CHANNEL': + // case 'COLOR': + return ; case 'INLINE_CODE': - return ; + return ; default: return null; } @@ -42,7 +45,10 @@ const Inline = ({ value }) => ( ); Inline.propTypes = { - value: PropTypes.object + value: PropTypes.object, + mentions: PropTypes.array, + navToRoomInfo: PropTypes.func, + style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]) }; export default Inline; diff --git a/app/containers/markdown/MessageBody/InlineCode.js b/app/containers/markdown/MessageBody/InlineCode.js new file mode 100644 index 000000000..913eb45a0 --- /dev/null +++ b/app/containers/markdown/MessageBody/InlineCode.js @@ -0,0 +1,40 @@ +import React from 'react'; +import { Text } from 'react-native'; +import PropTypes from 'prop-types'; +import { useTheme } from '@react-navigation/native'; + +import styles from '../styles'; +import { themes } from '../../../constants/colors'; + +const InlineCode = ({ value, style }) => { + const { theme } = useTheme(); + + return ( + + {((block) => { + switch (block.type) { + case 'PLAIN_TEXT': + return block.value; + default: + return null; + } + })(value)} + + ); +}; + +InlineCode.propTypes = { + value: PropTypes.object, + style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]) +}; + +export default InlineCode; diff --git a/app/containers/markdown/MessageBody/Link.js b/app/containers/markdown/MessageBody/Link.js index 07b49b9e3..1e83cd9d0 100644 --- a/app/containers/markdown/MessageBody/Link.js +++ b/app/containers/markdown/MessageBody/Link.js @@ -32,7 +32,6 @@ const Link = ({ value }) => { {((block) => { diff --git a/app/containers/markdown/MessageBody/Mention.js b/app/containers/markdown/MessageBody/Mention.js new file mode 100644 index 000000000..1906eed41 --- /dev/null +++ b/app/containers/markdown/MessageBody/Mention.js @@ -0,0 +1,63 @@ +import React from 'react'; +import { Text } from 'react-native'; +import PropTypes from 'prop-types'; + +import styles from '../styles'; +import { events, logEvent } from '../../../utils/log'; +import { useTheme } from '../../../theme'; +import { themes } from '../../../constants/colors'; + +const Mention = ({ + value: mention, mentions, navToRoomInfo, style +}) => { + const { theme } = useTheme(); + let mentionStyle = []; + const notMentionedStyle = [styles.text, { color: themes[theme].bodyText }, ...style]; + const mentionedUser = mentions.find(mentioned => mentioned.username === mention.value); + + if (mention === 'all' || mention === 'here') { + mentionStyle = [ + { + color: themes[theme].mentionGroupColor + }, + ...style + ]; + } + + if (mention === mentionedUser) { + mentionStyle = { + color: themes[theme].mentionMeColor + }; + } else { + mentionStyle = { + color: themes[theme].mentionOtherColor + }; + } + + const handlePress = () => { + logEvent(events.ROOM_MENTION_GO_USER_INFO); + const navParam = { + t: 'd', + rid: mentionedUser && mentionedUser._id + }; + navToRoomInfo(navParam); + }; + + return ( + + {mentionedUser ? mentionedUser.name || mention.value : `@{${ mention }}` } + + ); +}; + +Mention.propTypes = { + value: PropTypes.string, + mentions: PropTypes.array, + navToRoomInfo: PropTypes.func, + style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]) +}; + +export default Mention; diff --git a/app/containers/markdown/MessageBody/Paragraph.js b/app/containers/markdown/MessageBody/Paragraph.js index f73d1f76e..2d43c696e 100644 --- a/app/containers/markdown/MessageBody/Paragraph.js +++ b/app/containers/markdown/MessageBody/Paragraph.js @@ -3,11 +3,15 @@ import PropTypes from 'prop-types'; import Inline from './Inline'; -const Paragraph = ({ value, mentions }) => ; +const Paragraph = ({ + value, mentions, navToRoomInfo, style +}) => ; Paragraph.propTypes = { value: PropTypes.string, - mentions: PropTypes.string + mentions: PropTypes.string, + navToRoomInfo: PropTypes.func, + style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]) }; export default Paragraph; diff --git a/app/containers/markdown/MessageBody/Quote.js b/app/containers/markdown/MessageBody/Quote.js index 8f9f9fe02..934c63625 100644 --- a/app/containers/markdown/MessageBody/Quote.js +++ b/app/containers/markdown/MessageBody/Quote.js @@ -6,7 +6,7 @@ import { useTheme } from '../../../theme'; import styles from '../styles'; const Quote = ({ value }) => { - const theme = useTheme(); + const { theme } = useTheme(); return ( <> diff --git a/app/containers/markdown/MessageBody/index.js b/app/containers/markdown/MessageBody/index.js index 37aa53d1d..7880bd30f 100644 --- a/app/containers/markdown/MessageBody/index.js +++ b/app/containers/markdown/MessageBody/index.js @@ -9,14 +9,14 @@ import Heading from './Heading'; import Code from './Code'; import Link from './Link'; import BigEmoji from './BigEmoji'; -import { useTheme } from '../../../theme'; const isBigEmoji = tokens => tokens.length === 1 && tokens[0].type === 'BIG_EMOJI'; -const Body = ({ tokens, mentions }) => { - const { theme } = useTheme(); +const Body = ({ + tokens, mentions, navToRoomInfo, style +}) => { if (isBigEmoji(tokens)) { - return ; + return ; } return ( @@ -32,9 +32,9 @@ const Body = ({ tokens, mentions }) => { case 'QUOTE': return ; case 'PARAGRAPH': - return ; + return ; case 'CODE': - return ; + return ; case 'LINK': // eslint-disable-next-line jsx-a11y/anchor-is-valid return ; @@ -50,7 +50,9 @@ const Body = ({ tokens, mentions }) => { Body.propTypes = { tokens: PropTypes.array, - mentions: PropTypes.array + mentions: PropTypes.array, + navToRoomInfo: PropTypes.func, + style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]) }; export default Body; diff --git a/app/containers/markdown/index.js b/app/containers/markdown/index.js index c74e0d972..c4dd54d1b 100644 --- a/app/containers/markdown/index.js +++ b/app/containers/markdown/index.js @@ -376,7 +376,7 @@ class Markdown extends PureComponent { render() { const { - msg, md, numberOfLines, preview = false, theme, style = [], testID, user, mentions + msg, md, numberOfLines, preview = false, theme, style = [], testID, user, mentions, navToRoomInfo } = this.props; if (!msg) { @@ -384,7 +384,7 @@ class Markdown extends PureComponent { } if (user.enableMessageParserEarlyAdoption && md) { - return ; + return ; } let m = formatText(msg);