[FIX] Separate delete and remove channel (#1832)

* Rename to delete room

* Separate delete and remove channel

* handleRemoved -> handleRoomRemoved

* [FIX] Navigate to RoomsList & Handle tablet case

Co-authored-by: Djorkaeff Alexandre <djorkaeff.unb@gmail.com>
This commit is contained in:
Diego Mello 2020-03-06 10:13:24 -03:00 committed by GitHub
parent 4dc04b8579
commit ff807d705c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 92 additions and 31 deletions

View File

@ -31,7 +31,7 @@ export const ROOMS = createRequestTypes('ROOMS', [
'OPEN_SEARCH_HEADER', 'OPEN_SEARCH_HEADER',
'CLOSE_SEARCH_HEADER' 'CLOSE_SEARCH_HEADER'
]); ]);
export const ROOM = createRequestTypes('ROOM', ['LEAVE', 'ERASE', 'USER_TYPING']); export const ROOM = createRequestTypes('ROOM', ['LEAVE', 'DELETE_INIT', 'DELETE_FINISH', 'USER_TYPING']);
export const APP = createRequestTypes('APP', ['START', 'READY', 'INIT', 'INIT_LOCAL_SETTINGS']); export const APP = createRequestTypes('APP', ['START', 'READY', 'INIT', 'INIT_LOCAL_SETTINGS']);
export const MESSAGES = createRequestTypes('MESSAGES', ['REPLY_BROADCAST']); export const MESSAGES = createRequestTypes('MESSAGES', ['REPLY_BROADCAST']);
export const CREATE_CHANNEL = createRequestTypes('CREATE_CHANNEL', [...defaultTypes]); export const CREATE_CHANNEL = createRequestTypes('CREATE_CHANNEL', [...defaultTypes]);

View File

