[FIX] Batch server deletion on logout (#1382)

This commit is contained in:
Diego Mello 2019-11-13 16:53:57 -03:00 committed by GitHub
parent 447b48360f
commit 6f95bb0d17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 10 deletions

View File

@ -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

View File

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