From 3b7ec7d10b0eeeeb8d3180062950ce351f49c91d Mon Sep 17 00:00:00 2001 From: youssef-md Date: Sat, 8 Aug 2020 21:41:25 -0300 Subject: [PATCH 1/5] Logout from other logged in locations --- app/i18n/locales/en.js | 4 +++- app/i18n/locales/pt-BR.js | 4 +++- app/lib/rocketchat.js | 4 ++++ app/utils/log/events.js | 2 ++ app/views/ProfileView/index.js | 24 +++++++++++++++++++++++- 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/i18n/locales/en.js b/app/i18n/locales/en.js index 72ebbdb4efb..b138186aacf 100644 --- a/app/i18n/locales/en.js +++ b/app/i18n/locales/en.js @@ -624,5 +624,7 @@ export default { After_seconds_set_by_admin: 'After {{seconds}} seconds (set by admin)', Dont_activate: 'Don\'t activate now', Queued_chats: 'Queued chats', - Queue_is_empty: 'Queue is empty' + Queue_is_empty: 'Queue is empty', + Logout_from_other_logged_in_locations: 'Logout from other logged in locations', + You_will_be_logged_out_from_all_locations: 'You\'ll be logged out from all locations.' }; diff --git a/app/i18n/locales/pt-BR.js b/app/i18n/locales/pt-BR.js index 8ed4e76da6b..2ca6846c7de 100644 --- a/app/i18n/locales/pt-BR.js +++ b/app/i18n/locales/pt-BR.js @@ -569,5 +569,7 @@ export default { After_seconds_set_by_admin: 'Após {{seconds}} segundos (Configurado pelo adm)', Dont_activate: 'Não ativar agora', Queued_chats: 'Bate-papos na fila', - Queue_is_empty: 'A fila está vazia' + Queue_is_empty: 'A fila está vazia', + Logout_from_other_logged_in_locations: 'Sair de outros locais logados', + You_will_be_logged_out_from_all_locations: 'Você sairá de todos os locais.' }; diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 52c09f93f38..cafa98f3f5f 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -421,6 +421,10 @@ const RocketChat = { return user; }, logout, + logoutOtherLocations() { + const { id: userId } = reduxStore.getState().login.user; + return this.methodCallWrapper('logoutOtherClients', { id: userId }); + }, removeServer, async clearCache({ server }) { try { diff --git a/app/utils/log/events.js b/app/utils/log/events.js index c6d51d7e210..9e1dfc9d649 100644 --- a/app/utils/log/events.js +++ b/app/utils/log/events.js @@ -119,6 +119,8 @@ export default { PROFILE_SAVE_AVATAR_F: 'profile_save_avatar_f', PROFILE_SAVE_CHANGES: 'profile_save_changes', PROFILE_SAVE_CHANGES_F: 'profile_save_changes_f', + PROFILE_LOGOUT_OTHER_LOCATIONS: 'profile_logout_other_locations', + PROFILE_LOGOUT_OTHER_LOCATIONS_F: 'profile_logout_other_locations_f', // SETTINGS VIEW SE_CONTACT_US: 'se_contact_us', diff --git a/app/views/ProfileView/index.js b/app/views/ProfileView/index.js index 8d289935be5..4e600daefcc 100644 --- a/app/views/ProfileView/index.js +++ b/app/views/ProfileView/index.js @@ -13,7 +13,7 @@ import KeyboardView from '../../presentation/KeyboardView'; import sharedStyles from '../Styles'; import styles from './styles'; import scrollPersistTaps from '../../utils/scrollPersistTaps'; -import { showErrorAlert } from '../../utils/info'; +import { showErrorAlert, showConfirmationAlert } from '../../utils/info'; import { LISTENER } from '../../containers/Toast'; import EventEmitter from '../../utils/events'; import RocketChat from '../../lib/rocketchat'; @@ -423,6 +423,21 @@ class ProfileView extends React.Component { } } + logoutOtherLocations = () => { + logEvent(events.PROFILE_LOGOUT_OTHER_LOCATIONS); + showConfirmationAlert({ + message: I18n.t('You_will_be_logged_out_from_all_locations'), + callToAction: I18n.t('Logout'), + onPress: async() => { + try { + await RocketChat.logoutOtherLocations(); + } catch { + logEvent(events.PROFILE_LOGOUT_OTHER_LOCATIONS_F); + } + } + }); + } + render() { const { name, username, email, newPassword, avatarUrl, customFields, avatar, saving @@ -549,6 +564,13 @@ class ProfileView extends React.Component { loading={saving} theme={theme} /> +