mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 17:06:16 -04:00
chat: Plumb message object end to end
This will make it possible for future commits to add hooks that allow plugins to augment chat messages with arbitrary metadata.
This commit is contained in:
parent
f1f4ed7c58
commit
0f47ca9046
9 changed files with 113 additions and 42 deletions
|
@ -12,7 +12,7 @@ helper.spyOnSocketIO = () => {
|
|||
} else if (msg.data.type === 'USER_NEWINFO') {
|
||||
helper.userInfos.push(msg);
|
||||
} else if (msg.data.type === 'CHAT_MESSAGE') {
|
||||
helper.chatMessages.push(msg.data);
|
||||
helper.chatMessages.push(msg.data.message);
|
||||
} else if (msg.data.type === 'CHAT_MESSAGES') {
|
||||
helper.chatMessages.push(...msg.data.messages);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
describe('chat hooks', function () {
|
||||
let ChatMessage;
|
||||
let hooks;
|
||||
const hooksBackup = {};
|
||||
|
||||
const loadPad = async (opts = {}) => {
|
||||
await helper.aNewPad(opts);
|
||||
ChatMessage = helper.padChrome$.window.require('ep_etherpad-lite/static/js/ChatMessage');
|
||||
({hooks} = helper.padChrome$.window.require('ep_etherpad-lite/static/js/pluginfw/plugin_defs'));
|
||||
for (const [name, defs] of Object.entries(hooks)) {
|
||||
hooksBackup[name] = defs;
|
||||
|
@ -61,10 +63,10 @@ describe('chat hooks', function () {
|
|||
});
|
||||
}
|
||||
|
||||
it('message is an object', async function () {
|
||||
it('message is a ChatMessage object', async function () {
|
||||
await Promise.all([
|
||||
checkHook('chatNewMessage', ({message}) => {
|
||||
expect(message).to.be.an('object');
|
||||
expect(message).to.be.a(ChatMessage);
|
||||
}),
|
||||
helper.sendChatMessage(`${this.test.title}{enter}`),
|
||||
]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue