[NEW] Logout from other logged in locations (#2386)

* Logout from other logged in locations

* Add UI feedback for the request result

* Refactor request to use the proper REST API

* Change backgroundColor

* I18n

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Youssef Muhamad 2020-08-25 13:51:49 -03:00 committed by GitHub
parent 49ea816f5c
commit 67ecab7169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 3 deletions

View File

@ -631,5 +631,9 @@ export default {
After_seconds_set_by_admin: 'After {{seconds}} seconds (set by admin)', After_seconds_set_by_admin: 'After {{seconds}} seconds (set by admin)',
Dont_activate: 'Don\'t activate now', Dont_activate: 'Don\'t activate now',
Queued_chats: 'Queued chats', 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_other_locations: 'You\'ll be logged out from other locations.',
Logged_out_of_other_clients_successfully: 'Logged out of other clients successfully',
Logout_failed: 'Logout failed!'
}; };

View File

@ -577,5 +577,9 @@ export default {
After_seconds_set_by_admin: 'Após {{seconds}} segundos (Configurado pelo adm)', After_seconds_set_by_admin: 'Após {{seconds}} segundos (Configurado pelo adm)',
Dont_activate: 'Não ativar agora', Dont_activate: 'Não ativar agora',
Queued_chats: 'Bate-papos na fila', 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_other_locations: 'Você perderá a sessão de outros clientes',
Logged_out_of_other_clients_successfully: 'Desconectado de outros clientes com sucesso',
Logout_failed: 'Falha ao desconectar!'
}; };

View File

@ -419,6 +419,10 @@ const RocketChat = {
return user; return user;
}, },
logout, logout,
logoutOtherLocations() {
const { id: userId } = reduxStore.getState().login.user;
return this.sdk.post('users.removeOtherTokens', { userId });
},
removeServer, removeServer,
async clearCache({ server }) { async clearCache({ server }) {
try { try {

View File

@ -119,6 +119,8 @@ export default {
PROFILE_SAVE_AVATAR_F: 'profile_save_avatar_f', PROFILE_SAVE_AVATAR_F: 'profile_save_avatar_f',
PROFILE_SAVE_CHANGES: 'profile_save_changes', PROFILE_SAVE_CHANGES: 'profile_save_changes',
PROFILE_SAVE_CHANGES_F: 'profile_save_changes_f', 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 // SETTINGS VIEW
SE_CONTACT_US: 'se_contact_us', SE_CONTACT_US: 'se_contact_us',

View File

@ -13,7 +13,7 @@ import KeyboardView from '../../presentation/KeyboardView';
import sharedStyles from '../Styles'; import sharedStyles from '../Styles';
import styles from './styles'; import styles from './styles';
import scrollPersistTaps from '../../utils/scrollPersistTaps'; import scrollPersistTaps from '../../utils/scrollPersistTaps';
import { showErrorAlert } from '../../utils/info'; import { showErrorAlert, showConfirmationAlert } from '../../utils/info';
import { LISTENER } from '../../containers/Toast'; import { LISTENER } from '../../containers/Toast';
import EventEmitter from '../../utils/events'; import EventEmitter from '../../utils/events';
import RocketChat from '../../lib/rocketchat'; import RocketChat from '../../lib/rocketchat';
@ -426,6 +426,23 @@ class ProfileView extends React.Component {
} }
} }
logoutOtherLocations = () => {
logEvent(events.PROFILE_LOGOUT_OTHER_LOCATIONS);
showConfirmationAlert({
message: I18n.t('You_will_be_logged_out_from_other_locations'),
callToAction: I18n.t('Logout'),
onPress: async() => {
try {
await RocketChat.logoutOtherLocations();
EventEmitter.emit(LISTENER, { message: I18n.t('Logged_out_of_other_clients_successfully') });
} catch {
logEvent(events.PROFILE_LOGOUT_OTHER_LOCATIONS_F);
EventEmitter.emit(LISTENER, { message: I18n.t('Logout_failed') });
}
}
});
}
render() { render() {
const { const {
name, username, email, newPassword, avatarUrl, customFields, avatar, saving name, username, email, newPassword, avatarUrl, customFields, avatar, saving
@ -552,6 +569,14 @@ class ProfileView extends React.Component {
loading={saving} loading={saving}
theme={theme} theme={theme}
/> />
<Button
title={I18n.t('Logout_from_other_logged_in_locations')}
type='secondary'
backgroundColor={themes[theme].chatComponentBackground}
onPress={this.logoutOtherLocations}
testID='profile-view-logout-other-locations'
theme={theme}
/>
</ScrollView> </ScrollView>
</SafeAreaView> </SafeAreaView>
</KeyboardView> </KeyboardView>