Delete dead SERVER_MESSAGE and guest handling code

None of this code seems to be reachable. Hopefully no plugins expect
it to exist.
pull/4587/head
Richard Hansen 2020-12-18 02:31:08 -05:00 committed by John McLear
parent 794dfb1863
commit 7e50fc2ab5
7 changed files with 11 additions and 242 deletions

View File

@ -172,9 +172,6 @@
"pad.savedrevs.timeslider": "You can see saved revisions by visiting the timeslider",
"pad.userlist.entername": "Enter your name",
"pad.userlist.unnamed": "unnamed",
"pad.userlist.guest": "Guest",
"pad.userlist.deny": "Deny",
"pad.userlist.approve": "Approve",
"pad.editbar.clearcolors": "Clear authorship colors on entire document? This cannot be undone",
"pad.impexp.importbutton": "Import Now",

View File

@ -1013,9 +1013,7 @@ async function handleClientReady(socket, message, authorID) {
},
automaticReconnectionTimeout: settings.automaticReconnectionTimeout,
initialRevisionList: [],
initialOptions: {
guestPolicy: 'deny',
},
initialOptions: {},
savedRevisions: pad.getSavedRevisions(),
collab_client_vars: {
initialAttributedText: atext,
@ -1028,7 +1026,6 @@ async function handleClientReady(socket, message, authorID) {
},
colorPalette: authorManager.getColorPalette(),
clientIp: '127.0.0.1',
userIsGuest: true,
userColor: authorColorId,
padId: message.padId,
padOptions: settings.padOptions,

View File

@ -72,7 +72,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
onClientMessage() {},
onInternalAction() {},
onConnectionTrouble() {},
onServerMessage() {},
};
if (browser.firefox) {
// Prevent "escape" from taking effect and canceling a comet connection;
@ -392,8 +391,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
// 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'); }
} else if (msg.type == 'SERVER_MESSAGE') {
callbacks.onServerMessage(msg.payload);
}
// HACKISH: User messages do not have "payload" but "userInfo", so that all "handleClientMessage_USER_" hooks would work, populate payload
@ -586,9 +583,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
setOnConnectionTrouble(cb) {
callbacks.onConnectionTrouble = cb;
},
setOnServerMessage(cb) {
callbacks.onServerMessage = cb;
},
updateUserInfo: defer(updateUserInfo),
handleMessageFromServer,
getConnectedUsers,

View File

