1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Electron: Started integrating encryption

This commit is contained in:
Laurent Cozic
2017-12-14 17:58:10 +00:00
parent 55266e5694
commit 888ac8f4c2
11 changed files with 90 additions and 34 deletions

View File

@@ -8,6 +8,7 @@ const defaultState = {
notesParentType: null,
folders: [],
tags: [],
masterKeys: [],
searches: [],
selectedNoteIds: [],
selectedFolderId: null,
@@ -29,6 +30,20 @@ const defaultState = {
hasDisabledSyncItems: false,
};
function arrayHasEncryptedItems(array) {
for (let i = 0; i < array.length; i++) {
if (!!array[i].encryption_applied) return true;
}
return false
}
function stateHasEncryptedItems(state) {
if (arrayHasEncryptedItems(state.notes)) return true;
if (arrayHasEncryptedItems(state.folders)) return true;
if (arrayHasEncryptedItems(state.tags)) return true;
return false;
}
// When deleting a note, tag or folder
function handleItemDelete(state, action) {
let newState = Object.assign({}, state);
@@ -72,9 +87,16 @@ function handleItemDelete(state, action) {
return newState;
}
function updateOneTagOrFolder(state, action) {
let newItems = action.type === 'TAG_UPDATE_ONE' ? state.tags.splice(0) : state.folders.splice(0);
let item = action.type === 'TAG_UPDATE_ONE' ? action.tag : action.folder;
function updateOneItem(state, action) {
// let newItems = action.type === 'TAG_UPDATE_ONE' ? state.tags.splice(0) : state.folders.splice(0);
// let item = action.type === 'TAG_UPDATE_ONE' ? action.tag : action.folder;
let itemsKey = null;
if (action.type === 'TAG_UPDATE_ONE') itemsKey = 'tags';
if (action.type === 'FOLDER_UPDATE_ONE') itemsKey = 'folders';
if (action.type === 'MASTERKEY_UPDATE_ONE') itemsKey = 'masterKeys';
let newItems = state[itemsKey].splice(0);
let item = action.item;
var found = false;
for (let i = 0; i < newItems.length; i++) {
@@ -90,11 +112,13 @@ function updateOneTagOrFolder(state, action) {
let newState = Object.assign({}, state);
if (action.type === 'TAG_UPDATE_ONE') {
newState.tags = newItems;
} else {
newState.folders = newItems;
}
newState[itemsKey] = newItems;
// if (action.type === 'TAG_UPDATE_ONE') {
// newState.tags = newItems;
// } else {
// newState.folders = newItems;
// }
return newState;
}
@@ -307,14 +331,14 @@ const reducer = (state = defaultState, action) => {
case 'FOLDER_UPDATE_ALL':
newState = Object.assign({}, state);
newState.folders = action.folders;
newState.folders = action.items;
break;
case 'TAG_UPDATE_ALL':
newState = Object.assign({}, state);
newState.tags = action.tags;
break;
newState.tags = action.items;
break;
case 'TAG_SELECT':
@@ -328,13 +352,10 @@ const reducer = (state = defaultState, action) => {
break;
case 'TAG_UPDATE_ONE':
newState = updateOneTagOrFolder(state, action);
break;
case 'FOLDER_UPDATE_ONE':
case 'MASTERKEY_UPDATE_ONE':
newState = updateOneTagOrFolder(state, action);
newState = updateOneItem(state, action);
break;
case 'FOLDER_DELETE':
@@ -342,6 +363,12 @@ const reducer = (state = defaultState, action) => {
newState = handleItemDelete(state, action);
break;
case 'MASTERKEY_UPDATE_ALL':
newState = Object.assign({}, state);
newState.masterKeys = action.items;
break;
case 'SYNC_STARTED':
newState = Object.assign({}, state);
@@ -408,6 +435,11 @@ const reducer = (state = defaultState, action) => {
throw error;
}
if (action.type.indexOf('NOTE_UPDATE') === 0 || action.type.indexOf('FOLDER_UPDATE') === 0 || action.type.indexOf('TAG_UPDATE') === 0) {
newState = Object.assign({}, newState);
newState.hasEncryptedItems = stateHasEncryptedItems(newState);
}
return newState;
}