mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
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:
parent
53bc80e381
commit
ef7ae15722
1 changed files with 14 additions and 9 deletions
|
@ -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,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue