add back .isDeleted property to becca's note, branch and attribute entities for BC, fixes #2268

This commit is contained in:
zadam 2021-10-31 21:03:26 +01:00
parent ec4d445f97
commit 5978447185
6 changed files with 32 additions and 6 deletions

View File

@ -70,7 +70,7 @@ function postProcessEntityUpdate(entityName, entity) {
}
}
eventService.subscribe([eventService.ENTITY_CHANGE_SYNCED], ({entityName, entityRow}) => {
eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({entityName, entityRow}) => {
if (!becca.loaded) {
return;
}
@ -93,7 +93,7 @@ eventService.subscribe([eventService.ENTITY_CHANGE_SYNCED], ({entityName, entit
postProcessEntityUpdate(entityName, entityRow);
});
eventService.subscribe(eventService.ENTITY_CHANGED, ({entityName, entity}) => {
eventService.subscribeBeccaLoader(eventService.ENTITY_CHANGED, ({entityName, entity}) => {
if (!becca.loaded) {
return;
}
@ -101,7 +101,7 @@ eventService.subscribe(eventService.ENTITY_CHANGED, ({entityName, entity}) => {
postProcessEntityUpdate(entityName, entity);
});
eventService.subscribe([eventService.ENTITY_DELETED, eventService.ENTITY_DELETE_SYNCED], ({entityName, entityId}) => {
eventService.subscribeBeccaLoader([eventService.ENTITY_DELETED, eventService.ENTITY_DELETE_SYNCED], ({entityName, entityId}) => {
if (!becca.loaded) {
return;
}
@ -220,7 +220,7 @@ function noteReorderingUpdated(branchIdList) {
}
}
eventService.subscribe(eventService.ENTER_PROTECTED_SESSION, () => {
eventService.subscribeBeccaLoader(eventService.ENTER_PROTECTED_SESSION, () => {
try {
becca.decryptProtectedNotes();
}
@ -229,7 +229,7 @@ eventService.subscribe(eventService.ENTER_PROTECTED_SESSION, () => {
}
});
eventService.subscribe(eventService.LEAVE_PROTECTED_SESSION, load);
eventService.subscribeBeccaLoader(eventService.LEAVE_PROTECTED_SESSION, load);
module.exports = {
load,

View File

@ -145,6 +145,10 @@ class Attribute extends AbstractEntity {
}
}
get isDeleted() {
return !(this.attributeId in this.becca.attributes);
}
beforeSaving() {
if (!this.value) {
if (this.type === 'relation') {

View File

@ -101,6 +101,10 @@ class Branch extends AbstractEntity {
return this.becca.notes[this.parentNoteId];
}
get isDeleted() {
return !(this.branchId in this.becca.branches);
}
beforeSaving() {
if (this.notePosition === undefined || this.notePosition === null) {
// TODO finding new position can be refactored into becca

View File

@ -1112,6 +1112,10 @@ class Note extends AbstractEntity {
}
}
get isDeleted() {
return !(this.noteId in this.becca.notes);
}
beforeSaving() {
super.beforeSaving();

View File

@ -147,7 +147,7 @@ function updateNoteAttributes(req) {
if (incAttr.type === 'relation') {
const targetNote = becca.getNote(incAttr.value);
if (!targetNote || targetNote.isDeleted) {
if (!targetNote) {
log.error(`Target note of relation ${JSON.stringify(incAttr)} does not exist or is deleted`);
continue;
}

View File

@ -27,6 +27,19 @@ function subscribe(eventTypes, listener) {
}
}
function subscribeBeccaLoader(eventTypes, listener) {
if (!Array.isArray(eventTypes)) {
eventTypes = [ eventTypes ];
}
for (const eventType of eventTypes) {
eventListeners[eventType] = eventListeners[eventType] || [];
// becca loader should be the first listener so that other listeners can already work
// with updated becca
eventListeners[eventType] = [listener, ...eventListeners[eventType]];
}
}
function emit(eventType, data) {
const listeners = eventListeners[eventType];
@ -45,6 +58,7 @@ function emit(eventType, data) {
module.exports = {
subscribe,
subscribeBeccaLoader,
emit,
// event types:
NOTE_TITLE_CHANGED,