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 electron_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"electron-updater": "^3.0.3",
"electron-window-state": "^4.1.1",
"getos": "^3.1.1",
"knex": "0.15.2",
"knex": "0.17.6",
"line-by-line": "^0.1.6",
"moment": "^2.22.2",
"os-locale": "^3.0.1",
Expand Down
14 changes: 10 additions & 4 deletions electron_app/src/DBManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,11 @@ const deleteEmailContactByEmailId = (emailId, trx) => {
/* EmailLabel
----------------------------- */
const createEmailLabel = (emailLabels, prevTrx) => {
const transaction = prevTrx ? fn => fn(prevTrx) : db.transaction;
return transaction(async trx => {
const createOrUseTrx = (oldTrx, callback) => {
if (oldTrx) return callback(oldTrx);
return db.transaction(newTrx => callback(newTrx));
};
return createOrUseTrx(prevTrx, async trx => {
const toInsert = await filterEmailLabelIfNotStore(emailLabels, trx);
if (toInsert.length) {
await filterEmailLabelTrashToUpdateEmail(toInsert, 'create', trx);
Expand All @@ -252,8 +255,11 @@ const deleteEmailLabel = ({ emailIds, labelIds }, prevTrx) => {
labelId: labelIds[0]
};
});
const transaction = prevTrx ? fn => fn(prevTrx) : db.transaction;
return transaction(async trx => {
const createOrUseTrx = (oldTrx, callback) => {
if (oldTrx) return callback(oldTrx);
return db.transaction(newTrx => callback(newTrx));
};
return createOrUseTrx(prevTrx, async trx => {
await filterEmailLabelTrashToUpdateEmail(emailLabels, 'delete', trx);
return await trx
.table(Table.EMAIL_LABEL)
Expand Down
51 changes: 51 additions & 0 deletions electron_app/src/__integrations__/Email.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,57 @@ describe('Store relation data to EmailLabel Table: ', () => {
const response = await DBManager.createEmailLabel(emailLabelDraft);
expect(response).toBeUndefined();
});

it('Should Add and Remove emailLabel relation to database', async () => {
const emailUpdateLabels = {
email: {
threadId: 'threadK',
key: '12',
s3Key: 's3KeyK',
subject: 'Greetings',
content: '<p>Hello there</p>',
preview: 'Hello there',
date: '2013-10-07 08:23:20.120',
status: 1,
unread: false,
secure: true,
isMuted: false,
messageId: 'messageIdK',
fromAddress: 'User me <user@criptext.com>'
},
recipients: {
from: ['User me <user@criptext.com>'],
to: ['usera@criptext.com']
},
labels: [3, 7]
};
await DBManager.createEmail(emailUpdateLabels);
const [email] = await DBManager.getEmailByKey(emailUpdateLabels.email.key);
// Add
const emailLabelToAdd = [
{ emailId: email.id, labelId: systemLabels.starred.id }
];
const [addResponse] = await DBManager.createEmailLabel(emailLabelToAdd);
expect(addResponse).toEqual(expect.any(Number));
// Remove
await DBManager.deleteEmailLabel({
emailIds: [email.id],
labelIds: [systemLabels.starred.id]
});
// Check if exists
let existsRelation = false;
const remainingEmailLabels = await DBManager.getEmailLabelsByEmailId(
email.id
);
for (const remainingLabel of remainingEmailLabels) {
const { labelId } = remainingLabel;
if (labelId === systemLabels.starred.id) {
existsRelation = true;
break;
}
}
expect(existsRelation).toBe(false);
});
});

describe('Load data emails from Email Table:', () => {
Expand Down
12 changes: 5 additions & 7 deletions electron_app/src/globalManager.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
const packageData = require('./../package.json');
const allInstallerTypes = require('./../installerResources/installerTypes.json');
const { INSTALLER_TYPE } = require('./utils/const');
const { getDeviceType } = require('./utils/osUtils');
const currrentInstallerType = packageData.criptextInstallerType;
const allInstallerTypes = require('./../installerResources/installerTypes.json');

global.composerData = {};
global.emailToEdit = {};
global.isMAS = currrentInstallerType === allInstallerTypes.mac.store;
global.isMAS = INSTALLER_TYPE === allInstallerTypes.mac.store;
global.loadingData = {};
global.modalData = {};
global.temporalAccount = {};
global.windowsEventsDisabled = false;
global.internetConnection;
global.isWindowsStore =
currrentInstallerType === allInstallerTypes.windows.store;
global.deviceType = getDeviceType(currrentInstallerType, allInstallerTypes);
global.isWindowsStore = INSTALLER_TYPE === allInstallerTypes.windows.store;
global.deviceType = getDeviceType(INSTALLER_TYPE, allInstallerTypes);
global.pendingRestore = false;

/* Composer
Expand Down
5 changes: 3 additions & 2 deletions electron_app/src/nucleusManager.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const { APP_VERSION, NUCLEUS_ID } = require('./utils/const');
const { APP_VERSION, NUCLEUS_ID, INSTALLER_TYPE } = require('./utils/const');
const myAccount = require('./Account');
let Nucleus;

const initNucleus = ({ userId }) => {
const data = {
onlyMainProcess: true,
userId: userId || 'unknown',
version: APP_VERSION
version: APP_VERSION,
installerType: INSTALLER_TYPE
};
Nucleus = require('electron-nucleus')(NUCLEUS_ID, data);
};
Expand Down
9 changes: 7 additions & 2 deletions electron_app/src/utils/const.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* process */
require('dotenv').config();
const { version, nucleusId } = require('./../../package.json');
const {
version,
nucleusId,
criptextInstallerType
} = require('./../../package.json');

const API_CLIENT_VERSION = '9.0.0';
const LINK_DEVICES_FILE_VERSION = '5';
Expand Down Expand Up @@ -32,5 +36,6 @@ module.exports = {
APP_VERSION: isDevelopment ? '0.0.0' : version,
NUCLEUS_ID: isDevelopment
? process.env.DEV_NUCLEUS_ID
: process.env.PROD_NUCLEUS_ID || nucleusId
: process.env.PROD_NUCLEUS_ID || nucleusId,
INSTALLER_TYPE: criptextInstallerType
};
Loading