@ -8,14 +8,20 @@ export function leaveRoom(rid, t) {
}; };
} }
export function eraseRoom(rid, t) { export function deleteRoomInit(rid, t) {
return { return {
type: types.ROOM.ERASE, type: types.ROOM.DELETE_INIT,
rid, rid,
t t
}; };
} }
export function deleteRoomFinish() {
return {
type: types.ROOM.DELETE_FINISH
};
}
export function userTyping(rid, status = true) { export function userTyping(rid, status = true) {
return { return {
type: types.ROOM.USER_TYPING, type: types.ROOM.USER_TYPING,

View File

@ -166,6 +166,7 @@ export default {
delete: 'löschen', delete: 'löschen',
Delete: 'Löschen', Delete: 'Löschen',
DELETE: 'LÖSCHEN', DELETE: 'LÖSCHEN',
deleting_room: 'lösche Raum',
description: 'Beschreibung', description: 'Beschreibung',
Description: 'Beschreibung', Description: 'Beschreibung',
DESKTOP_OPTIONS: 'Desktop-Einstellungen', DESKTOP_OPTIONS: 'Desktop-Einstellungen',
@ -187,7 +188,6 @@ export default {
Enable_Auto_Translate: 'Automatische Übersetzung aktivieren', Enable_Auto_Translate: 'Automatische Übersetzung aktivieren',
Enable_notifications: 'Benachrichtigungen aktivieren', Enable_notifications: 'Benachrichtigungen aktivieren',
Everyone_can_access_this_channel: 'Jeder kann auf diesen Kanal zugreifen', Everyone_can_access_this_channel: 'Jeder kann auf diesen Kanal zugreifen',
erasing_room: 'lösche Raum',
Error_uploading: 'Fehler beim Hochladen', Error_uploading: 'Fehler beim Hochladen',
Expiration_Days: 'läuft ab (Tage)', Expiration_Days: 'läuft ab (Tage)',
Favorite: 'Favorisieren', Favorite: 'Favorisieren',

View File

@ -166,6 +166,7 @@ export default {
delete: 'delete', delete: 'delete',
Delete: 'Delete', Delete: 'Delete',
DELETE: 'DELETE', DELETE: 'DELETE',
deleting_room: 'deleting room',
description: 'description', description: 'description',
Description: 'Description', Description: 'Description',
DESKTOP_OPTIONS: 'DESKTOP OPTIONS', DESKTOP_OPTIONS: 'DESKTOP OPTIONS',
@ -187,7 +188,6 @@ export default {
Enable_Auto_Translate: 'Enable Auto-Translate', Enable_Auto_Translate: 'Enable Auto-Translate',
Enable_notifications: 'Enable notifications', Enable_notifications: 'Enable notifications',
Everyone_can_access_this_channel: 'Everyone can access this channel', Everyone_can_access_this_channel: 'Everyone can access this channel',
erasing_room: 'erasing room',
Error_uploading: 'Error uploading', Error_uploading: 'Error uploading',
Expiration_Days: 'Expiration (Days)', Expiration_Days: 'Expiration (Days)',
Favorite: 'Favorite', Favorite: 'Favorite',

View File

@ -158,6 +158,7 @@ export default {
delete: 'eliminar', delete: 'eliminar',
Delete: 'Eliminar', Delete: 'Eliminar',
DELETE: 'ELIMINAR', DELETE: 'ELIMINAR',
deleting_room: 'eliminando sala',
description: 'descripción', description: 'descripción',
Description: 'Descripción', Description: 'Descripción',
DESKTOP_OPTIONS: 'OPCIONES DE ESCRITORIO', DESKTOP_OPTIONS: 'OPCIONES DE ESCRITORIO',
@ -178,7 +179,6 @@ export default {
Enable_Auto_Translate: 'Permitir Auto-Translate', Enable_Auto_Translate: 'Permitir Auto-Translate',
Enable_notifications: 'Permitir notificaciones', Enable_notifications: 'Permitir notificaciones',
Everyone_can_access_this_channel: 'Todos los usuarios pueden acceder a este canal', Everyone_can_access_this_channel: 'Todos los usuarios pueden acceder a este canal',
erasing_room: 'eliminando sala',
Error_uploading: 'Error en la subida', Error_uploading: 'Error en la subida',
Favorite: 'Favorito', Favorite: 'Favorito',
Favorites: 'Favoritos', Favorites: 'Favoritos',

View File

@ -138,6 +138,7 @@ export default {
delete: 'supprimez', delete: 'supprimez',
Delete: 'Supprimez', Delete: 'Supprimez',
DELETE: 'SUPPRIMEZ', DELETE: 'SUPPRIMEZ',
deleting_room: 'effacement de la salle',
description: 'la description', description: 'la description',
Description: 'La description', Description: 'La description',
Disable_notifications: 'Désactiver les notifications', Disable_notifications: 'Désactiver les notifications',
@ -145,7 +146,6 @@ export default {
Dont_Have_An_Account: 'Vous n\'avez pas de compte?', Dont_Have_An_Account: 'Vous n\'avez pas de compte?',
Do_you_really_want_to_key_this_room_question_mark: 'Voulez-vous vraiment {{key}} cette salle?', Do_you_really_want_to_key_this_room_question_mark: 'Voulez-vous vraiment {{key}} cette salle?',
edit: 'modifier', edit: 'modifier',
erasing_room: 'effacement de la salle',
Edit: 'Modifier', Edit: 'Modifier',
Email_or_password_field_is_empty: 'Le champ e-mail ou mot de passe est vide', Email_or_password_field_is_empty: 'Le champ e-mail ou mot de passe est vide',
Email: 'E-mail', Email: 'E-mail',

View File

@ -160,6 +160,7 @@ export default {
delete: 'elimina', delete: 'elimina',
Delete: 'Elimina', Delete: 'Elimina',
DELETE: 'ELIMINA', DELETE: 'ELIMINA',
deleting_room: 'cancellazione stanza',
description: 'descrizione', description: 'descrizione',
Description: 'Descrizione', Description: 'Descrizione',
DESKTOP_OPTIONS: 'OPZIONI DESKTOP', DESKTOP_OPTIONS: 'OPZIONI DESKTOP',
@ -181,7 +182,6 @@ export default {
Enable_Auto_Translate: 'Abilita traduzione automatica', Enable_Auto_Translate: 'Abilita traduzione automatica',
Enable_notifications: 'Abilita notifiche', Enable_notifications: 'Abilita notifiche',
Everyone_can_access_this_channel: 'Tutti hanno accesso a questo canale', Everyone_can_access_this_channel: 'Tutti hanno accesso a questo canale',
erasing_room: 'cancellazione stanza',
Error_uploading: 'Errore nel caricamento di', Error_uploading: 'Errore nel caricamento di',
Expiration_Days: 'Scadenza (giorni)', Expiration_Days: 'Scadenza (giorni)',
Favorite: 'Preferito', Favorite: 'Preferito',

View File

@ -181,6 +181,7 @@ export default {
delete: '削除', delete: '削除',
Delete: '削除', Delete: '削除',
DELETE: '削除', DELETE: '削除',
deleting_room: 'ルームを削除',
description: '概要', description: '概要',
Description: '概要', Description: '概要',
DESKTOP_OPTIONS: 'デスクトップオプション', DESKTOP_OPTIONS: 'デスクトップオプション',
@ -204,7 +205,6 @@ export default {
Enable_markdown: 'マークダウンを有効にする', Enable_markdown: 'マークダウンを有効にする',
Enable_notifications: '通知を有効にする', Enable_notifications: '通知を有効にする',
Everyone_can_access_this_channel: '全員このチャンネルにアクセスできます', Everyone_can_access_this_channel: '全員このチャンネルにアクセスできます',
erasing_room: 'ルームを削除',
Error_uploading: 'アップロードエラー', Error_uploading: 'アップロードエラー',
Expiration_Days: '期限切れ (日)', Expiration_Days: '期限切れ (日)',
Favorite: 'お気に入り', Favorite: 'お気に入り',

View File

@ -160,6 +160,7 @@ export default {
delete: 'delete', delete: 'delete',
Delete: 'Delete', Delete: 'Delete',
DELETE: 'DELETE', DELETE: 'DELETE',
deleting_room: 'kamer legen',
description: 'beschrijving', description: 'beschrijving',
Description: 'Beschrijving', Description: 'Beschrijving',
DESKTOP_OPTIONS: 'DESKTOP OPTIES', DESKTOP_OPTIONS: 'DESKTOP OPTIES',
@ -181,7 +182,6 @@ export default {
Enable_Auto_Translate: 'Zet Auto-Translate aan', Enable_Auto_Translate: 'Zet Auto-Translate aan',
Enable_notifications: 'Zet notifications aan', Enable_notifications: 'Zet notifications aan',
Everyone_can_access_this_channel: 'Iedereen kan bij dit kanaal', Everyone_can_access_this_channel: 'Iedereen kan bij dit kanaal',
erasing_room: 'kamer legen',
Error_uploading: 'Error tijdens uploaden', Error_uploading: 'Error tijdens uploaden',
Expiration_Days: 'Vervalt in (Dagen)', Expiration_Days: 'Vervalt in (Dagen)',
Favorite: 'Favoriet', Favorite: 'Favoriet',

View File

@ -163,6 +163,7 @@ export default {
delete: 'excluir', delete: 'excluir',
Delete: 'Excluir', Delete: 'Excluir',
DELETE: 'EXCLUIR', DELETE: 'EXCLUIR',
deleting_room: 'excluindo sala',
Direct_Messages: 'Mensagens Diretas', Direct_Messages: 'Mensagens Diretas',
Directory: 'Diretório', Directory: 'Diretório',
description: 'descrição', description: 'descrição',
@ -173,7 +174,6 @@ export default {
Do_you_really_want_to_key_this_room_question_mark: 'Você quer realmente {{key}} esta sala?', Do_you_really_want_to_key_this_room_question_mark: 'Você quer realmente {{key}} esta sala?',
edit: 'editar', edit: 'editar',
edited: 'editado', edited: 'editado',
erasing_room: 'apagando sala',
Edit: 'Editar', Edit: 'Editar',
Edit_Invite: 'Editar convite', Edit_Invite: 'Editar convite',
Email_or_password_field_is_empty: 'Email ou senha estão vazios', Email_or_password_field_is_empty: 'Email ou senha estão vazios',

View File

@ -145,7 +145,7 @@ export default {
Dont_Have_An_Account: 'Não tem uma conta?', Dont_Have_An_Account: 'Não tem uma conta?',
Do_you_really_want_to_key_this_room_question_mark: 'Você quer mesmo {{key}} esta sala?', Do_you_really_want_to_key_this_room_question_mark: 'Você quer mesmo {{key}} esta sala?',
edit: 'editar', edit: 'editar',
erasing_room: 'apagando sala', deleting_room: 'apagando sala',
Edit: 'Editar', Edit: 'Editar',
Email_or_password_field_is_empty: 'O campo de e-mail ou palavra-passe está vazio', Email_or_password_field_is_empty: 'O campo de e-mail ou palavra-passe está vazio',
Email: 'E-mail', Email: 'E-mail',

View File

@ -173,7 +173,7 @@ export default {
Enable_Auto_Translate: 'Включить автоперевод', Enable_Auto_Translate: 'Включить автоперевод',
Enable_notifications: 'Включить уведомления', Enable_notifications: 'Включить уведомления',
Everyone_can_access_this_channel: 'Каждый может получить доступ к этому каналу', Everyone_can_access_this_channel: 'Каждый может получить доступ к этому каналу',
erasing_room: 'стирание комнаты', deleting_room: 'стирание комнаты',
Error_uploading: 'Ошибка при загрузке', Error_uploading: 'Ошибка при загрузке',
Favorite: 'Избранное', Favorite: 'Избранное',
Favorites: 'Избранные', Favorites: 'Избранные',

View File

@ -144,7 +144,7 @@ export default {
Dont_Have_An_Account: '还没有账号?', Dont_Have_An_Account: '还没有账号?',
Do_you_really_want_to_key_this_room_question_mark: '你真的想要{{key}}这个房间吗?', Do_you_really_want_to_key_this_room_question_mark: '你真的想要{{key}}这个房间吗?',
edit: '编辑', edit: '编辑',
erasing_room: '正抹去房间', deleting_room: '正抹去房间',
Edit: '编辑', Edit: '编辑',
Email_or_password_field_is_empty: '邮件或密码字段为空', Email_or_password_field_is_empty: '邮件或密码字段为空',
Email: '邮箱', Email: '邮箱',

View File

@ -14,6 +14,7 @@ import { handlePayloadUserInteraction } from '../actions';
import buildMessage from '../helpers/buildMessage'; import buildMessage from '../helpers/buildMessage';
import RocketChat from '../../rocketchat'; import RocketChat from '../../rocketchat';
import EventEmmiter from '../../../utils/events'; import EventEmmiter from '../../../utils/events';
import { deleteRoomFinish } from '../../../actions/room';
const removeListener = listener => listener.stop(); const removeListener = listener => listener.stop();
@ -239,7 +240,15 @@ export default function subscribeRooms() {
...threadMessagesToDelete ...threadMessagesToDelete
); );
}); });
EventEmmiter.emit('removed', { rid: data.rid });
const roomState = store.getState().room;
// Delete and remove events come from this stream
// Here we identify which one was triggered
if (data.rid === roomState.rid && roomState.isDeleting) {
store.dispatch(deleteRoomFinish());
} else {
EventEmmiter.emit('ROOM_REMOVED', { rid: data.rid });
}
} catch (e) { } catch (e) {
log(e); log(e);
} }

View File

@ -787,7 +787,7 @@ const RocketChat = {
// RC 0.48.0 // RC 0.48.0
return this.sdk.post(`${ this.roomTypeToApiType(t) }.leave`, { roomId }); return this.sdk.post(`${ this.roomTypeToApiType(t) }.leave`, { roomId });
}, },
eraseRoom(roomId, t) { deleteRoom(roomId, t) {
// RC 0.49.0 // RC 0.49.0
return this.sdk.post(`${ this.roomTypeToApiType(t) }.delete`, { roomId }); return this.sdk.post(`${ this.roomTypeToApiType(t) }.delete`, { roomId });
}, },

View File

@ -2,6 +2,7 @@ import { combineReducers } from 'redux';
import settings from './reducers'; import settings from './reducers';
import login from './login'; import login from './login';
import meteor from './connect'; import meteor from './connect';
import room from './room';
import rooms from './rooms'; import rooms from './rooms';
import server from './server'; import server from './server';
import selectedUsers from './selectedUsers'; import selectedUsers from './selectedUsers';
@ -24,6 +25,7 @@ export default combineReducers({
selectedUsers, selectedUsers,
createChannel, createChannel,
app, app,
room,
rooms, rooms,
sortPreferences, sortPreferences,
notification, notification,

24
app/reducers/room.js Normal file
View File

@ -0,0 +1,24 @@
import { ROOM } from '../actions/actionsTypes';
const initialState = {
rid: null,
isDeleting: false
};
export default function(state = initialState, action) {
switch (action.type) {
case ROOM.DELETE_INIT:
return {
...state,
rid: action.rid,
isDeleting: true
};
case ROOM.DELETE_FINISH:
return {
...state,
isDeleting: false
};
default:
return state;
}
}

View File

@ -1,10 +1,11 @@
import { Alert } from 'react-native'; import { Alert } from 'react-native';
import { import {
takeLatest, take, select, delay takeLatest, take, select, delay, race, put
} from 'redux-saga/effects'; } from 'redux-saga/effects';
import Navigation from '../lib/Navigation'; import Navigation from '../lib/Navigation';
import * as types from '../actions/actionsTypes'; import * as types from '../actions/actionsTypes';
import { deleteRoomFinish } from '../actions/room';
import RocketChat from '../lib/rocketchat'; import RocketChat from '../lib/rocketchat';
import log from '../utils/log'; import log from '../utils/log';
import I18n from '../i18n'; import I18n from '../i18n';
@ -42,20 +43,28 @@ const handleLeaveRoom = function* handleLeaveRoom({ rid, t }) {
} }
}; };
const handleEraseRoom = function* handleEraseRoom({ rid, t }) { const handleDeleteRoom = function* handleDeleteRoom({ rid, t }) {
try { try {
const result = yield RocketChat.eraseRoom(rid, t); const result = yield RocketChat.deleteRoom(rid, t);
if (result.success) { if (result.success) {
yield Navigation.navigate('RoomsListView'); yield Navigation.navigate('RoomsListView');
} }
// types.ROOM.DELETE_FINISH is triggered by `subscriptions-changed` with `removed` arg
const { timeout } = yield race({
deleteFinished: take(types.ROOM.DELETE_FINISH),
timeout: delay(3000)
});
if (timeout) {
put(deleteRoomFinish());
}
} catch (e) { } catch (e) {
Alert.alert(I18n.t('Oops'), I18n.t('There_was_an_error_while_action', { action: I18n.t('erasing_room') })); Alert.alert(I18n.t('Oops'), I18n.t('There_was_an_error_while_action', { action: I18n.t('deleting_room') }));
} }
}; };
const root = function* root() { const root = function* root() {
yield takeLatest(types.ROOM.USER_TYPING, watchUserTyping); yield takeLatest(types.ROOM.USER_TYPING, watchUserTyping);
yield takeLatest(types.ROOM.LEAVE, handleLeaveRoom); yield takeLatest(types.ROOM.LEAVE, handleLeaveRoom);
yield takeLatest(types.ROOM.ERASE, handleEraseRoom); yield takeLatest(types.ROOM.DELETE_INIT, handleDeleteRoom);
}; };
export default root; export default root;

View File

@ -129,6 +129,17 @@ export const initTabletNav = (setState) => {
return null; return null;
} }
if (routeName === 'RoomsListView') {
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'RoomView', params: {} })]
});
roomRef.dispatch(resetAction);
notificationRef.dispatch(resetAction);
setState({ showModal: false });
return null;
}
if (routeName === 'NewMessageView') { if (routeName === 'NewMessageView') {
modalRef.dispatch(NavigationActions.navigate({ routeName, params })); modalRef.dispatch(NavigationActions.navigate({ routeName, params }));
setState({ showModal: true }); setState({ showModal: true });

View File

@ -8,7 +8,7 @@ import { SafeAreaView } from 'react-navigation';
import equal from 'deep-equal'; import equal from 'deep-equal';
import database from '../../lib/database'; import database from '../../lib/database';
import { eraseRoom as eraseRoomAction } from '../../actions/room'; import { deleteRoomInit as deleteRoomInitAction } from '../../actions/room';
import KeyboardView from '../../presentation/KeyboardView'; import KeyboardView from '../../presentation/KeyboardView';
import sharedStyles from '../Styles'; import sharedStyles from '../Styles';
import styles from './styles'; import styles from './styles';
@ -51,7 +51,7 @@ class RoomInfoEditView extends React.Component {
static propTypes = { static propTypes = {
navigation: PropTypes.object, navigation: PropTypes.object,
eraseRoom: PropTypes.func, deleteRoomInit: PropTypes.func,
theme: PropTypes.string theme: PropTypes.string
}; };
@ -237,7 +237,7 @@ class RoomInfoEditView extends React.Component {
delete = () => { delete = () => {
const { room } = this.state; const { room } = this.state;
const { eraseRoom } = this.props; const { deleteRoomInit } = this.props;
Alert.alert( Alert.alert(
I18n.t('Are_you_sure_question_mark'), I18n.t('Are_you_sure_question_mark'),
@ -250,7 +250,7 @@ class RoomInfoEditView extends React.Component {
{ {
text: I18n.t('Yes_action_it', { action: I18n.t('delete') }), text: I18n.t('Yes_action_it', { action: I18n.t('delete') }),
style: 'destructive', style: 'destructive',
onPress: () => eraseRoom(room.rid, room.t) onPress: () => deleteRoomInit(room.rid, room.t)
} }
], ],
{ cancelable: false } { cancelable: false }
@ -498,7 +498,7 @@ class RoomInfoEditView extends React.Component {
} }
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
eraseRoom: (rid, t) => dispatch(eraseRoomAction(rid, t)) deleteRoomInit: (rid, t) => dispatch(deleteRoomInitAction(rid, t))
}); });
export default connect(null, mapDispatchToProps)(withTheme(RoomInfoEditView)); export default connect(null, mapDispatchToProps)(withTheme(RoomInfoEditView));

View File

@ -54,6 +54,7 @@ import RoomClass from '../../lib/methods/subscriptions/room';
import { getUserSelector } from '../../selectors/login'; import { getUserSelector } from '../../selectors/login';
import { CONTAINER_TYPES } from '../../lib/methods/actions'; import { CONTAINER_TYPES } from '../../lib/methods/actions';
import Markdown from '../../containers/markdown'; import Markdown from '../../containers/markdown';
import Navigation from '../../lib/Navigation';
const stateAttrsUpdate = [ const stateAttrsUpdate = [
'joined', 'joined',
@ -229,7 +230,7 @@ class RoomView extends React.Component {
if (isTablet) { if (isTablet) {
EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands); EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands);
} }
EventEmitter.addEventListener('removed', this.handleRemoved); EventEmitter.addEventListener('ROOM_REMOVED', this.handleRoomRemoved);
console.timeEnd(`${ this.constructor.name } mount`); console.timeEnd(`${ this.constructor.name } mount`);
} }
@ -312,7 +313,7 @@ class RoomView extends React.Component {
if (isTablet) { if (isTablet) {
EventEmitter.removeListener(KEY_COMMAND, this.handleCommands); EventEmitter.removeListener(KEY_COMMAND, this.handleCommands);
} }
EventEmitter.removeListener('removed', this.handleRemoved); EventEmitter.removeListener('ROOM_REMOVED', this.handleRoomRemoved);
console.countReset(`${ this.constructor.name }.render calls`); console.countReset(`${ this.constructor.name }.render calls`);
} }
@ -553,11 +554,10 @@ class RoomView extends React.Component {
EventEmitter.removeListener('connected', this.handleConnected); EventEmitter.removeListener('connected', this.handleConnected);
} }
handleRemoved = ({ rid }) => { handleRoomRemoved = ({ rid }) => {
const { room } = this.state; const { room } = this.state;
const { navigation } = this.props;
if (rid === this.rid) { if (rid === this.rid) {
navigation.pop(); 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: this.getRoomTitle(room) }), I18n.t('Oops'));
} }
} }