From bd621043ff6dd75a437b2d9432ed539e068979c9 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 8 Apr 2022 04:30:31 -0400 Subject: [PATCH] chat: Move message copy to `padCopy` hook --- src/ep.json | 1 + src/node/chat.js | 13 +++++++++++++ src/node/db/Pad.js | 1 - 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ep.json b/src/ep.json index 7b657c05a..f1c4ad3cd 100644 --- a/src/ep.json +++ b/src/ep.json @@ -26,6 +26,7 @@ "eejsBlock_stickyContainer": "ep_etherpad-lite/node/chat", "handleMessage": "ep_etherpad-lite/node/chat", "padCheck": "ep_etherpad-lite/node/chat", + "padCopy": "ep_etherpad-lite/node/chat", "padLoad": "ep_etherpad-lite/node/chat", "socketio": "ep_etherpad-lite/node/chat" } diff --git a/src/node/chat.js b/src/node/chat.js index 935607db9..570c4aff4 100644 --- a/src/node/chat.js +++ b/src/node/chat.js @@ -156,6 +156,19 @@ exports.padCheck = async (hookName, {pad}) => { for (const p of chats.batch(100).buffer(99)) await p; }; +exports.padCopy = async (hookName, {srcPad, dstPad}) => { + const {chatHead = -1} = srcPad; + dstPad.chatHead = chatHead; + const copyChat = async (i) => { + const val = await srcPad.db.get(`pad:${srcPad.id}:chat:${i}`); + await dstPad.db.set(`pad:${dstPad.id}:chat:${i}`, val); + }; + const ops = (function* () { + for (let i = 0; i <= chatHead; ++i) yield copyChat(i); + })(); + for (const op of new Stream(ops).batch(100).buffer(99)) await op; +}; + exports.padLoad = async (hookName, {pad}) => { if (!('chatHead' in pad)) pad.chatHead = -1; }; diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index ee080b112..b16cf8de8 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -372,7 +372,6 @@ class Pad { const promises = (function* () { yield copyRecord(''); yield* Stream.range(0, this.head + 1).map((i) => copyRecord(`:revs:${i}`)); - yield* Stream.range(0, this.chatHead + 1).map((i) => copyRecord(`:chat:${i}`)); yield this.copyAuthorInfoToDestinationPad(destinationID); if (destGroupID) yield db.setSub(`group:${destGroupID}`, ['pads', destinationID], 1); }).call(this);