[FIX] Stop showing message on leave channel (#1896)
* [FIX] Leave room don't show 'was removed' message * [FIX] Remove duplicated code Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
c58120a639
commit
fe5ee355f1
|
@ -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', 'DELETE_INIT', 'DELETE_FINISH', 'USER_TYPING']);
|
export const ROOM = createRequestTypes('ROOM', ['LEAVE', 'DELETE', 'REMOVED', '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]);
|
||||||
|
|
|
@ -8,17 +8,17 @@ export function leaveRoom(rid, t) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteRoomInit(rid, t) {
|
export function deleteRoom(rid, t) {
|
||||||
return {
|
return {
|
||||||
type: types.ROOM.DELETE_INIT,
|
type: types.ROOM.DELETE,
|
||||||
rid,
|
rid,
|
||||||
t
|
t
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteRoomFinish() {
|
export function removedRoom() {
|
||||||
return {
|
return {
|
||||||
type: types.ROOM.DELETE_FINISH
|
type: types.ROOM.REMOVED
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +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';
|
import { removedRoom } from '../../../actions/room';
|
||||||
|
|
||||||
const removeListener = listener => listener.stop();
|
const removeListener = listener => listener.stop();
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ export default function subscribeRooms() {
|
||||||
// Delete and remove events come from this stream
|
// Delete and remove events come from this stream
|
||||||
// Here we identify which one was triggered
|
// Here we identify which one was triggered
|
||||||
if (data.rid === roomState.rid && roomState.isDeleting) {
|
if (data.rid === roomState.rid && roomState.isDeleting) {
|
||||||
store.dispatch(deleteRoomFinish());
|
store.dispatch(removedRoom());
|
||||||
} else {
|
} else {
|
||||||
EventEmmiter.emit('ROOM_REMOVED', { rid: data.rid });
|
EventEmmiter.emit('ROOM_REMOVED', { rid: data.rid });
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,19 @@ const initialState = {
|
||||||
|
|
||||||
export default function(state = initialState, action) {
|
export default function(state = initialState, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ROOM.DELETE_INIT:
|
case ROOM.LEAVE:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
rid: action.rid,
|
rid: action.rid,
|
||||||
isDeleting: true
|
isDeleting: true
|
||||||
};
|
};
|
||||||
case ROOM.DELETE_FINISH:
|
case ROOM.DELETE:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
rid: action.rid,
|
||||||
|
isDeleting: true
|
||||||
|
};
|
||||||
|
case ROOM.REMOVED:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
isDeleting: false
|
isDeleting: false
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {
|
||||||
|
|
||||||
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 { removedRoom } 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';
|
||||||
|
@ -28,12 +28,24 @@ const watchUserTyping = function* watchUserTyping({ rid, status }) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleRemovedRoom = function* handleLeaveRoom({ result }) {
|
||||||
|
if (result.success) {
|
||||||
|
yield Navigation.navigate('RoomsListView');
|
||||||
|
}
|
||||||
|
// types.ROOM.REMOVE is triggered by `subscriptions-changed` with `removed` arg
|
||||||
|
const { timeout } = yield race({
|
||||||
|
deleteFinished: take(types.ROOM.REMOVED),
|
||||||
|
timeout: delay(3000)
|
||||||
|
});
|
||||||
|
if (timeout) {
|
||||||
|
put(removedRoom());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleLeaveRoom = function* handleLeaveRoom({ rid, t }) {
|
const handleLeaveRoom = function* handleLeaveRoom({ rid, t }) {
|
||||||
try {
|
try {
|
||||||
const result = yield RocketChat.leaveRoom(rid, t);
|
const result = yield RocketChat.leaveRoom(rid, t);
|
||||||
if (result.success) {
|
yield handleRemovedRoom({ result });
|
||||||
yield Navigation.navigate('RoomsListView');
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.data && e.data.errorType === 'error-you-are-last-owner') {
|
if (e.data && e.data.errorType === 'error-you-are-last-owner') {
|
||||||
Alert.alert(I18n.t('Oops'), I18n.t(e.data.errorType));
|
Alert.alert(I18n.t('Oops'), I18n.t(e.data.errorType));
|
||||||
|
@ -46,17 +58,7 @@ const handleLeaveRoom = function* handleLeaveRoom({ rid, t }) {
|
||||||
const handleDeleteRoom = function* handleDeleteRoom({ rid, t }) {
|
const handleDeleteRoom = function* handleDeleteRoom({ rid, t }) {
|
||||||
try {
|
try {
|
||||||
const result = yield RocketChat.deleteRoom(rid, t);
|
const result = yield RocketChat.deleteRoom(rid, t);
|
||||||
if (result.success) {
|
yield handleRemovedRoom({ result });
|
||||||
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('deleting_room') }));
|
Alert.alert(I18n.t('Oops'), I18n.t('There_was_an_error_while_action', { action: I18n.t('deleting_room') }));
|
||||||
}
|
}
|
||||||
|
@ -65,6 +67,6 @@ const handleDeleteRoom = function* handleDeleteRoom({ rid, t }) {
|
||||||
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.DELETE_INIT, handleDeleteRoom);
|
yield takeLatest(types.ROOM.DELETE, handleDeleteRoom);
|
||||||
};
|
};
|
||||||
export default root;
|
export default root;
|
||||||
|
|
|
@ -11,7 +11,7 @@ import isEqual from 'lodash/isEqual';
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
|
|
||||||
import database from '../../lib/database';
|
import database from '../../lib/database';
|
||||||
import { deleteRoomInit as deleteRoomInitAction } from '../../actions/room';
|
import { deleteRoom as deleteRoomAction } 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';
|
||||||
|
@ -56,7 +56,7 @@ class RoomInfoEditView extends React.Component {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
navigation: PropTypes.object,
|
navigation: PropTypes.object,
|
||||||
deleteRoomInit: PropTypes.func,
|
deleteRoom: PropTypes.func,
|
||||||
serverVersion: PropTypes.string,
|
serverVersion: PropTypes.string,
|
||||||
theme: PropTypes.string
|
theme: PropTypes.string
|
||||||
};
|
};
|
||||||
|
@ -253,7 +253,7 @@ class RoomInfoEditView extends React.Component {
|
||||||
|
|
||||||
delete = () => {
|
delete = () => {
|
||||||
const { room } = this.state;
|
const { room } = this.state;
|
||||||
const { deleteRoomInit } = this.props;
|
const { deleteRoom } = this.props;
|
||||||
|
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
I18n.t('Are_you_sure_question_mark'),
|
I18n.t('Are_you_sure_question_mark'),
|
||||||
|
@ -266,7 +266,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: () => deleteRoomInit(room.rid, room.t)
|
onPress: () => deleteRoom(room.rid, room.t)
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
{ cancelable: false }
|
{ cancelable: false }
|
||||||
|
@ -554,7 +554,7 @@ const mapStateToProps = state => ({
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
deleteRoomInit: (rid, t) => dispatch(deleteRoomInitAction(rid, t))
|
deleteRoom: (rid, t) => dispatch(deleteRoomAction(rid, t))
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(RoomInfoEditView));
|
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(RoomInfoEditView));
|
||||||
|
|
Loading…
Reference in New Issue