fix leave room bug

pull/10851/head
Guilherme Gazzo 7 years ago
parent 275c2b02ba
commit 68e51b5aff
No known key found for this signature in database
GPG Key ID: 1F85C9AD922D0829
  1. 18
      client/methods/leaveRoom.js
  2. 82
      packages/rocketchat-lib/client/lib/ChannelActions.js

@ -1,18 +0,0 @@
Meteor.methods({
leaveRoom(rid) {
if (!Meteor.userId()) {
return false;
}
ChatSubscription.remove({
rid,
'u._id': Meteor.userId()
});
ChatRoom.update(rid, {
$pull: {
usernames: Meteor.user().username
}
});
}
});

@ -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);
@ -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) {
@ -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
});
});
}

Loading…
Cancel
Save