diff --git a/app/constants/settings.js b/app/constants/settings.js index 4f2c1f444..04298fbd3 100644 --- a/app/constants/settings.js +++ b/app/constants/settings.js @@ -50,6 +50,9 @@ export default { FEDERATION_Enabled: { type: 'valueAsBoolean' }, + Hide_System_Messages: { + type: 'valueAsArray' + }, LDAP_Enable: { type: 'valueAsBoolean' }, @@ -120,7 +123,7 @@ export default { type: 'valueAsBoolean' }, Threads_enabled: { - type: null + type: 'valueAsBoolean' }, FileUpload_MediaTypeWhiteList: { type: 'valueAsString' diff --git a/app/lib/database/model/Setting.js b/app/lib/database/model/Setting.js index dce080366..050e70981 100644 --- a/app/lib/database/model/Setting.js +++ b/app/lib/database/model/Setting.js @@ -1,5 +1,7 @@ import { Model } from '@nozbe/watermelondb'; -import { field, date } from '@nozbe/watermelondb/decorators'; +import { field, date, json } from '@nozbe/watermelondb/decorators'; + +import { sanitizer } from '../utils'; export default class Setting extends Model { static table = 'settings'; @@ -10,5 +12,7 @@ export default class Setting extends Model { @field('value_as_number') valueAsNumber; + @json('value_as_array', sanitizer) valueAsArray; + @date('_updated_at') _updatedAt; } diff --git a/app/lib/database/model/migrations.js b/app/lib/database/model/migrations.js index c0b859419..ced859bda 100644 --- a/app/lib/database/model/migrations.js +++ b/app/lib/database/model/migrations.js @@ -40,6 +40,17 @@ export default schemaMigrations({ ] }) ] + }, + { + toVersion: 5, + steps: [ + addColumns({ + table: 'settings', + columns: [ + { name: 'value_as_array', type: 'string', isOptional: true } + ] + }) + ] } ] }); diff --git a/app/lib/database/schema/app.js b/app/lib/database/schema/app.js index ab3390ee7..de98df29b 100644 --- a/app/lib/database/schema/app.js +++ b/app/lib/database/schema/app.js @@ -1,7 +1,7 @@ import { appSchema, tableSchema } from '@nozbe/watermelondb'; export default appSchema({ - version: 4, + version: 5, tables: [ tableSchema({ name: 'subscriptions', @@ -196,6 +196,7 @@ export default appSchema({ { name: 'value_as_string', type: 'string', isOptional: true }, { name: 'value_as_boolean', type: 'boolean', isOptional: true }, { name: 'value_as_number', type: 'number', isOptional: true }, + { name: 'value_as_array', type: 'string', isOptional: true }, { name: '_updated_at', type: 'number', isOptional: true } ] }), diff --git a/app/lib/methods/getSettings.js b/app/lib/methods/getSettings.js index 5ab7aa59a..ab6c83304 100644 --- a/app/lib/methods/getSettings.js +++ b/app/lib/methods/getSettings.js @@ -78,6 +78,7 @@ export async function setSettings() { valueAsString: item.valueAsString, valueAsBoolean: item.valueAsBoolean, valueAsNumber: item.valueAsNumber, + valueAsArray: item.valueAsArray, _updatedAt: item._updatedAt })); reduxStore.dispatch(actions.setAllSettings(RocketChat.parseSettings(parsed.slice(0, parsed.length)))); diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 0805ed58c..3d275eb57 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -629,6 +629,10 @@ const RocketChat = { getRoles, parseSettings: settings => settings.reduce((ret, item) => { ret[item._id] = item[defaultSettings[item._id].type]; + if (item._id === 'Hide_System_Messages') { + ret[item._id] = ret[item._id] + .reduce((array, value) => [...array, ...value === 'mute_unmute' ? ['user-muted', 'user-unmuted'] : [value]], []); + } return ret; }, {}), _prepareSettings(settings) { diff --git a/app/views/RoomView/List.js b/app/views/RoomView/List.js index 864f60cce..238fb319d 100644 --- a/app/views/RoomView/List.js +++ b/app/views/RoomView/List.js @@ -27,6 +27,7 @@ class List extends React.Component { tmid: PropTypes.string, theme: PropTypes.string, listRef: PropTypes.func, + hideSystemMessages: PropTypes.array, navigation: PropTypes.object }; @@ -61,7 +62,7 @@ class List extends React.Component { // eslint-disable-next-line react/sort-comp async init() { - const { rid, tmid } = this.props; + const { rid, tmid, hideSystemMessages = [] } = this.props; const db = database.active; if (tmid) { @@ -74,12 +75,12 @@ class List extends React.Component { } this.messagesObservable = db.collections .get('thread_messages') - .query(Q.where('rid', tmid)) + .query(Q.where('rid', tmid), Q.or(Q.where('t', Q.notIn(hideSystemMessages)), Q.where('t', Q.eq(null)))) .observe(); } else if (rid) { this.messagesObservable = db.collections .get('messages') - .query(Q.where('rid', rid)) + .query(Q.where('rid', rid), Q.or(Q.where('t', Q.notIn(hideSystemMessages)), Q.where('t', Q.eq(null)))) .observe(); } diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index dacdbd39f..fb08d61ff 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -142,6 +142,7 @@ class RoomView extends React.Component { Message_GroupingPeriod: PropTypes.number, Message_TimeFormat: PropTypes.string, Message_Read_Receipt_Enabled: PropTypes.bool, + Hide_System_Messages: PropTypes.array, baseUrl: PropTypes.string, customEmojis: PropTypes.object, screenProps: PropTypes.object, @@ -943,7 +944,7 @@ class RoomView extends React.Component { room, reactionsModalVisible, selectedMessage, loading, reacting } = this.state; const { - user, baseUrl, theme, navigation + user, baseUrl, theme, navigation, Hide_System_Messages } = this.props; const { rid, t } = room; @@ -969,6 +970,7 @@ class RoomView extends React.Component { renderRow={this.renderItem} loading={loading} navigation={navigation} + hideSystemMessages={Hide_System_Messages} /> {this.renderAnnouncementModal()} {this.renderFooter()} @@ -1003,7 +1005,8 @@ const mapStateToProps = state => ({ useMarkdown: state.markdown.useMarkdown, customEmojis: state.customEmojis, baseUrl: state.server.server, - Message_Read_Receipt_Enabled: state.settings.Message_Read_Receipt_Enabled + Message_Read_Receipt_Enabled: state.settings.Message_Read_Receipt_Enabled, + Hide_System_Messages: state.settings.Hide_System_Messages }); const mapDispatchToProps = dispatch => ({