From cdfbaf5ad9a1fe1044051c4bd6b1032ce2638ca2 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 21 Aug 2019 13:22:05 +0200 Subject: [PATCH] write tasks along with metadata --- historyKeeper.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/historyKeeper.js b/historyKeeper.js index 93ce0a2f1..672f63b76 100644 --- a/historyKeeper.js +++ b/historyKeeper.js @@ -318,6 +318,7 @@ module.exports.create = function (cfg) { if (metadata_cache[channel.id] && metadata_cache[channel.id].expire && metadata_cache[channel.id].expire < +new Date()) { return; // Don't store messages on expired channel + // TODO if a channel expired a long time ago but it's still here, remove it } let id; if (isCp) { @@ -667,21 +668,6 @@ module.exports.create = function (cfg) { metadata.channel = channelName; nThen(function (waitFor) { - if (!tasks) { return; } // tasks are not supported - if (typeof(metadata.expire) !== 'number' || !metadata.expire) { return; } - - // the fun part... - // the user has said they want this pad to expire at some point - tasks.write(metadata.expire, "EXPIRE", [ channelName ], waitFor(function (err) { - if (err) { - // if there is an error, we don't want to crash the whole server... - // just log it, and if there's a problem you'll be able to fix it - // at a later date with the provided information - Log.error('HK_CREATE_EXPIRE_TASK', err); - Log.info('HK_INVALID_EXPIRE_TASK', JSON.stringify([metadata.expire, 'EXPIRE', channelName])); - } - })); - }).nThen(function (waitFor) { var w = waitFor(); /* unless this is a young channel, we will serve all messages from an offset @@ -739,6 +725,21 @@ module.exports.create = function (cfg) { return void Log.error('HK_WRITE_METADATA'); } }); + + // write tasks + if(tasks && metadata.expire && metadata.expire === 'number') { + // the fun part... + // the user has said they want this pad to expire at some point + tasks.write(metadata.expire, "EXPIRE", [ channelName ], function (err) { + if (err) { + // if there is an error, we don't want to crash the whole server... + // just log it, and if there's a problem you'll be able to fix it + // at a later date with the provided information + Log.error('HK_CREATE_EXPIRE_TASK', err); + Log.info('HK_INVALID_EXPIRE_TASK', JSON.stringify([metadata.expire, 'EXPIRE', channelName])); + } + }); + } sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(metadata)]); }