From 732e92e17f91d7014e68b01c83713b1cae10b435 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 8 Apr 2021 15:46:24 +0200 Subject: [PATCH 1/3] Fix XXX --- www/admin/inner.js | 8 ++++---- www/common/notifications.js | 6 +----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/www/admin/inner.js b/www/admin/inner.js index beafdf0b1..1063cec9d 100644 --- a/www/admin/inner.js +++ b/www/admin/inner.js @@ -1240,7 +1240,7 @@ define([ var send = function (data) { $button.prop('disabled', 'disabled'); data.time = +new Date(); // XXX not used anymore? - common.mailbox.sendTo('BROADCAST_CUSTOM', data, {}, function (err /*, data */) { // XXX unused argument + common.mailbox.sendTo('BROADCAST_CUSTOM', data, {}, function (err) { if (err) { $button.prop('disabled', ''); console.error(err); @@ -1265,7 +1265,7 @@ define([ if (!activeUid) { return; } common.mailbox.sendTo('BROADCAST_DELETE', { uid: activeUid - }, {}, function (err /* , data */) { // XXX unused argument + }, {}, function (err) { if (err) { return UI.warn(Messages.error); } UI.log(Messages.saved); refresh(); @@ -1360,7 +1360,7 @@ define([ return; } // Maintenance applied, send notification - common.mailbox.sendTo('BROADCAST_MAINTENANCE', {}, {}, function (/* err, data */) { // XXX unused arguments + common.mailbox.sendTo('BROADCAST_MAINTENANCE', {}, {}, function () { refresh(); checkLastBroadcastHash(); }); @@ -1456,7 +1456,7 @@ define([ // Maintenance applied, send notification common.mailbox.sendTo('BROADCAST_SURVEY', { url: data - }, {}, function (/* err, data */) { // XXX unused arguments + }, {}, function () { refresh(); checkLastBroadcastHash(); }); diff --git a/www/common/notifications.js b/www/common/notifications.js index 4a26cab44..d364bad6c 100644 --- a/www/common/notifications.js +++ b/www/common/notifications.js @@ -415,7 +415,7 @@ define([ }; content.handler = function () { common.openUnsafeURL(msg.url); - // XXX dismiss on click? + defaultDismiss(common, data)(); }; if (!content.archived) { content.dismissHandler = defaultDismiss(common, data); @@ -440,7 +440,6 @@ define([ toShow = Util.fixHTML(toShow); content.getFormatText = function () { - // XXX Add a title to custom messages? Or use a generic key in the notification and only display the text in the alert? if (slice) { return toShow.slice(0, 200) + '...'; } @@ -448,13 +447,11 @@ define([ }; if (slice) { content.handler = function () { - // XXX Allow markdown (sanitized)? var content = h('div', [ h('h4', Messages.broadcast_newCustom), h('div.cp-admin-message', toShow) ]); UI.alert(content); - // XXX Dismiss on click? }; } if (!content.archived) { @@ -466,7 +463,6 @@ define([ return { add: function(common, data) { - console.log(data); // XXX noise? var type = data.content.msg.type; if (handlers[type]) { From 6027123d12dc696326d37fe765092505eb1187b2 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 8 Apr 2021 16:10:03 +0200 Subject: [PATCH 2/3] Fix maintenance --- lib/decrees.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/decrees.js b/lib/decrees.js index 09bf1926e..4eb1dff85 100644 --- a/lib/decrees.js +++ b/lib/decrees.js @@ -141,7 +141,7 @@ var args_isMaintenance = function (args) { var makeBroadcastSetter = function (attr, validation) { return function (Env, args) { - if ((validation && !validation(args)) || !args_isString(args)) { + if ((validation && !validation(args)) && !args_isString(args)) { throw new Error('INVALID_ARGS'); } var str = args[0]; From 406d3cdd0eb08c79d37989758e8e4e097cf6390c Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 8 Apr 2021 16:37:26 +0200 Subject: [PATCH 3/3] Fix race condition --- www/common/sframe-common-mailbox.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/www/common/sframe-common-mailbox.js b/www/common/sframe-common-mailbox.js index 58396b1e9..861ff8d53 100644 --- a/www/common/sframe-common-mailbox.js +++ b/www/common/sframe-common-mailbox.js @@ -217,11 +217,16 @@ define([ }); }; - var historyState = false; var onHistory = function () {}; - mailbox.getMoreHistory = function (type, count, lastKnownHash, cb) { - if (type !== "broadcast" && historyState) { return void cb("ALREADY_CALLED"); } - historyState = true; + var onHistoryEnd; + mailbox.getMoreHistory = function (type, count, lastKnownHash, cb) { + if (type === "broadcast" && onHistoryEnd) { + onHistoryEnd.reg(cb); + return; + } + if (onHistoryEnd) { return void cb("ALREADY_CALLED"); } + onHistoryEnd = Util.mkEvent(); + onHistoryEnd.reg(cb); var txid = Util.uid(); execCommand('LOAD_HISTORY', { type: type, @@ -237,8 +242,8 @@ define([ if (data.complete) { onHistory = function () {}; var end = messages.length < count; - cb(null, messages, end); - historyState = false; + onHistoryEnd.fire(null, messages, end); + onHistoryEnd = undefined; return; } if (data.hash !== lastKnownHash) {