From 4597ab6c78e3d9ff634730fd39acf48cde783bb2 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Wed, 4 Mar 2020 08:49:54 -0300 Subject: [PATCH] [FIX] Pop from room which you have been removed (#1819) Co-authored-by: Diego Mello --- app/i18n/locales/en.js | 1 + app/i18n/locales/pt-BR.js | 1 + app/lib/methods/subscriptions/rooms.js | 2 ++ app/views/RoomView/index.js | 11 +++++++++++ 4 files changed, 15 insertions(+) diff --git a/app/i18n/locales/en.js b/app/i18n/locales/en.js index f6a643d1b..fc6a565a8 100644 --- a/app/i18n/locales/en.js +++ b/app/i18n/locales/en.js @@ -476,6 +476,7 @@ export default { You_can_search_using_RegExp_eg: 'You can use RegExp. e.g. `/^text$/i`', You_colon: 'You: ', you_were_mentioned: 'you were mentioned', + You_were_removed_from_channel: 'You were removed from {{channel}}', you: 'you', You: 'You', Logged_out_by_server: 'You\'ve been logged out by the server. Please log in again.', diff --git a/app/i18n/locales/pt-BR.js b/app/i18n/locales/pt-BR.js index 75fae9464..557ec7a12 100644 --- a/app/i18n/locales/pt-BR.js +++ b/app/i18n/locales/pt-BR.js @@ -427,6 +427,7 @@ export default { You_can_search_using_RegExp_eg: 'Você pode usar expressões regulares, por exemplo `/^text$/i`', You_colon: 'Você: ', you_were_mentioned: 'você foi mencionado', + You_were_removed_from_channel: 'Você foi removido de {{channel}}', you: 'você', You: 'Você', Your_invite_link_will_expire_after__usesLeft__uses: 'Seu link de convite irá vencer depois de {{usesLeft}} usos.', diff --git a/app/lib/methods/subscriptions/rooms.js b/app/lib/methods/subscriptions/rooms.js index 8a0891f56..8436e0afa 100644 --- a/app/lib/methods/subscriptions/rooms.js +++ b/app/lib/methods/subscriptions/rooms.js @@ -13,6 +13,7 @@ import { notificationReceived } from '../../../actions/notification'; import { handlePayloadUserInteraction } from '../actions'; import buildMessage from '../helpers/buildMessage'; import RocketChat from '../../rocketchat'; +import EventEmmiter from '../../../utils/events'; const removeListener = listener => listener.stop(); @@ -238,6 +239,7 @@ export default function subscribeRooms() { ...threadMessagesToDelete ); }); + EventEmmiter.emit('removed', { rid: data.rid }); } catch (e) { log(e); } diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 5472c5029..3d15f63fe 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -229,6 +229,7 @@ class RoomView extends React.Component { if (isTablet) { EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands); } + EventEmitter.addEventListener('removed', this.handleRemoved); console.timeEnd(`${ this.constructor.name } mount`); } @@ -311,6 +312,7 @@ class RoomView extends React.Component { if (isTablet) { EventEmitter.removeListener(KEY_COMMAND, this.handleCommands); } + EventEmitter.removeListener('removed', this.handleRemoved); console.countReset(`${ this.constructor.name }.render calls`); } @@ -551,6 +553,15 @@ class RoomView extends React.Component { EventEmitter.removeListener('connected', this.handleConnected); } + handleRemoved = ({ rid }) => { + const { room } = this.state; + const { navigation } = this.props; + if (rid === this.rid) { + navigation.pop(); + showErrorAlert(I18n.t('You_were_removed_from_channel', { channel: this.getRoomTitle(room) }), I18n.t('Oops')); + } + } + internalSetState = (...args) => { if (!this.mounted) { return;