chat: Move message copy to `padCopy` hook

rhansen-chat
Richard Hansen 2022-04-08 04:30:31 -04:00
parent 01f1a8b75e
commit bd621043ff
3 changed files with 14 additions and 1 deletions

View File

@ -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"
}

View File

@ -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;
};

View File

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