From 997eb3de63b9258dbd4d7030667b51c4b48f3808 Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 28 Aug 2016 23:48:50 +0200 Subject: [PATCH] client/tags: fix detecting changes to names Since 243ab15 the order of tag aliases matters, so the changes need to pick up also permuting - which were ignored before. --- client/js/models/tag.js | 2 +- client/js/util/misc.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/client/js/models/tag.js b/client/js/models/tag.js index 676ec54e..0d5a96cd 100644 --- a/client/js/models/tag.js +++ b/client/js/models/tag.js @@ -45,7 +45,7 @@ class Tag extends events.EventTarget { const detail = {version: this._version}; // send only changed fields to avoid user privilege violation - if (misc.arraysDiffer(this._names, this._orig._names)) { + if (misc.arraysDiffer(this._names, this._orig._names, true)) { detail.names = this._names; } if (this._category !== this._orig._category) { diff --git a/client/js/util/misc.js b/client/js/util/misc.js index 629db902..c46f9793 100644 --- a/client/js/util/misc.js +++ b/client/js/util/misc.js @@ -252,9 +252,20 @@ function escapeHtml(unsafe) { .replace(/'/g, '''); } -function arraysDiffer(source1, source2) { +function arraysDiffer(source1, source2, orderImportant) { source1 = [...source1]; source2 = [...source2]; + if (orderImportant === true) { + if (source1.length !== source2.length) { + return true; + } + for (let i = 0; i < source1.length; i++) { + if (source1[i] !== source2[i]) { + return true; + } + } + return false; + } return ( source1.filter(value => !source2.includes(value)).length > 0 || source2.filter(value => !source1.includes(value)).length > 0);