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);