From 0add556537942bf2ec757592b86091cac81a5a2e Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 28 Mar 2024 12:45:20 +0100 Subject: [PATCH] Fix timestamp issues with support tickets --- lib/hk-util.js | 8 ++++---- www/common/outer/support.js | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/hk-util.js b/lib/hk-util.js index 2c5054f51..da0a63ab8 100644 --- a/lib/hk-util.js +++ b/lib/hk-util.js @@ -311,14 +311,13 @@ var trimMapByOffset = function (map, offset) { * to guarantee that offset computation is always atomic with writes */ // FIXME 'optionalMessageHash' is always supplied, so we could consider renaming it for clarity -const storeMessage = function (Env, channel, msg, isCp, optionalMessageHash, cb) { +const storeMessage = function (Env, channel, msg, isCp, optionalMessageHash, time, cb) { const id = channel.id; const Log = Env.Log; if (typeof(cb) !== "function") { cb = function () {}; } Env.queueStorage(id, function (next) { const msgBin = Buffer.from(msg + '\n', 'utf8'); - const time = Array.isArray(msg) && msg[msg.length - 1]; // Store the message first, and update the index only once it's stored. // store.messageBin can be async so updating the index first may // result in a wrong cpIndex @@ -1033,11 +1032,12 @@ HK.onChannelMessage = function (Env, Server, channel, msgStruct, cb) { } // add the time to the message - msgStruct.push(now()); + let time = now(); + msgStruct.push(time); // storeMessage //console.log(+new Date(), "Storing message"); - storeMessage(Env, channel, JSON.stringify(msgStruct), isCp, getHash(msgStruct[4], Log), cb); + storeMessage(Env, channel, JSON.stringify(msgStruct), isCp, getHash(msgStruct[4], Log), time, cb); //console.log(+new Date(), "Message stored"); }); }; diff --git a/www/common/outer/support.js b/www/common/outer/support.js index f447c4103..1e18c6442 100644 --- a/www/common/outer/support.js +++ b/www/common/outer/support.js @@ -239,7 +239,7 @@ define([ getKeys(ctx, isAdmin, data, waitFor((err, obj) => { if (err) { waitFor.abort(); - return void cb({error: err}); + return void cb(err); } theirPublic = obj.theirPublic; myCurve = obj.myCurve; @@ -517,23 +517,26 @@ define([ if (data.curvePublic !== curve) { return; } return Util.find(msg, ['sender', 'quota', 'plan']); }); - var senderKey = last.sender && last.sender.edPublic; // Update ChainPad with latest ticket data var entry = doc.tickets.active[data.channel]; if (entry) { - entry.time = last.time; if (last.legacy) { let lastMsg = Array.isArray(last.messages) && last.messages[last.messages.length - 1]; - entry.time = lastMsg.time || entry.time; - senderKey = lastMsg.sender && lastMsg.sender.edPublic; + last = lastMsg; } + entry.time = last.time; entry.premium = premium; - + if (last.sender) { + entry.lastAdmin = !last.sender.blockLocation; + } + /* + let senderKey = last.sender && last.sender.edPublic; if (senderKey) { entry.lastAdmin = ctx.moderatorKeys.indexOf(senderKey) !== -1; } + */ } cb(res); }); @@ -899,15 +902,14 @@ define([ var rdmTo = Math.floor(Math.random() * 2000); // Between 0 and 2000ms setTimeout(() => { var doc = ctx.adminDoc.proxy; - if (!doc.tickets.active[data.channel] && !doc.tickets.pending[data.channel]) { - return; } let t = doc.tickets.active[data.channel] || doc.tickets.pending[data.channel]; + if (!t) { return; } + if (data.time <= t.time) { return; } if (data.isClose) { doc.tickets.closed[data.channel] = t; delete doc.tickets.active[data.channel]; delete doc.tickets.pending[data.channel]; } - if (data.time <= t.time) { return; } t.time = data.time; t.lastAdmin = false;