Skip to content

Commit

Permalink
fix leave room bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed May 23, 2018
1 parent 275c2b0 commit 68e51b5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 56 deletions.
18 changes: 0 additions & 18 deletions client/methods/leaveRoom.js

This file was deleted.

82 changes: 44 additions & 38 deletions packages/rocketchat-lib/client/lib/ChannelActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,33 @@ export function hide(type, rid, name) {
cancelButtonText: t('Cancel'),
closeOnConfirm: true,
html: false
}, function() {
}, async function() {
if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) {
FlowRouter.go('home');
}

Meteor.call('hideRoom', rid, function(err) {
if (err) {
handleError(err);
} else if (rid === Session.get('openedRoom')) {
Session.delete('openedRoom');
}
});
await call('hideRoom', rid);
if (rid === Session.get('openedRoom')) {
Session.delete('openedRoom');
}
});

return false;
}

const leaveRoom = async rid => {
if (!Meteor.userId()) {
return false;
}
const tmp = ChatSubscription.findOne({ rid, 'u._id': Meteor.userId() });
ChatSubscription.remove({ rid, 'u._id': Meteor.userId() });
try {
await call('leaveRoom', rid);
} catch (error) {
ChatSubscription.insert(tmp);
throw error;
}
};

export function leave(type, rid, name) {
const warnText = RocketChat.roomTypes.roomTypes[type].getUiText(UiTextContext.LEAVE_WARNING);

Expand All @@ -43,29 +53,26 @@ export function leave(type, rid, name) {
cancelButtonText: t('Cancel'),
closeOnConfirm: false,
html: false
}, function(isConfirm) {
if (isConfirm) {
Meteor.call('leaveRoom', rid, function(err) {
if (err) {
modal.open({
title: t('Warning'),
text: handleError(err, false),
type: 'warning',
html: false
});
} else {
modal.close();
if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) {
FlowRouter.go('home');
}

RoomManager.close(rid);
}
}, async function(isConfirm) {
if (!isConfirm) {
return;
}
try {
await leaveRoom(rid);
modal.close();
if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) {
FlowRouter.go('home');
}
RoomManager.close(rid);
} catch (error) {
return modal.open({
type: 'error',
title: t('Warning'),
text: handleError(error, false),
html: false
});
}
});

return false;
}

export function erase(rid) {
Expand All @@ -79,15 +86,14 @@ export function erase(rid) {
cancelButtonText: t('Cancel'),
closeOnConfirm: false,
html: false
}, () => {
call('eraseRoom', rid).then(() => {
modal.open({
title: t('Deleted'),
text: t('Room_has_been_deleted'),
type: 'success',
timer: 2000,
showConfirmButton: false
});
}, async() => {
await call('eraseRoom', rid);
modal.open({
title: t('Deleted'),
text: t('Room_has_been_deleted'),
type: 'success',
timer: 2000,
showConfirmButton: false
});
});
}

0 comments on commit 68e51b5

Please sign in to comment.