mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 16:36:15 -04:00
chat: Move chat message handling to chat.js
This commit is contained in:
parent
870191f622
commit
8d3a6e5ef9
3 changed files with 29 additions and 24 deletions
|
@ -15,7 +15,9 @@
|
||||||
{
|
{
|
||||||
"name": "chat",
|
"name": "chat",
|
||||||
"client_hooks": {
|
"client_hooks": {
|
||||||
"aceKeyEvent": "ep_etherpad-lite/static/js/chat"
|
"aceKeyEvent": "ep_etherpad-lite/static/js/chat",
|
||||||
|
"handleClientMessage_CHAT_MESSAGE": "ep_etherpad-lite/static/js/chat",
|
||||||
|
"handleClientMessage_CHAT_MESSAGES": "ep_etherpad-lite/static/js/chat"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -306,3 +306,29 @@ exports.aceKeyEvent = (hookName, {evt}) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.handleClientMessage_CHAT_MESSAGE = (hookName, {msg}) => {
|
||||||
|
exports.chat.addMessage(msg.message, true, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.handleClientMessage_CHAT_MESSAGES = (hookName, {msg}) => {
|
||||||
|
for (let i = msg.messages.length - 1; i >= 0; i--) {
|
||||||
|
exports.chat.addMessage(msg.messages[i], true, true);
|
||||||
|
}
|
||||||
|
if (!exports.chat.gotInitalMessages) {
|
||||||
|
exports.chat.scrollDown();
|
||||||
|
exports.chat.gotInitalMessages = true;
|
||||||
|
exports.chat.historyPointer = clientVars.chatHead - msg.messages.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// messages are loaded, so hide the loading-ball
|
||||||
|
$('#chatloadmessagesball').css('display', 'none');
|
||||||
|
|
||||||
|
// there are less than 100 messages or we reached the top
|
||||||
|
if (exports.chat.historyPointer <= 0) {
|
||||||
|
$('#chatloadmessagesbutton').css('display', 'none');
|
||||||
|
} else {
|
||||||
|
// there are still more messages, re-show the load-button
|
||||||
|
$('#chatloadmessagesbutton').css('display', 'block');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const chat = require('./chat').chat;
|
|
||||||
const hooks = require('./pluginfw/hooks');
|
const hooks = require('./pluginfw/hooks');
|
||||||
const browser = require('./vendors/browser');
|
const browser = require('./vendors/browser');
|
||||||
|
|
||||||
|
@ -266,28 +265,6 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
|
||||||
}
|
}
|
||||||
} else if (msg.type === 'CLIENT_MESSAGE') {
|
} else if (msg.type === 'CLIENT_MESSAGE') {
|
||||||
callbacks.onClientMessage(msg.payload);
|
callbacks.onClientMessage(msg.payload);
|
||||||
} else if (msg.type === 'CHAT_MESSAGE') {
|
|
||||||
chat.addMessage(msg.message, true, false);
|
|
||||||
} else if (msg.type === 'CHAT_MESSAGES') {
|
|
||||||
for (let i = msg.messages.length - 1; i >= 0; i--) {
|
|
||||||
chat.addMessage(msg.messages[i], true, true);
|
|
||||||
}
|
|
||||||
if (!chat.gotInitalMessages) {
|
|
||||||
chat.scrollDown();
|
|
||||||
chat.gotInitalMessages = true;
|
|
||||||
chat.historyPointer = clientVars.chatHead - msg.messages.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
// messages are loaded, so hide the loading-ball
|
|
||||||
$('#chatloadmessagesball').css('display', 'none');
|
|
||||||
|
|
||||||
// there are less than 100 messages or we reached the top
|
|
||||||
if (chat.historyPointer <= 0) {
|
|
||||||
$('#chatloadmessagesbutton').css('display', 'none');
|
|
||||||
} else {
|
|
||||||
// there are still more messages, re-show the load-button
|
|
||||||
$('#chatloadmessagesbutton').css('display', 'block');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACKISH: User messages do not have "payload" but "userInfo", so that all
|
// HACKISH: User messages do not have "payload" but "userInfo", so that all
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue