From 6f95bb0d17678aa82a1da378601dde5a8d3dbd18 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 13 Nov 2019 16:53:57 -0300 Subject: [PATCH] [FIX] Batch server deletion on logout (#1382) --- app/lib/rocketchat.js | 9 +++++++-- app/sagas/login.js | 9 +-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index d253c8204..d9986abf3 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -430,8 +430,13 @@ const RocketChat = { const serversDB = database.servers; await serversDB.action(async() => { const usersCollection = serversDB.collections.get('users'); - const user = await usersCollection.find(userId); - await user.destroyPermanently(); + const userRecord = await usersCollection.find(userId); + const serverCollection = serversDB.collections.get('servers'); + const serverRecord = await serverCollection.find(server); + await serversDB.batch( + userRecord.prepareDestroyPermanently(), + serverRecord.prepareDestroyPermanently() + ); }); } catch (error) { // Do nothing diff --git a/app/sagas/login.js b/app/sagas/login.js index b9d20a55b..5d54eb5ff 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -130,16 +130,9 @@ const handleLogout = function* handleLogout() { const serversDB = database.servers; // all servers const serversCollection = serversDB.collections.get('servers'); - - // filter logging out server and delete it - yield serversDB.action(async() => { - const serverRecord = await serversCollection.find(server); - await serverRecord.destroyPermanently(); - }); - const servers = yield serversCollection.query().fetch(); - // see if there's other logged in servers and selects first one + // see if there're other logged in servers and selects first one if (servers.length > 0) { const newServer = servers[0].id; const token = yield RNUserDefaults.get(`${ RocketChat.TOKEN_KEY }-${ newServer }`);