From c95c2089fb8a661cd248a45f5fdf9a4da8e7cc8a Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Fri, 30 Jul 2021 14:24:05 -0400 Subject: [PATCH] Remove message-parser lib and add enable message parser field to User model --- app/constants/settings.js | 6 +-- app/lib/database/model/servers/User.js | 2 + app/lib/database/model/servers/migrations.js | 11 +++++ app/lib/database/schema/servers.js | 5 ++- app/views/ProfileView/index.js | 45 +++++++++++--------- package.json | 1 - yarn.lock | 5 --- 7 files changed, 43 insertions(+), 32 deletions(-) diff --git a/app/constants/settings.js b/app/constants/settings.js index 312487ebe..8c0d55779 100644 --- a/app/constants/settings.js +++ b/app/constants/settings.js @@ -26,6 +26,9 @@ export default { Accounts_CustomFields: { type: 'valueAsString' }, + Accounts_Default_User_Preferences_enableMessageParserEarlyAdoption: { + type: 'valueAsBoolean' + }, Accounts_EmailOrUsernamePlaceholder: { type: 'valueAsString' }, @@ -202,8 +205,5 @@ export default { }, Jitsi_Enable_Channels: { type: 'valuesAsBoolean' - }, - Accounts_Default_User_Preferences_enableMessageParserEarlyAdoption: { - type: 'valueAsBoolean' } }; diff --git a/app/lib/database/model/servers/User.js b/app/lib/database/model/servers/User.js index 6d78c27fa..30bd5f57d 100644 --- a/app/lib/database/model/servers/User.js +++ b/app/lib/database/model/servers/User.js @@ -25,4 +25,6 @@ export default class User extends Model { @field('show_message_in_main_thread') showMessageInMainThread; @field('is_from_webview') isFromWebView; + + @field('enable_message_parser_early_adoption') enableMessageParserEarlyAdoption; } diff --git a/app/lib/database/model/servers/migrations.js b/app/lib/database/model/servers/migrations.js index 80954d475..e8dfe62a0 100644 --- a/app/lib/database/model/servers/migrations.js +++ b/app/lib/database/model/servers/migrations.js @@ -105,6 +105,17 @@ export default schemaMigrations({ ] }) ] + }, + { + toVersion: 12, + steps: [ + addColumns({ + table: 'users', + columns: [ + { name: 'enable_message_parser_early_adoption', type: 'boolean', isOptional: true } + ] + }) + ] } ] }); diff --git a/app/lib/database/schema/servers.js b/app/lib/database/schema/servers.js index 1105cf165..1d849b874 100644 --- a/app/lib/database/schema/servers.js +++ b/app/lib/database/schema/servers.js @@ -1,7 +1,7 @@ import { appSchema, tableSchema } from '@nozbe/watermelondb'; export default appSchema({ - version: 11, + version: 12, tables: [ tableSchema({ name: 'users', @@ -16,7 +16,8 @@ export default appSchema({ { name: 'login_email_password', type: 'boolean', isOptional: true }, { name: 'show_message_in_main_thread', type: 'boolean', isOptional: true }, { name: 'avatar_etag', type: 'string', isOptional: true }, - { name: 'is_from_webview', type: 'boolean', isOptional: true } + { name: 'is_from_webview', type: 'boolean', isOptional: true }, + { name: 'enable_message_parser_early_adoption', type: 'boolean', isOptional: true } ] }), tableSchema({ diff --git a/app/views/ProfileView/index.js b/app/views/ProfileView/index.js index ca440adbd..51cf59f3d 100644 --- a/app/views/ProfileView/index.js +++ b/app/views/ProfileView/index.js @@ -61,23 +61,19 @@ class ProfileView extends React.Component { theme: PropTypes.string } - constructor(props) { - super(props); - const { Accounts_enableMessageParserEarlyAdoption } = this.props; - this.state = { - saving: false, - name: null, - username: null, - email: null, - newPassword: null, - currentPassword: null, - avatarUrl: null, - avatar: {}, - avatarSuggestions: {}, - customFields: {}, - enableMessageParser: Accounts_enableMessageParserEarlyAdoption - }; - } + state = { + saving: false, + enableMessageParserEarlyAdoption: false, + name: null, + username: null, + email: null, + newPassword: null, + currentPassword: null, + avatarUrl: null, + avatar: {}, + avatarSuggestions: {}, + customFields: {} + }; async componentDidMount() { this.init(); @@ -116,7 +112,7 @@ class ProfileView extends React.Component { init = (user) => { const { user: userProps } = this.props; const { - name, username, emails, customFields + name, username, emails, customFields, enableMessageParserEarlyAdoption } = user || userProps; this.setState({ @@ -127,13 +123,14 @@ class ProfileView extends React.Component { currentPassword: null, avatarUrl: null, avatar: {}, - customFields: customFields || {} + customFields: customFields || {}, + enableMessageParserEarlyAdoption }); } formIsChanged = () => { const { - name, username, email, newPassword, avatar, customFields + name, username, email, newPassword, avatar, customFields, enableMessageParserEarlyAdoption } = this.state; const { user } = this.props; let customFieldsChanged = false; @@ -149,6 +146,7 @@ class ProfileView extends React.Component { return !(user.name === name && user.username === username + && user.enableMessageParserEarlyAdoption === enableMessageParserEarlyAdoption && !newPassword && (user.emails && user.emails[0].address === email) && !avatar.data @@ -173,7 +171,7 @@ class ProfileView extends React.Component { this.setState({ saving: true }); const { - name, username, email, newPassword, currentPassword, avatar, customFields, enableMessageParser + name, username, email, newPassword, currentPassword, avatar, customFields, enableMessageParserEarlyAdoption } = this.state; const { user, setUser } = this.props; const params = {}; @@ -203,6 +201,11 @@ 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 }); diff --git a/package.json b/package.json index 626495280..ae3147925 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "@react-navigation/drawer": "5.12.5", "@react-navigation/native": "5.9.4", "@react-navigation/stack": "5.14.5", - "@rocket.chat/message-parser": "^0.27.0", "@rocket.chat/react-native-fast-image": "^8.2.0", "@rocket.chat/sdk": "RocketChat/Rocket.Chat.js.SDK#mobile", "@rocket.chat/ui-kit": "0.13.0", diff --git a/yarn.lock b/yarn.lock index c943e7a0f..e8cd3c094 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3215,11 +3215,6 @@ resolved "https://registry.yarnpkg.com/@redux-saga/types/-/types-1.1.0.tgz#0e81ce56b4883b4b2a3001ebe1ab298b84237204" integrity sha512-afmTuJrylUU/0OtqzaRkbyYFFNgCF73Bvel/sw90pvGrWIZ+vyoIJqA6eMSoA6+nb443kTmulmBtC9NerXboNg== -"@rocket.chat/message-parser@^0.27.0": - version "0.27.0" - resolved "https://registry.yarnpkg.com/@rocket.chat/message-parser/-/message-parser-0.27.0.tgz#55a07887da649bffb9277aa11ae843a0f5d22895" - integrity sha512-CJxV1N4aSOrTeGKPX+685EeYiG7AMivp8N23SHMZpmbxF36IoVsrdFlxlLRw11Dq8ZMkz4TXAyVk0i4Pvu/psA== - "@rocket.chat/react-native-fast-image@^8.2.0": version "8.2.0" resolved "https://registry.yarnpkg.com/@rocket.chat/react-native-fast-image/-/react-native-fast-image-8.2.0.tgz#4f48858f95f40afcb10b39cee9b1239c150d6c51"