@ -337,9 +337,6 @@ var pad = {
getPrivilege(name) {
return clientVars.accountPrivs[name];
},
getUserIsGuest() {
return clientVars.userIsGuest;
},
getUserId() {
return pad.myUserInfo.userId;
},
@ -440,7 +437,6 @@ var pad = {
pad.collabClient.setOnUpdateUserInfo(pad.handleUserUpdate);
pad.collabClient.setOnUserLeave(pad.handleUserLeave);
pad.collabClient.setOnClientMessage(pad.handleClientMessage);
pad.collabClient.setOnServerMessage(pad.handleServerMessage);
pad.collabClient.setOnChannelStateChange(pad.handleChannelStateChange);
pad.collabClient.setOnInternalAction(pad.handleCollabAction);
@ -537,18 +533,11 @@ var pad = {
}
padeditor.setViewOptions(pad.padOptions.view);
}
if (opts.guestPolicy) {
// order important here
pad.padOptions.guestPolicy = opts.guestPolicy;
}
},
getPadOptions() {
// caller shouldn't mutate the object
return pad.padOptions;
},
isPadPublic() {
return pad.getPadOptions().guestPolicy == 'allow';
},
suggestUserName(userId, name) {
pad.collabClient.sendClientMessage(
{
@ -579,9 +568,6 @@ var pad = {
} else if (msg.type == 'padoptions') {
const opts = msg.options;
pad.handleOptionsChange(opts);
} else if (msg.type == 'guestanswer') {
// someone answered a prompt, remove it
paduserlist.removeGuestPrompt(msg.guestId);
}
},
dmesg(m) {
@ -594,21 +580,6 @@ var pad = {
}
}
},
handleServerMessage(m) {
if (m.type == 'NOTICE') {
if (m.text) {
alertBar.displayMessage((abar) => {
abar.find('#servermsgdate').text(` (${padutils.simpleDateTime(new Date())})`);
abar.find('#servermsgtext').text(m.text);
});
}
if (m.js) {
window['ev' + 'al'](m.js);
}
} else if (m.type == 'GUEST_PROMPT') {
paduserlist.showGuestPrompt(m.userId, m.displayName);
}
},
handleChannelStateChange(newState, message) {
const oldFullyConnected = !!padconnectionstatus.isFullyConnected();
const wasConnecting = (padconnectionstatus.getStatus().what == 'connecting');
@ -695,9 +666,6 @@ var pad = {
padeditbar.setSyncStatus('done');
}
},
hideServerMessage() {
alertBar.hideMessage();
},
asyncSendDiagnosticInfo() {
window.setTimeout(() => {
$.ajax(
@ -743,35 +711,6 @@ var pad = {
},
};
var alertBar = (function () {
const animator = padutils.makeShowHideAnimator(arriveAtAnimationState, false, 25, 400);
function arriveAtAnimationState(state) {
if (state == -1) {
$('#alertbar').css('opacity', 0).css('display', 'block');
} else if (state == 0) {
$('#alertbar').css('opacity', 1);
} else if (state == 1) {
$('#alertbar').css('opacity', 0).css('display', 'none');
} else if (state < 0) {
$('#alertbar').css('opacity', state + 1);
} else if (state > 0) {
$('#alertbar').css('opacity', 1 - state);
}
}
const self = {
displayMessage(setupFunc) {
animator.show();
setupFunc($('#alertbar'));
},
hideMessage() {
animator.hide();
},
};
return self;
}());
function init() {
return pad.init();
}
@ -794,4 +733,3 @@ exports.getUrlVars = getUrlVars;
exports.handshake = handshake;
exports.pad = pad;
exports.init = init;
exports.alertBar = alertBar;

View File

@ -352,26 +352,6 @@ const paduserlist = (function () {
jqueryNode.removeAttr('disabled').addClass('editable');
}
const knocksToIgnore = {};
let guestPromptFlashState = 0;
const guestPromptFlash = padutils.makeAnimationScheduler(
() => {
const prompts = $('#guestprompts .guestprompt');
if (prompts.length == 0) {
return false; // no more to do
}
guestPromptFlashState = 1 - guestPromptFlashState;
if (guestPromptFlashState) {
prompts.css('background', '#ffa');
} else {
prompts.css('background', '#ffe');
}
return true;
}, 1000);
var pad = undefined;
var self = {
init(myInitialUserInfo, _pad) {
@ -383,18 +363,16 @@ const paduserlist = (function () {
$('#otheruserstable tr').remove();
if (pad.getUserIsGuest()) {
$('#myusernameedit').addClass('myusernameedithoverable');
setUpEditable($('#myusernameedit'), () => myUserInfo.name || '', (newValue) => {
myUserInfo.name = newValue;
pad.notifyChangeName(newValue);
// wrap with setTimeout to do later because we get
// a double "blur" fire in IE...
window.setTimeout(() => {
self.renderMyUserInfo();
}, 0);
});
}
$('#myusernameedit').addClass('myusernameedithoverable');
setUpEditable($('#myusernameedit'), () => myUserInfo.name || '', (newValue) => {
myUserInfo.name = newValue;
pad.notifyChangeName(newValue);
// wrap with setTimeout to do later because we get
// a double "blur" fire in IE...
window.setTimeout(() => {
self.renderMyUserInfo();
}, 0);
});
// color picker
$('#myswatchbox').click(showColorPicker);
@ -551,56 +529,6 @@ const paduserlist = (function () {
self.updateNumberOfOnlineUsers();
},
showGuestPrompt(userId, displayName) {
if (knocksToIgnore[userId]) {
return;
}
const encodedUserId = padutils.encodeUserId(userId);
const actionName = `hide-guest-prompt-${encodedUserId}`;
padutils.cancelActions(actionName);
let box = $(`#guestprompt-${encodedUserId}`);
if (box.length == 0) {
// make guest prompt box
box = $(`<div id="${padutils.escapeHtml(`guestprompt-${encodedUserId}`)}" class="guestprompt"><div class="choices"><a href="${padutils.escapeHtml(`javascript:void(require(${JSON.stringify(module.id)}).paduserlist.answerGuestPrompt(${JSON.stringify(encodedUserId)},false))`)}">${_('pad.userlist.deny')}</a> <a href="${padutils.escapeHtml(`javascript:void(require(${JSON.stringify(module.id)}).paduserlist.answerGuestPrompt(${JSON.stringify(encodedUserId)},true))`)}">${_('pad.userlist.approve')}</a></div><div class="guestname"><strong>${_('pad.userlist.guest')}:</strong> ${padutils.escapeHtml(displayName)}</div></div>`);
$('#guestprompts').append(box);
} else {
// update display name
box.find('.guestname').html(`<strong>${_('pad.userlist.guest')}:</strong> ${padutils.escapeHtml(displayName)}`);
}
const hideLater = padutils.getCancellableAction(actionName, () => {
self.removeGuestPrompt(userId);
});
window.setTimeout(hideLater, 15000); // time-out with no knock
guestPromptFlash.scheduleAnimation();
},
removeGuestPrompt(userId) {
const box = $(`#guestprompt-${padutils.encodeUserId(userId)}`);
// remove ID now so a new knock by same user gets new, unfaded box
box.removeAttr('id').fadeOut('fast', () => {
box.remove();
});
knocksToIgnore[userId] = true;
window.setTimeout(() => {
delete knocksToIgnore[userId];
}, 5000);
},
answerGuestPrompt(encodedUserId, approve) {
const guestId = padutils.decodeUserId(encodedUserId);
const msg = {
type: 'guestanswer',
authId: pad.getUserId(),
guestId,
answer: (approve ? 'approved' : 'denied'),
};
pad.sendClientMessage(msg);
self.removeGuestPrompt(guestId);
},
renderMyUserInfo() {
if (myUserInfo.name) {
$('#myusernameedit').removeClass('editempty').val(myUserInfo.name);

View File

@ -247,90 +247,6 @@ const padutils = {
};
return {scheduleAnimation};
},
makeShowHideAnimator: (funcToArriveAtState, initiallyShown, fps, totalMs) => {
let animationState = (initiallyShown ? 0 : -2); // -2 hidden, -1 to 0 fade in, 0 to 1 fade out
const animationFrameDelay = 1000 / fps;
const animationStep = animationFrameDelay / totalMs;
const animateOneStep = () => {
if (animationState < -1 || animationState === 0) {
return false;
} else if (animationState < 0) {
// animate show
animationState += animationStep;
if (animationState >= 0) {
animationState = 0;
funcToArriveAtState(animationState);
return false;
} else {
funcToArriveAtState(animationState);
return true;
}
} else if (animationState > 0) {
// animate hide
animationState += animationStep;
if (animationState >= 1) {
animationState = 1;
funcToArriveAtState(animationState);
animationState = -2;
return false;
} else {
funcToArriveAtState(animationState);
return true;
}
}
};
const scheduleAnimation =
padutils.makeAnimationScheduler(animateOneStep, animationFrameDelay).scheduleAnimation;
return {
show: () => {
animationState = -1;
funcToArriveAtState(animationState);
scheduleAnimation();
},
quickShow: () => { // start showing without losing any fade-in progress
if (animationState < -1) {
animationState = -1;
} else if (animationState > 0) {
animationState = Math.max(-1, Math.min(0, -animationState));
}
funcToArriveAtState(animationState);
scheduleAnimation();
},
hide: () => {
if (animationState >= -1 && animationState <= 0) {
animationState = 1e-6;
scheduleAnimation();
}
},
};
},
_nextActionId: 1,
uncanceledActions: {},
getCancellableAction: (actionType, actionFunc) => {
let o = padutils.uncanceledActions[actionType];
if (!o) {
o = {};
padutils.uncanceledActions[actionType] = o;
}
const actionId = (padutils._nextActionId++);
o[actionId] = true;
return () => {
const p = padutils.uncanceledActions[actionType];
if (p && p[actionId]) {
actionFunc();
}
};
},
cancelActions: (actionType) => {
const o = padutils.uncanceledActions[actionType];
if (o) {
// clear it
delete padutils.uncanceledActions[actionType];
}
},
makeFieldLabeledWhenEmpty: (field, labelText) => {
field = $(field);

View File

@ -353,7 +353,6 @@
</div>
</div>
<div id="otherusers" aria-role="document">
<div id="guestprompts"></div>
<table id="otheruserstable" cellspacing="0" cellpadding="0" border="0">
<tr><td></td></tr>
</table>