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 {
static propTypes = {
msg: PropTypes.string,
md: PropTypes.string,
getCustomEmoji: PropTypes.func,
baseUrl: PropTypes.string,
username: PropTypes.string,

View File

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

View File

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

View File

@ -220,7 +220,7 @@
"email": "e-mail",
"Empty_title": "Empty title",
"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",
"Encrypted": "Encrypted",
"Encrypted_message": "Encrypted message",

View File

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

View File

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