chat: Move message deletion to `padRemove` hook

rhansen-chat
Richard Hansen 2022-04-08 04:37:15 -04:00
parent bd621043ff
commit b6bcc092ed
3 changed files with 9 additions and 5 deletions

View File

@ -28,6 +28,7 @@
"padCheck": "ep_etherpad-lite/node/chat",
"padCopy": "ep_etherpad-lite/node/chat",
"padLoad": "ep_etherpad-lite/node/chat",
"padRemove": "ep_etherpad-lite/node/chat",
"socketio": "ep_etherpad-lite/node/chat"
}
},

View File

@ -173,6 +173,14 @@ exports.padLoad = async (hookName, {pad}) => {
if (!('chatHead' in pad)) pad.chatHead = -1;
};
exports.padRemove = async (hookName, {pad}) => {
const ops = (function* () {
const {chatHead = -1} = pad;
for (let i = 0; i <= chatHead; ++i) yield pad.db.remove(`pad:${pad.id}:chat:${i}`);
})();
for (const op of new Stream(ops).batch(100).buffer(99)) await op;
};
exports.socketio = (hookName, {io}) => {
socketio = io;
};

View File

@ -530,11 +530,6 @@ class Pad {
}));
p.push(db.remove(`pad2readonly:${padID}`));
// delete all chat messages
p.push(promises.timesLimit(this.chatHead + 1, 500, async (i) => {
await this.db.remove(`pad:${this.id}:chat:${i}`, null);
}));
// delete all revisions
p.push(promises.timesLimit(this.head + 1, 500, async (i) => {
await this.db.remove(`pad:${this.id}:revs:${i}`, null);