Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
1cd297c
Add message parser to profile view and db
gerzonc Jul 29, 2021
7ec40a1
Add md to db
gerzonc Jul 29, 2021
f779a0a
Remove changes to Xcode project
gerzonc Jul 29, 2021
c95c208
Remove message-parser lib and add enable message parser field to User…
gerzonc Jul 30, 2021
be43117
Fix message parser
gerzonc Aug 2, 2021
56ee8d4
Remove admin enableMessageParserEarlyAdoption
gerzonc Aug 3, 2021
332a4eb
Add NewMarkdown component
gerzonc Aug 3, 2021
559f804
Remove NewMarkdown component and add specific components for new mess…
gerzonc Aug 3, 2021
ff9b0fe
Add new parser components
gerzonc Aug 12, 2021
1e7bb87
Fix BigEmoji
gerzonc Aug 12, 2021
71aed0c
Updated components and added more Code components
gerzonc Aug 14, 2021
c2dd2db
update components and add storybooks
gerzonc Aug 20, 2021
68e2fb1
Merge branch 'develop' into new.support-new-message-parser
gerzonc Aug 20, 2021
8f26301
Update Code component and add it to storybooks
gerzonc Aug 21, 2021
d7c0b4c
Merge branch 'new.support-new-message-parser' of https://github.com/R…
gerzonc Aug 21, 2021
d4c3322
Update Mention component
gerzonc Aug 21, 2021
06b3da0
Minor tweaks
gerzonc Aug 21, 2021
81c0d32
Merge branch 'develop' into new.support-new-message-parser
gerzonc Aug 21, 2021
73f4e81
Add server message parser validation
gerzonc Aug 23, 2021
3c7ad9a
Merge branch 'develop' into new.support-new-message-parser
diegolmello Sep 6, 2021
7a88d8d
Merge branch 'develop' into new.support-new-message-parser
gerzonc Sep 21, 2021
20d2db9
Renamed folder, add @rocket.chat/message-parser, migrate some files t…
gerzonc Sep 21, 2021
5edbfe6
Migrate components to TypeScript and fix styling
gerzonc Sep 22, 2021
e27ffd7
Merge branch 'develop' into new.support-new-message-parser
gerzonc Sep 22, 2021
ddfdba4
Merge branch 'develop' into new.support-new-message-parser
gerzonc Sep 23, 2021
4895fd2
Change interfaces and add TaskListComponent and styles
gerzonc Sep 23, 2021
47eeadc
Merge branch 'develop' into new.support-new-message-parser
gerzonc Sep 23, 2021
417ea35
Fix new markdown and styles
gerzonc Sep 27, 2021
4418a5e
Merge branch 'develop' into new.support-new-message-parser
gerzonc Sep 28, 2021
ede741c
Merge branch 'develop' into new.support-new-message-parser
diegolmello Oct 7, 2021
8a748a7
Fix inlinecode
diegolmello Oct 8, 2021
a1ecc26
Stop using server setting
diegolmello Oct 8, 2021
968445d
Use enableMessageParserEarlyAdoption on mapStateToProps
diegolmello Oct 8, 2021
9acac29
Remove React.FC
gerzonc Oct 14, 2021
36421c9
Merge branch 'develop' into new.support-new-message-parser
gerzonc Oct 15, 2021
2960277
add link to bold, italic and strike
gerzonc Oct 15, 2021
81fe382
Update parser components
gerzonc Oct 19, 2021
397e9c9
Fix missing components
gerzonc Oct 19, 2021
2b970ff
Minor tweak
gerzonc Oct 19, 2021
49af50f
Fix lint and add getCustomEmojis
gerzonc Oct 19, 2021
4115d19
Fix customEmojis
gerzonc Oct 19, 2021
338ffe4
Update emojis
gerzonc Oct 19, 2021
0243fdc
Minor tweak
gerzonc Oct 19, 2021
5fde513
disconnect markdown from store
gerzonc Oct 19, 2021
94739c9
Use @rocket.chat/message-parser@0.30.0
diegolmello Oct 19, 2021
640f96d
Fix link style
diegolmello Oct 19, 2021
a4ce209
Unify lists and styles
diegolmello Oct 19, 2021
f1357bc
Remove style prop
diegolmello Oct 19, 2021
0c7dda5
Use big emoji as a normal token
diegolmello Oct 19, 2021
60d079f
Remove unnecessary memo
diegolmello Oct 19, 2021
631e633
Fix code styles
diegolmello Oct 19, 2021
96c3c41
Update tests
diegolmello Oct 19, 2021
e66bb5b
Conditionally create renderer
diegolmello Oct 19, 2021
56eddf7
Use Context instead of prop drill
diegolmello Oct 20, 2021
d22344b
Fix Link component
diegolmello Oct 20, 2021
82b4ad7
Fix plain text regression and update tests
diegolmello Oct 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,380 changes: 1,380 additions & 0 deletions __tests__/__snapshots__/Storyshots.test.js.snap

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions app/containers/markdown/AtMention.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Text } from 'react-native';

import { useTheme } from '../../theme';
import { themes } from '../../constants/colors';
import styles from './styles';
import { events, logEvent } from '../../utils/log';
Expand All @@ -9,20 +10,20 @@ interface IAtMention {
mention: string;
username: string;
navToRoomInfo: Function;
style: any;
style?: any;
useRealName: boolean;
theme: string;
mentions: any;
}

const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, style = [], useRealName, theme }: IAtMention) => {
const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, style = [], useRealName }: IAtMention) => {
const { theme } = useTheme();
if (mention === 'all' || mention === 'here') {
return (
<Text
style={[
styles.mention,
{
color: themes[theme].mentionGroupColor
color: themes[theme!].mentionGroupColor
},
...style
]}>
Expand All @@ -34,11 +35,11 @@ const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, styl
let mentionStyle = {};
if (mention === username) {
mentionStyle = {
color: themes[theme].mentionMeColor
color: themes[theme!].mentionMeColor
};
} else {
mentionStyle = {
color: themes[theme].mentionOtherColor
color: themes[theme!].mentionOtherColor
};
}

Expand All @@ -61,7 +62,7 @@ const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, styl
);
}

return <Text style={[styles.text, { color: themes[theme].bodyText }, ...style]}>{`@${mention}`}</Text>;
return <Text style={[styles.text, { color: themes[theme!].bodyText }, ...style]}>{`@${mention}`}</Text>;
});

export default AtMention;
17 changes: 10 additions & 7 deletions app/containers/markdown/Hashtag.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import React from 'react';
import { Text } from 'react-native';
import { Text, TextStyle } from 'react-native';

import { themes } from '../../constants/colors';
import { useTheme } from '../../theme';
import styles from './styles';

interface IHashtag {
hashtag: string;
navToRoomInfo: Function;
style: [];
theme: string;
style?: TextStyle[];
channels: {
[index: number]: string | number;
name: string;
_id: number;
}[];
}

