mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
chat: Move .etherpad
import/export handling to chat.js
This commit is contained in:
parent
bc06ef87bb
commit
310a371234
4 changed files with 34 additions and 2 deletions
|
@ -24,7 +24,9 @@
|
|||
"clientVars": "ep_etherpad-lite/node/chat",
|
||||
"eejsBlock_mySettings": "ep_etherpad-lite/node/chat",
|
||||
"eejsBlock_stickyContainer": "ep_etherpad-lite/node/chat",
|
||||
"exportEtherpad": "ep_etherpad-lite/node/chat",
|
||||
"handleMessage": "ep_etherpad-lite/node/chat",
|
||||
"importEtherpad": "ep_etherpad-lite/node/chat",
|
||||
"padCheck": "ep_etherpad-lite/node/chat",
|
||||
"padCopy": "ep_etherpad-lite/node/chat",
|
||||
"padLoad": "ep_etherpad-lite/node/chat",
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
const ChatMessage = require('../static/js/ChatMessage');
|
||||
const CustomError = require('./utils/customError');
|
||||
const Stream = require('./utils/Stream');
|
||||
const api = require('./db/API');
|
||||
const assert = require('assert').strict;
|
||||
const authorManager = require('./db/AuthorManager');
|
||||
|
@ -106,6 +107,21 @@ exports.eejsBlock_stickyContainer = (hookName, context) => {
|
|||
/* eslint-enable max-len */
|
||||
};
|
||||
|
||||
exports.exportEtherpad = async (hookName, {pad, data, dstPadId}) => {
|
||||
const ops = (function* () {
|
||||
const {chatHead = -1} = pad;
|
||||
data[`pad:${dstPadId}`].chatHead = chatHead;
|
||||
for (let i = 0; i <= chatHead; ++i) {
|
||||
yield (async () => {
|
||||
const v = await pad.db.get(`pad:${pad.id}:chat:${i}`);
|
||||
if (v == null) return;
|
||||
data[`pad:${dstPadId}:chat:${i}`] = v;
|
||||
})();
|
||||
}
|
||||
})();
|
||||
for (const op of new Stream(ops).batch(100).buffer(99)) await op;
|
||||
};
|
||||
|
||||
exports.handleMessage = async (hookName, {message, sessionInfo, socket}) => {
|
||||
const {authorId, padId, readOnly} = sessionInfo;
|
||||
if (message.type !== 'COLLABROOM' || readOnly) return;
|
||||
|
@ -140,6 +156,19 @@ exports.handleMessage = async (hookName, {message, sessionInfo, socket}) => {
|
|||
return null; // Important! Returning null (not undefined!) stops further processing.
|
||||
};
|
||||
|
||||
exports.importEtherpad = async (hookName, {pad, data, srcPadId}) => {
|
||||
const ops = (function* () {
|
||||
const {chatHead = -1} = data[`pad:${srcPadId}`];
|
||||
pad.chatHead = chatHead;
|
||||
for (let i = 0; i <= chatHead; ++i) {
|
||||
const v = data[`pad:${srcPadId}:chat:${i}`];
|
||||
if (v == null) continue;
|
||||
yield pad.db.set(`pad:${pad.id}:chat:${i}`, v);
|
||||
}
|
||||
})();
|
||||
for (const op of new Stream(ops).batch(100).buffer(99)) await op;
|
||||
};
|
||||
|
||||
exports.padCheck = async (hookName, {pad}) => {
|
||||
assert(pad.chatHead != null);
|
||||
assert(Number.isInteger(pad.chatHead));
|
||||
|
|
|
@ -50,7 +50,6 @@ exports.getPadRaw = async (padId, readOnlyId) => {
|
|||
})()];
|
||||
}
|
||||
for (let i = 0; i <= pad.head; ++i) yield [`${dstPfx}:revs:${i}`, pad.getRevision(i)];
|
||||
for (let i = 0; i <= pad.chatHead; ++i) yield [`${dstPfx}:chat:${i}`, pad.getChatMessage(i)];
|
||||
for (const gen of pluginRecords) yield* gen;
|
||||
})();
|
||||
const data = {[dstPfx]: pad};
|
||||
|
|
|
@ -74,7 +74,9 @@ exports.setPadRaw = async (padId, r, authorId = '') => {
|
|||
return;
|
||||
}
|
||||
value.padIDs = {[padId]: 1};
|
||||
} else if (padKeyPrefixes.includes(prefix)) {
|
||||
} else if (padKeyPrefixes.includes(prefix) &&
|
||||
// Chat message handling was moved to the importEtherpad hook.
|
||||
(keyParts[0] !== 'pad' || keyParts[2] !== 'chat')) {
|
||||
checkOriginalPadId(id);
|
||||
if (prefix === 'pad' && keyParts.length === 2) {
|
||||
const pool = new AttributePool().fromJsonable(value.pool);
|
||||
|
|
Loading…
Reference in a new issue