mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
chat: Move message checking to padCheck
hook
This commit is contained in:
parent
cdea600acc
commit
42c22ce28d
3 changed files with 19 additions and 17 deletions
|
@ -25,6 +25,7 @@
|
||||||
"eejsBlock_mySettings": "ep_etherpad-lite/node/chat",
|
"eejsBlock_mySettings": "ep_etherpad-lite/node/chat",
|
||||||
"eejsBlock_stickyContainer": "ep_etherpad-lite/node/chat",
|
"eejsBlock_stickyContainer": "ep_etherpad-lite/node/chat",
|
||||||
"handleMessage": "ep_etherpad-lite/node/chat",
|
"handleMessage": "ep_etherpad-lite/node/chat",
|
||||||
|
"padCheck": "ep_etherpad-lite/node/chat",
|
||||||
"socketio": "ep_etherpad-lite/node/chat"
|
"socketio": "ep_etherpad-lite/node/chat"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
const ChatMessage = require('../static/js/ChatMessage');
|
const ChatMessage = require('../static/js/ChatMessage');
|
||||||
const api = require('./db/API');
|
const api = require('./db/API');
|
||||||
|
const assert = require('assert').strict;
|
||||||
const authorManager = require('./db/AuthorManager');
|
const authorManager = require('./db/AuthorManager');
|
||||||
const hooks = require('../static/js/pluginfw/hooks.js');
|
const hooks = require('../static/js/pluginfw/hooks.js');
|
||||||
const pad = require('./db/Pad');
|
const pad = require('./db/Pad');
|
||||||
|
@ -138,6 +139,23 @@ exports.handleMessage = async (hookName, {message, sessionInfo, socket}) => {
|
||||||
return null; // Important! Returning null (not undefined!) stops further processing.
|
return null; // Important! Returning null (not undefined!) stops further processing.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.padCheck = async (hookName, {pad}) => {
|
||||||
|
assert(pad.chatHead != null);
|
||||||
|
assert(Number.isInteger(pad.chatHead));
|
||||||
|
assert(pad.chatHead >= -1);
|
||||||
|
const chats = Stream.range(0, pad.chatHead).map(async (c) => {
|
||||||
|
try {
|
||||||
|
const msg = await getChatMessage(pad, c);
|
||||||
|
assert(msg != null);
|
||||||
|
assert(msg instanceof ChatMessage);
|
||||||
|
} catch (err) {
|
||||||
|
err.message = `(pad ${pad.id} chat message ${c}) ${err.message}`;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (const p of chats.batch(100).buffer(99)) await p;
|
||||||
|
};
|
||||||
|
|
||||||
exports.socketio = (hookName, {io}) => {
|
exports.socketio = (hookName, {io}) => {
|
||||||
socketio = io;
|
socketio = io;
|
||||||
};
|
};
|
||||||
|
|
|
@ -690,23 +690,6 @@ class Pad {
|
||||||
assert.deepEqual(this.atext, atext);
|
assert.deepEqual(this.atext, atext);
|
||||||
assert.deepEqual(this.getAllAuthors().sort(), [...authorIds].sort());
|
assert.deepEqual(this.getAllAuthors().sort(), [...authorIds].sort());
|
||||||
|
|
||||||
assert(this.chatHead != null);
|
|
||||||
assert(Number.isInteger(this.chatHead));
|
|
||||||
assert(this.chatHead >= -1);
|
|
||||||
const chats = Stream.range(0, this.chatHead + 1)
|
|
||||||
.map(async (c) => {
|
|
||||||
try {
|
|
||||||
const msg = await chat.getChatMessage(this, c);
|
|
||||||
assert(msg != null);
|
|
||||||
assert(msg instanceof ChatMessage);
|
|
||||||
} catch (err) {
|
|
||||||
err.message = `(pad ${this.id} chat message ${c}) ${err.message}`;
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.batch(100).buffer(99);
|
|
||||||
for (const p of chats) await p;
|
|
||||||
|
|
||||||
await hooks.aCallAll('padCheck', {pad: this});
|
await hooks.aCallAll('padCheck', {pad: this});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue