From a372cbb2dfa918084e2d447a01fca6f076ddf486 Mon Sep 17 00:00:00 2001 From: azivner Date: Tue, 22 May 2018 23:51:13 -0400 Subject: [PATCH] fix #105 --- src/entities/entity.js | 5 ++++- src/services/script.js | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/entities/entity.js b/src/entities/entity.js index 395cbae9c..a5f1495d4 100644 --- a/src/entities/entity.js +++ b/src/entities/entity.js @@ -21,7 +21,10 @@ class Entity { contentToHash += "|" + this[propertyName]; } - this["hash"] = utils.hash(contentToHash).substr(0, 10); + // this IF is to ease the migration from before hashed options, can be later removed + if (this.constructor.tableName !== 'options' || this.isSynced) { + this["hash"] = utils.hash(contentToHash).substr(0, 10); + } } async save() { diff --git a/src/services/script.js b/src/services/script.js index e9b18ad07..c2759ec1c 100644 --- a/src/services/script.js +++ b/src/services/script.js @@ -1,6 +1,8 @@ const sql = require('./sql'); const ScriptContext = require('./script_context'); const repository = require('./repository'); +const cls = require('./cls'); +const sourceIdService = require('./source_id'); async function executeNote(note) { if (!note.isJavaScript()) { @@ -49,6 +51,9 @@ async function executeScript(script, params, startNoteId, currentNoteId) { } async function execute(ctx, script, paramsStr) { + // scripts run as "server" sourceId so clients recognize the changes as "foreign" and update themselves + cls.namespace.set('sourceId', sourceIdService.getCurrentSourceId()); + return await (function() { return eval(`const apiContext = this;\r\n(${script}\r\n)(${paramsStr})`); }.call(ctx)); }