From 200f94e2443cceebc8cb4a6c8505801ff5e1bfac Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Thu, 30 Apr 2020 13:24:49 -0300 Subject: [PATCH] [FIX] Respect UI_Allow_room_names_with_special_chars setting (#2076) Co-authored-by: Diego Mello --- app/constants/settings.js | 3 +++ app/lib/rocketchat.js | 5 ++++- app/views/RoomActionsView/index.js | 4 ++-- app/views/RoomInfoEditView/index.js | 4 ++-- app/views/RoomInfoView/index.js | 2 +- app/views/RoomView/index.js | 13 ++++--------- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/constants/settings.js b/app/constants/settings.js index 5287367fb..0103fb58f 100644 --- a/app/constants/settings.js +++ b/app/constants/settings.js @@ -125,6 +125,9 @@ export default { uniqueID: { type: 'valueAsString' }, + UI_Allow_room_names_with_special_chars: { + type: 'valueAsBoolean' + }, UI_Use_Real_Name: { type: 'valueAsBoolean' }, diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 9147eb97b..ad54ac35b 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -1226,11 +1226,14 @@ const RocketChat = { return this.methodCall('autoTranslate.translateMessage', message, targetLanguage); }, getRoomTitle(room) { - const { UI_Use_Real_Name: useRealName } = reduxStore.getState().settings; + const { UI_Use_Real_Name: useRealName, UI_Allow_room_names_with_special_chars: allowSpecialChars } = reduxStore.getState().settings; const { username } = reduxStore.getState().login.user; if (RocketChat.isGroupChat(room) && !(room.name && room.name.length)) { return room.usernames.filter(u => u !== username).sort((u1, u2) => u1.localeCompare(u2)).join(', '); } + if (allowSpecialChars && room.t !== 'd') { + return room.fname || room.name; + } return ((room.prid || useRealName) && room.fname) || room.name; }, getRoomAvatar(room) { diff --git a/app/views/RoomActionsView/index.js b/app/views/RoomActionsView/index.js index 21dc281f0..5e6a30f8e 100644 --- a/app/views/RoomActionsView/index.js +++ b/app/views/RoomActionsView/index.js @@ -442,7 +442,7 @@ class RoomActionsView extends React.Component { Alert.alert( I18n.t('Are_you_sure_question_mark'), - I18n.t('Are_you_sure_you_want_to_leave_the_room', { room: room.t === 'd' ? room.fname : room.name }), + I18n.t('Are_you_sure_you_want_to_leave_the_room', { room: RocketChat.getRoomTitle(room) }), [ { text: I18n.t('Cancel'), @@ -484,7 +484,7 @@ class RoomActionsView extends React.Component { : ( - {room.prid ? room.fname : room.name} + {RocketChat.getRoomTitle(room)} ) } diff --git a/app/views/RoomInfoEditView/index.js b/app/views/RoomInfoEditView/index.js index 63de0c02c..592ff8467 100644 --- a/app/views/RoomInfoEditView/index.js +++ b/app/views/RoomInfoEditView/index.js @@ -125,13 +125,13 @@ class RoomInfoEditView extends React.Component { init = (room) => { const { - name, description, topic, announcement, t, ro, reactWhenReadOnly, joinCodeRequired, sysMes + description, topic, announcement, t, ro, reactWhenReadOnly, joinCodeRequired, sysMes } = room; // fake password just to user knows about it this.randomValue = random(15); this.setState({ room, - name, + name: RocketChat.getRoomTitle(room), description, topic, announcement, diff --git a/app/views/RoomInfoView/index.js b/app/views/RoomInfoView/index.js index 184109ea7..1e1139f9a 100644 --- a/app/views/RoomInfoView/index.js +++ b/app/views/RoomInfoView/index.js @@ -36,7 +36,7 @@ const getRoomTitle = (room, type, name, username, statusText, theme) => (type == : ( - {room.prid ? room.fname : room.name} + {RocketChat.getRoomTitle(room)} ) ); diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 341df6ce6..9599e0326 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -218,7 +218,7 @@ class RoomView extends React.Component { } = this.props; if ((room.id || room.rid) && !this.tmid) { navigation.setParams({ - name: this.getRoomTitle(room), + name: RocketChat.getRoomTitle(room), subtitle: room.topic, avatar: room.name, t: room.t, @@ -292,7 +292,7 @@ class RoomView extends React.Component { } } if (((roomUpdate.fname !== prevState.roomUpdate.fname) || (roomUpdate.name !== prevState.roomUpdate.name)) && !this.tmid) { - navigation.setParams({ name: this.getRoomTitle(room) }); + navigation.setParams({ name: RocketChat.getRoomTitle(room) }); } } @@ -456,7 +456,7 @@ class RoomView extends React.Component { this.setState({ room }); if (!this.tmid) { navigation.setParams({ - name: this.getRoomTitle(room), + name: RocketChat.getRoomTitle(room), subtitle: room.topic, avatar: room.name, t: room.t @@ -645,7 +645,7 @@ class RoomView extends React.Component { const { room } = this.state; if (rid === this.rid) { Navigation.navigate('RoomsListView'); - showErrorAlert(I18n.t('You_were_removed_from_channel', { channel: this.getRoomTitle(room) }), I18n.t('Oops')); + showErrorAlert(I18n.t('You_were_removed_from_channel', { channel: RocketChat.getRoomTitle(room) }), I18n.t('Oops')); } } @@ -667,11 +667,6 @@ class RoomView extends React.Component { }); }; - getRoomTitle = (room) => { - const { useRealName } = this.props; - return ((room.prid || useRealName) && room.fname) || room.name; - } - getMessages = () => { const { room } = this.state; if (room.lastOpen) {