PadMessageHandler: Don't send USER_NEWINFO about unknown authors

When a new client opens a socket.io connection and sends a
CLIENT_READY message, Etherpad sends the new client a bunch of
USER_NEWINFO messages, one per other user already connected to the
pad. When iterating over the other users, filter out those without an
author ID or missing from the global authors database.
This commit is contained in:
Richard Hansen 2020-11-25 17:17:26 -05:00 committed by John McLear
parent 53bc80e381
commit ef7ae15722

View file

@ -1124,20 +1124,25 @@ async function handleClientReady(socket, message, authorID) {
if (sessionInfo == null) return;
// get the authorname & colorId
const author = sessionInfo.author;
const cached = historicalAuthorData[author];
const authorId = sessionInfo.author;
// The authorId of this other user might be unknown if the other user just connected and has
// not yet sent a CLIENT_READY message.
if (authorId == null) return;
// reuse previously created cache of author's data
let authorInfo = cached ? cached : (await authorManager.getAuthor(author));
const authorInfo = historicalAuthorData[authorId] || await authorManager.getAuthor(authorId);
if (authorInfo == null) {
messageLogger.error(
`Author ${authorId} connected via socket.io session ${roomSocket.id} is missing from ` +
'the global author database. This should never happen because the author ID is ' +
'generated by the same code that adds the author to the database.');
// Don't bother telling the new user about this mystery author.
return;
}
// default fallback color to use if authorInfo.colorId is null
const defaultColor = '#daf0b2';
if (!authorInfo) {
console.warn('handleClientReady(): no authorInfo parameter was received. Default values are going to be used. See issue #3612. This can be caused by a user clicking undo after clearing all authorship colors see #2802');
authorInfo = {};
}
// For some reason sometimes name isn't set
// Catch this issue here and use a fixed name.
if (!authorInfo.name) {
@ -1162,7 +1167,7 @@ async function handleClientReady(socket, message, authorID) {
colorId: authorInfo.colorId,
name: authorInfo.name,
userAgent: 'Anonymous',
userId: author,
userId: authorId,
},
},
};