chat: Move chat init to chat.js

This commit is contained in:
Richard Hansen 2021-12-05 22:50:52 -05:00
parent 8d3a6e5ef9
commit a5c729af32
3 changed files with 43 additions and 41 deletions

View file

@ -17,7 +17,8 @@
"client_hooks": {
"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"
"handleClientMessage_CHAT_MESSAGES": "ep_etherpad-lite/static/js/chat",
"postAceInit": "ep_etherpad-lite/static/js/chat"
}
},
{

View file

@ -332,3 +332,43 @@ exports.handleClientMessage_CHAT_MESSAGES = (hookName, {msg}) => {
$('#chatloadmessagesbutton').css('display', 'block');
}
};
exports.postAceInit = async (hookName, {clientVars, pad}) => {
exports.chat.init(pad);
if (padcookie.getPref('chatAlwaysVisible')) {
exports.chat.stickToScreen(true);
$('#options-stickychat').prop('checked', true);
}
if (padcookie.getPref('chatAndUsers')) {
exports.chat.chatAndUsers(true);
$('#options-chatandusers').prop('checked', true);
}
// Prevent sticky chat or chat and users to be checked for mobiles
const checkChatAndUsersVisibility = (x) => {
if (!x.matches) return;
$('#options-chatandusers:checked').click();
$('#options-stickychat:checked').click();
};
const mobileMatch = window.matchMedia('(max-width: 800px)');
mobileMatch.addListener(checkChatAndUsersVisibility);
setTimeout(() => { checkChatAndUsersVisibility(mobileMatch); }, 0);
if (clientVars.chatHead !== -1) {
const chatHead = clientVars.chatHead;
const start = Math.max(chatHead - 100, 0);
pad.collabClient.sendMessage({type: 'GET_CHAT_MESSAGES', start, end: chatHead});
} else {
$('#chatloadmessagesbutton').css('display', 'none');
}
if (clientVars.readonly) {
exports.chat.hide();
$('#chatinput').attr('disabled', true);
$('#options-chatandusers').parent().hide();
$('#options-stickychat').parent().hide();
} else if (!pad.settings.hideChat) {
$('#chaticon').show();
}
};

View file

@ -367,8 +367,6 @@ const pad = {
},
_afterHandshake() {
pad.clientTimeOffset = Date.now() - clientVars.serverTimestamp;
// initialize the chat
chat.init(this);
getParams();
padcookie.init(); // initialize the cookies
@ -387,16 +385,6 @@ const pad = {
setTimeout(() => {
padeditor.ace.focus();
}, 0);
// if we have a cookie for always showing chat then show it
if (padcookie.getPref('chatAlwaysVisible')) {
chat.stickToScreen(true); // stick it to the screen
$('#options-stickychat').prop('checked', true); // set the checkbox to on
}
// if we have a cookie for always showing chat then show it
if (padcookie.getPref('chatAndUsers')) {
chat.chatAndUsers(true); // stick it to the screen
$('#options-chatandusers').prop('checked', true); // set the checkbox to on
}
if (padcookie.getPref('showAuthorshipColors') === false) {
pad.changeViewOption('showAuthorColors', false);
}
@ -409,17 +397,6 @@ const pad = {
pad.changeViewOption('padFontFamily', padcookie.getPref('padFontFamily'));
$('#viewfontmenu').val(padcookie.getPref('padFontFamily')).niceSelect('update');
// Prevent sticky chat or chat and users to be checked for mobiles
const checkChatAndUsersVisibility = (x) => {
if (x.matches) { // If media query matches
$('#options-chatandusers:checked').click();
$('#options-stickychat:checked').click();
}
};
const mobileMatch = window.matchMedia('(max-width: 800px)');
mobileMatch.addListener(checkChatAndUsersVisibility); // check if window resized
setTimeout(() => { checkChatAndUsersVisibility(mobileMatch); }, 0); // check now after load
$('#editorcontainer').addClass('initialized');
hooks.aCallAll('postAceInit', {ace: padeditor.ace, clientVars, pad});
@ -444,23 +421,7 @@ const pad = {
pad.collabClient.setOnChannelStateChange(pad.handleChannelStateChange);
pad.collabClient.setOnInternalAction(pad.handleCollabAction);
// load initial chat-messages
if (clientVars.chatHead !== -1) {
const chatHead = clientVars.chatHead;
const start = Math.max(chatHead - 100, 0);
pad.collabClient.sendMessage({type: 'GET_CHAT_MESSAGES', start, end: chatHead});
} else {
// there are no messages
$('#chatloadmessagesbutton').css('display', 'none');
}
if (window.clientVars.readonly) {
chat.hide();
$('#myusernameedit').attr('disabled', true);
$('#chatinput').attr('disabled', true);
$('#options-chatandusers').parent().hide();
$('#options-stickychat').parent().hide();
} else if (!settings.hideChat) { $('#chaticon').show(); }
if (window.clientVars.readonly) $('#myusernameedit').attr('disabled', true);
$('body').addClass(window.clientVars.readonly ? 'readonly' : 'readwrite');