const Hashtag = React.memo(({ hashtag, channels, navToRoomInfo, style = [], theme }: IHashtag) => {
const Hashtag = React.memo(({ hashtag, channels, navToRoomInfo, style = [] }: IHashtag) => {
const { theme } = useTheme();

const handlePress = () => {
const index = channels.findIndex(channel => channel.name === hashtag);
const index = channels?.findIndex(channel => channel.name === hashtag);
const navParam = {
t: 'c',
rid: channels[index]._id
Expand All @@ -31,7 +34,7 @@ const Hashtag = React.memo(({ hashtag, channels, navToRoomInfo, style = [], them
style={[
styles.mention,
{
color: themes[theme].mentionOtherColor
color: themes[theme!].mentionOtherColor
},
...style
]}
Expand All @@ -40,7 +43,7 @@ const Hashtag = React.memo(({ hashtag, channels, navToRoomInfo, style = [], them
</Text>
);
}
return <Text style={[styles.text, { color: themes[theme].bodyText }, ...style]}>{`#${hashtag}`}</Text>;
return <Text style={[styles.text, { color: themes[theme!].bodyText }, ...style]}>{`#${hashtag}`}</Text>;
});

export default Hashtag;
64 changes: 57 additions & 7 deletions app/containers/markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Image, Text } from 'react-native';
import { Node, Parser } from 'commonmark';
import Renderer from 'commonmark-react-renderer';
import removeMarkdown from 'remove-markdown';
import { MarkdownAST } from '@rocket.chat/message-parser';

import shortnameToUnicode from '../../utils/shortnameToUnicode';
import I18n from '../../i18n';
Expand All @@ -20,9 +21,20 @@ import MarkdownTableCell from './TableCell';
import mergeTextNodes from './mergeTextNodes';
import styles from './styles';
import { isValidURL } from '../../utils/url';
import NewMarkdown from './new';

interface IUser {
_id: string;
username: string;
name: string;
}

type UserMention = Pick<IUser, '_id' | 'username' | 'name'>;

interface IMarkdownProps {
msg: string;
md: MarkdownAST;
mentions: UserMention[];
getCustomEmoji: Function;
baseUrl: string;
username: string;
Expand All @@ -35,7 +47,7 @@ interface IMarkdownProps {
name: string;
_id: number;
}[];
mentions: object[];
enableMessageParser: boolean;
navToRoomInfo: Function;
preview: boolean;
theme: string;
Expand Down Expand Up @@ -97,7 +109,9 @@ class Markdown extends PureComponent<IMarkdownProps, any> {

constructor(props: IMarkdownProps) {
super(props);
this.renderer = this.createRenderer();
if (!this.isNewMarkdown) {
this.renderer = this.createRenderer();
}
}

createRenderer = () =>
Expand Down Expand Up @@ -139,6 +153,11 @@ class Markdown extends PureComponent<IMarkdownProps, any> {
renderParagraphsInLists: true
});

get isNewMarkdown(): boolean {
const { md, enableMessageParser } = this.props;
return enableMessageParser && !!md;
}

editedMessage = (ast: any) => {
const { isEdited } = this.props;
if (isEdited) {
Expand Down Expand Up @@ -227,20 +246,19 @@ class Markdown extends PureComponent<IMarkdownProps, any> {
};

renderHashtag = ({ hashtag }: { hashtag: string }) => {
const { channels, navToRoomInfo, style, theme } = this.props;
return <MarkdownHashtag hashtag={hashtag} channels={channels} navToRoomInfo={navToRoomInfo} theme={theme} style={style} />;
const { channels, navToRoomInfo, style } = this.props;
return <MarkdownHashtag hashtag={hashtag} channels={channels} navToRoomInfo={navToRoomInfo} style={style} />;
};

renderAtMention = ({ mentionName }: { mentionName: string }) => {
const { username, mentions, navToRoomInfo, useRealName, style, theme } = this.props;
const { username, mentions, navToRoomInfo, useRealName, style } = this.props;
return (
<MarkdownAtMention
mentions={mentions}
mention={mentionName}
useRealName={useRealName}
username={username}
navToRoomInfo={navToRoomInfo}
theme={theme}
style={style}
/>
);
Expand Down Expand Up @@ -329,12 +347,44 @@ class Markdown extends PureComponent<IMarkdownProps, any> {
};

render() {
const { msg, numberOfLines, preview = false, theme, style = [], testID } = this.props;
const {
msg,
md,
numberOfLines,
preview = false,
theme,
style = [],
testID,
mentions,
channels,
navToRoomInfo,
useRealName,
username,
getCustomEmoji,
baseUrl,
onLinkPress
} = this.props;

if (!msg) {
return null;
}

if (this.isNewMarkdown) {
return (
<NewMarkdown
username={username}
baseUrl={baseUrl}
getCustomEmoji={getCustomEmoji}
useRealName={useRealName}
tokens={md}
mentions={mentions}
channels={channels}
navToRoomInfo={navToRoomInfo}
onLinkPress={onLinkPress}
/>
);
}

let m = formatText(msg);

// Ex: '[ ](https://open.rocket.chat/group/test?msg=abcdef) Test'
Expand Down
25 changes: 25 additions & 0 deletions app/containers/markdown/new/BigEmoji.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { BigEmoji as BigEmojiProps } from '@rocket.chat/message-parser';

import Emoji from './Emoji';

interface IBigEmojiProps {
value: BigEmojiProps['value'];
}

const styles = StyleSheet.create({
container: {
flexDirection: 'row'
}
});

const BigEmoji = ({ value }: IBigEmojiProps): JSX.Element => (
<View style={styles.container}>
{value.map(block => (
<Emoji value={block.value} isBigEmoji />
))}
</View>
);

export default BigEmoji;
40 changes: 40 additions & 0 deletions app/containers/markdown/new/Bold.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { StyleSheet, Text } from 'react-native';
import { Bold as BoldProps } from '@rocket.chat/message-parser';

import sharedStyles from '../../../views/Styles';
import Strike from './Strike';
import Italic from './Italic';
import Plain from './Plain';
import Link from './Link';

interface IBoldProps {
value: BoldProps['value'];
}

const styles = StyleSheet.create({
text: {
...sharedStyles.textBold
}
});

const Bold = ({ value }: IBoldProps): JSX.Element => (
<Text style={styles.text}>
{value.map(block => {
switch (block.type) {
case 'LINK':
return <Link value={block.value} />;
case 'PLAIN_TEXT':
return <Plain value={block.value} />;
case 'STRIKE':
return <Strike value={block.value} />;
case 'ITALIC':
return <Italic value={block.value} />;
default:
return null;
}
})}
</Text>
);

export default Bold;
39 changes: 39 additions & 0 deletions app/containers/markdown/new/Code.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import { Text } from 'react-native';
import { Code as CodeProps } from '@rocket.chat/message-parser';

import styles from '../styles';
import { themes } from '../../../constants/colors';
import { useTheme } from '../../../theme';
import CodeLine from './CodeLine';

interface ICodeProps {
value: CodeProps['value'];
}

const Code = ({ value }: ICodeProps): JSX.Element => {
const { theme } = useTheme();

return (
<Text
style={[
styles.codeBlock,
{
color: themes[theme!].bodyText,
backgroundColor: themes[theme!].bannerBackground,
borderColor: themes[theme!].borderColor
}
]}>
{value.map(block => {
switch (block.type) {
case 'CODE_LINE':
return <CodeLine value={block.value} />;
default:
return null;
}
})}
</Text>
);
};

export default Code;
17 changes: 17 additions & 0 deletions app/containers/markdown/new/CodeLine.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { Text } from 'react-native';
import { CodeLine as CodeLineProps } from '@rocket.chat/message-parser';

interface ICodeLineProps {
value: CodeLineProps['value'];
}

const CodeLine = ({ value }: ICodeLineProps): JSX.Element | null => {
if (value.type !== 'PLAIN_TEXT') {
return null;
}

return <Text>{value.value}</Text>;
};

export default CodeLine;
29 changes: 29 additions & 0 deletions app/containers/markdown/new/Emoji.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useContext } from 'react';
import { Text } from 'react-native';
import { Emoji as EmojiProps } from '@rocket.chat/message-parser';

import shortnameToUnicode from '../../../utils/shortnameToUnicode';
import { themes } from '../../../constants/colors';
import { useTheme } from '../../../theme';
import styles from '../styles';
import CustomEmoji from '../../EmojiPicker/CustomEmoji';
import MarkdownContext from './MarkdownContext';

interface IEmojiProps {
value: EmojiProps['value'];
isBigEmoji?: boolean;
}

const Emoji = ({ value, isBigEmoji }: IEmojiProps): JSX.Element => {
const { theme } = useTheme();
const { baseUrl, getCustomEmoji } = useContext(MarkdownContext);
const emojiUnicode = shortnameToUnicode(`:${value.value}:`);
const emoji = getCustomEmoji?.(value.value);

if (emoji) {
return <CustomEmoji baseUrl={baseUrl} style={[isBigEmoji ? styles.customEmojiBig : styles.customEmoji]} emoji={emoji} />;
}
return <Text style={[{ color: themes[theme!].bodyText }, isBigEmoji ? styles.textBig : styles.text]}>{emojiUnicode}</Text>;
};

export default Emoji;
Loading