Fix message parser

This commit is contained in:
Gerzon Z 2021-08-02 16:37:50 -04:00
parent c95c2089fb
commit be431179e7
6 changed files with 50 additions and 31 deletions

View File

@ -68,6 +68,7 @@ const parser = new Parser();
class Markdown extends PureComponent { class Markdown extends PureComponent {
static propTypes = { static propTypes = {
msg: PropTypes.string, msg: PropTypes.string,
md: PropTypes.string,
getCustomEmoji: PropTypes.func, getCustomEmoji: PropTypes.func,
baseUrl: PropTypes.string, baseUrl: PropTypes.string,
username: PropTypes.string, username: PropTypes.string,

View File

@ -48,6 +48,7 @@ const Content = React.memo((props) => {
const { baseUrl, user, onLinkPress } = useContext(MessageContext); const { baseUrl, user, onLinkPress } = useContext(MessageContext);
content = ( content = (
<Markdown <Markdown
md={props.md}
msg={props.msg} msg={props.msg}
baseUrl={baseUrl} baseUrl={baseUrl}
getCustomEmoji={props.getCustomEmoji} getCustomEmoji={props.getCustomEmoji}
@ -124,6 +125,7 @@ Content.propTypes = {
tmid: PropTypes.string, tmid: PropTypes.string,
isThreadRoom: PropTypes.bool, isThreadRoom: PropTypes.bool,
msg: PropTypes.string, msg: PropTypes.string,
md: PropTypes.string,
theme: PropTypes.string, theme: PropTypes.string,
isEdited: PropTypes.bool, isEdited: PropTypes.bool,
isEncrypted: PropTypes.bool, isEncrypted: PropTypes.bool,

View File

@ -341,7 +341,8 @@ class MessageContainer extends React.Component {
unread, unread,
blocks, blocks,
autoTranslate: autoTranslateMessage, autoTranslate: autoTranslateMessage,
replies replies,
md
} = item; } = item;
let message = msg; let message = msg;
@ -375,6 +376,7 @@ class MessageContainer extends React.Component {
<Message <Message
id={id} id={id}
msg={message} msg={message}
md={md}
rid={rid} rid={rid}
author={u} author={u}
ts={ts} ts={ts}

View File

@ -220,7 +220,7 @@
"email": "e-mail", "email": "e-mail",
"Empty_title": "Empty title", "Empty_title": "Empty title",
"Enable_Auto_Translate": "Enable Auto-Translate", "Enable_Auto_Translate": "Enable Auto-Translate",
"Enable_Message_Parser_Early_Adoption": "Enable message parser early adoption", "Enable_Message_Parser": "Enable message parser",
"Enable_notifications": "Enable notifications", "Enable_notifications": "Enable notifications",
"Encrypted": "Encrypted", "Encrypted": "Encrypted",
"Encrypted_message": "Encrypted message", "Encrypted_message": "Encrypted message",

View File

@ -616,7 +616,8 @@ const RocketChat = {
roles: result.me.roles, roles: result.me.roles,
avatarETag: result.me.avatarETag, avatarETag: result.me.avatarETag,
isFromWebView, isFromWebView,
showMessageInMainThread: result.me.settings?.preferences?.showMessageInMainThread ?? true showMessageInMainThread: result.me.settings?.preferences?.showMessageInMainThread ?? true,
enableMessageParserEarlyAdoption: result.me.settings?.preferences?.enableMessageParserEarlyAdoption ?? true
}; };
return user; return user;
}, },

View File

@ -1,6 +1,8 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { View, ScrollView, Keyboard } from 'react-native'; import {
View, ScrollView, Keyboard, Switch
} from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import prompt from 'react-native-prompt-android'; import prompt from 'react-native-prompt-android';
import SHA256 from 'js-sha256'; import SHA256 from 'js-sha256';
@ -19,6 +21,7 @@ import { LISTENER } from '../../containers/Toast';
import EventEmitter from '../../utils/events'; import EventEmitter from '../../utils/events';
import RocketChat from '../../lib/rocketchat'; import RocketChat from '../../lib/rocketchat';
import RCTextInput from '../../containers/TextInput'; import RCTextInput from '../../containers/TextInput';
import * as List from '../../containers/List';
import log, { logEvent, events } from '../../utils/log'; import log, { logEvent, events } from '../../utils/log';
import I18n from '../../i18n'; import I18n from '../../i18n';
import Button from '../../containers/Button'; import Button from '../../containers/Button';
@ -27,11 +30,10 @@ import { setUser as setUserAction } from '../../actions/login';
import { CustomIcon } from '../../lib/Icons'; import { CustomIcon } from '../../lib/Icons';
import * as HeaderButton from '../../containers/HeaderButton'; import * as HeaderButton from '../../containers/HeaderButton';
import StatusBar from '../../containers/StatusBar'; import StatusBar from '../../containers/StatusBar';
import { themes } from '../../constants/colors'; import { SWITCH_TRACK_COLOR, themes } from '../../constants/colors';
import { withTheme } from '../../theme'; import { withTheme } from '../../theme';
import { getUserSelector } from '../../selectors/login'; import { getUserSelector } from '../../selectors/login';
import SafeAreaView from '../../containers/SafeAreaView'; import SafeAreaView from '../../containers/SafeAreaView';
import SwitchContainer from '../RoomInfoEditView/SwitchContainer';
class ProfileView extends React.Component { class ProfileView extends React.Component {
static navigationOptions = ({ navigation, isMasterDetail }) => { static navigationOptions = ({ navigation, isMasterDetail }) => {
@ -63,7 +65,7 @@ class ProfileView extends React.Component {
state = { state = {
saving: false, saving: false,
enableMessageParserEarlyAdoption: false, enableMessageParser: false,
name: null, name: null,
username: null, username: null,
email: null, email: null,
@ -72,7 +74,8 @@ class ProfileView extends React.Component {
avatarUrl: null, avatarUrl: null,
avatar: {}, avatar: {},
avatarSuggestions: {}, avatarSuggestions: {},
customFields: {} customFields: {},
preferences: []
}; };
async componentDidMount() { async componentDidMount() {
@ -109,12 +112,15 @@ class ProfileView extends React.Component {
this.setState({ avatar }); this.setState({ avatar });
} }
init = (user) => { init = async(user) => {
const { user: userProps } = this.props; const { user: userProps } = this.props;
const { const {
name, username, emails, customFields, enableMessageParserEarlyAdoption name, username, emails, customFields, id
} = user || userProps; } = user || userProps;
const result = await RocketChat.getUserPreferences(id);
const { preferences } = result;
this.setState({ this.setState({
name, name,
username, username,
@ -124,13 +130,14 @@ class ProfileView extends React.Component {
avatarUrl: null, avatarUrl: null,
avatar: {}, avatar: {},
customFields: customFields || {}, customFields: customFields || {},
enableMessageParserEarlyAdoption enableMessageParser: preferences?.enableMessageParserEarlyAdoption || false,
preferences
}); });
} }
formIsChanged = () => { formIsChanged = () => {
const { const {
name, username, email, newPassword, avatar, customFields, enableMessageParserEarlyAdoption name, username, email, newPassword, avatar, customFields, enableMessageParser, preferences
} = this.state; } = this.state;
const { user } = this.props; const { user } = this.props;
let customFieldsChanged = false; let customFieldsChanged = false;
@ -146,7 +153,7 @@ class ProfileView extends React.Component {
return !(user.name === name return !(user.name === name
&& user.username === username && user.username === username
&& user.enableMessageParserEarlyAdoption === enableMessageParserEarlyAdoption && preferences.enableMessageParserEarlyAdoption === enableMessageParser
&& !newPassword && !newPassword
&& (user.emails && user.emails[0].address === email) && (user.emails && user.emails[0].address === email)
&& !avatar.data && !avatar.data
@ -171,7 +178,7 @@ class ProfileView extends React.Component {
this.setState({ saving: true }); this.setState({ saving: true });
const { const {
name, username, email, newPassword, currentPassword, avatar, customFields, enableMessageParserEarlyAdoption name, username, email, newPassword, currentPassword, avatar, customFields
} = this.state; } = this.state;
const { user, setUser } = this.props; const { user, setUser } = this.props;
const params = {}; const params = {};
@ -201,11 +208,6 @@ class ProfileView extends React.Component {
params.currentPassword = SHA256(currentPassword); params.currentPassword = SHA256(currentPassword);
} }
// MessageParser
if (user.enableMessageParserEarlyAdoption !== enableMessageParserEarlyAdoption) {
params.enableMessageParserEarlyAdoption = enableMessageParserEarlyAdoption;
}
const requirePassword = !!params.email || newPassword; const requirePassword = !!params.email || newPassword;
if (requirePassword && !params.currentPassword) { if (requirePassword && !params.currentPassword) {
this.setState({ saving: false }); this.setState({ saving: false });
@ -433,7 +435,18 @@ class ProfileView extends React.Component {
} }
} }
toggleEnableMessageParserEarlyAdoption = (value) => { renderMessageParserSwitch = () => {
const { enableMessageParser } = this.state;
return (
<Switch
value={enableMessageParser}
trackColor={SWITCH_TRACK_COLOR}
onValueChange={this.toggleEnableMessageParser}
/>
);
}
toggleEnableMessageParser = (value) => {
// logEvent(events.RI_EDIT_TOGGLE_SYSTEM_MSG); // logEvent(events.RI_EDIT_TOGGLE_SYSTEM_MSG);
this.setState({ enableMessageParser: value }); this.setState({ enableMessageParser: value });
} }
@ -457,7 +470,7 @@ class ProfileView extends React.Component {
render() { render() {
const { const {
name, username, email, newPassword, avatarUrl, customFields, avatar, saving, enableMessageParser name, username, email, newPassword, avatarUrl, customFields, avatar, saving
} = this.state; } = this.state;
const { const {
user, user,
@ -554,16 +567,16 @@ class ProfileView extends React.Component {
testID='profile-view-new-password' testID='profile-view-new-password'
theme={theme} theme={theme}
/> />
<SwitchContainer <List.Separator />
value={enableMessageParser} {Accounts_enableMessageParserEarlyAdoption
leftLabelPrimary={I18n.t('Enable_Message_Parser_Early_Adoption')} ? (
// leftLabelSecondary={Accounts_enableMessageParserEarlyAdoption ? I18n.t('Overwrites_the_server_configuration_and_use_room_config') : I18n.t('Uses_server_configuration')} <List.Item
theme={theme} title='Enable_Message_Parser'
testID='profile-switch-message-parser-early-adoption' testID='profile-view-enable-message-parser'
onValueChange={value => this.setState({ enableMessageParser: value })} right={() => this.renderMessageParserSwitch()}
labelContainerStyle={styles.hideSystemMessages}
leftLabelStyle={styles.systemMessagesLabel}
/> />
) : null}
<List.Separator />
{this.renderCustomFields()} {this.renderCustomFields()}
<RCTextInput <RCTextInput
editable={Accounts_AllowUserAvatarChange} editable={Accounts_AllowUserAvatarChange}