mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-12 19:49:59 +05:00
Fix timestamp issues with support tickets
This commit is contained in:
parent
c0a21eeb82
commit
0add556537
@ -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");
|
||||
});
|
||||
};
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user