Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/actions/actionsTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const ROOMS = createRequestTypes('ROOMS', [
'OPEN_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 MESSAGES = createRequestTypes('MESSAGES', ['REPLY_BROADCAST']);
export const CREATE_CHANNEL = createRequestTypes('CREATE_CHANNEL', [...defaultTypes]);
Expand Down
8 changes: 4 additions & 4 deletions app/actions/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ export function leaveRoom(rid, t) {
};
}

export function deleteRoomInit(rid, t) {
export function deleteRoom(rid, t) {
return {
type: types.ROOM.DELETE_INIT,
type: types.ROOM.DELETE,
rid,
t
};
}

export function deleteRoomFinish() {
export function removedRoom() {
return {
type: types.ROOM.DELETE_FINISH
type: types.ROOM.REMOVED
};
}

Expand Down
4 changes: 2 additions & 2 deletions app/lib/methods/subscriptions/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { handlePayloadUserInteraction } from '../actions';
import buildMessage from '../helpers/buildMessage';
import RocketChat from '../../rocketchat';
import EventEmmiter from '../../../utils/events';
import { deleteRoomFinish } from '../../../actions/room';
import { removedRoom } from '../../../actions/room';

const removeListener = listener => listener.stop();

Expand Down Expand Up @@ -245,7 +245,7 @@ export default function subscribeRooms() {
// 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());
store.dispatch(removedRoom());
} else {
EventEmmiter.emit('ROOM_REMOVED', { rid: data.rid });
}
Expand Down
10 changes: 8 additions & 2 deletions app/reducers/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ const initialState = {

export default function(state = initialState, action) {
switch (action.type) {
case ROOM.DELETE_INIT:
case ROOM.LEAVE:
return {
...state,
rid: action.rid,
isDeleting: true
};
case ROOM.DELETE_FINISH:
case ROOM.DELETE:
return {
...state,
rid: action.rid,
isDeleting: true
};
case ROOM.REMOVED:
return {
...state,
isDeleting: false
Expand Down
34 changes: 18 additions & 16 deletions app/sagas/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {

import Navigation from '../lib/Navigation';
import * as types from '../actions/actionsTypes';
import { deleteRoomFinish } from '../actions/room';
import { removedRoom } from '../actions/room';
import RocketChat from '../lib/rocketchat';
import log from '../utils/log';
import I18n from '../i18n';
Expand All @@ -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 }) {
try {
const result = yield RocketChat.leaveRoom(rid, t);
if (result.success) {
yield Navigation.navigate('RoomsListView');
}
yield handleRemovedRoom({ result });
} catch (e) {
if (e.data && e.data.errorType === 'error-you-are-last-owner') {
Alert.alert(I18n.t('Oops'), I18n.t(e.data.errorType));
Expand All @@ -46,17 +58,7 @@ const handleLeaveRoom = function* handleLeaveRoom({ rid, t }) {
const handleDeleteRoom = function* handleDeleteRoom({ rid, t }) {
try {
const result = yield RocketChat.deleteRoom(rid, t);
if (result.success) {
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());
}
yield handleRemovedRoom({ result });
} catch (e) {
Alert.alert(I18n.t('Oops'), I18n.t('There_was_an_error_while_action', { action: I18n.t('deleting_room') }));
}
Expand All @@ -65,6 +67,6 @@ const handleDeleteRoom = function* handleDeleteRoom({ rid, t }) {
const root = function* root() {
yield takeLatest(types.ROOM.USER_TYPING, watchUserTyping);
yield takeLatest(types.ROOM.LEAVE, handleLeaveRoom);
yield takeLatest(types.ROOM.DELETE_INIT, handleDeleteRoom);
yield takeLatest(types.ROOM.DELETE, handleDeleteRoom);
};
export default root;
10 changes: 5 additions & 5 deletions app/views/RoomInfoEditView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import isEqual from 'lodash/isEqual';
import semver from 'semver';

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 sharedStyles from '../Styles';
import styles from './styles';
Expand Down Expand Up @@ -56,7 +56,7 @@ class RoomInfoEditView extends React.Component {

static propTypes = {
navigation: PropTypes.object,
deleteRoomInit: PropTypes.func,
deleteRoom: PropTypes.func,
serverVersion: PropTypes.string,
theme: PropTypes.string
};
Expand Down Expand Up @@ -253,7 +253,7 @@ class RoomInfoEditView extends React.Component {

delete = () => {
const { room } = this.state;
const { deleteRoomInit } = this.props;
const { deleteRoom } = this.props;

Alert.alert(
I18n.t('Are_you_sure_question_mark'),
Expand All @@ -266,7 +266,7 @@ class RoomInfoEditView extends React.Component {
{
text: I18n.t('Yes_action_it', { action: I18n.t('delete') }),
style: 'destructive',
onPress: () => deleteRoomInit(room.rid, room.t)
onPress: () => deleteRoom(room.rid, room.t)
}
],
{ cancelable: false }
Expand Down Expand Up @@ -554,7 +554,7 @@ const mapStateToProps = state => ({
});

const mapDispatchToProps = dispatch => ({
deleteRoomInit: (rid, t) => dispatch(deleteRoomInitAction(rid, t))
deleteRoom: (rid, t) => dispatch(deleteRoomAction(rid, t))
});

export default connect(mapStateToProps, mapDispatchToProps)(withTheme(RoomInfoEditView));