PadMessageHandler: Simplify handleClientReady a bit

Before, this function referred to the same author ID in different ways
in different places. Use one spelling to make the code easier to read.
This commit is contained in:
Richard Hansen 2020-09-02 19:33:08 -04:00 committed by John McLear
parent ed3c82e8c3
commit d4db091d1d

View file

@ -894,8 +894,8 @@ async function handleClientReady(client, message)
let padIds = await readOnlyManager.getIds(message.padId); let padIds = await readOnlyManager.getIds(message.padId);
// FIXME: Allow to override readwrite access with readonly // FIXME: Allow to override readwrite access with readonly
let statusObject = await securityManager.checkAccess(padIds.padId, message.sessionID, message.token, message.password); const {accessStatus, authorID} = await securityManager.checkAccess(
let accessStatus = statusObject.accessStatus; padIds.padId, message.sessionID, message.token, message.password);
// no access, send the client a message that tells him why // no access, send the client a message that tells him why
if (accessStatus !== "grant") { if (accessStatus !== "grant") {
@ -903,11 +903,9 @@ async function handleClientReady(client, message)
return; return;
} }
let author = statusObject.authorID;
// get all authordata of this new user // get all authordata of this new user
assert(author); assert(authorID);
let value = await authorManager.getAuthor(author); let value = await authorManager.getAuthor(authorID);
let authorColorId = value.colorId; let authorColorId = value.colorId;
let authorName = value.name; let authorName = value.name;
@ -933,7 +931,7 @@ async function handleClientReady(client, message)
})); }));
let thisUserHasEditedThisPad = false; let thisUserHasEditedThisPad = false;
if (historicalAuthorData[statusObject.authorID]) { if (historicalAuthorData[authorID]) {
/* /*
* This flag is set to true when a user contributes to a specific pad for * This flag is set to true when a user contributes to a specific pad for
* the first time. It is used for deciding if importing to that pad is * the first time. It is used for deciding if importing to that pad is
@ -954,7 +952,7 @@ async function handleClientReady(client, message)
for (let client of roomClients) { for (let client of roomClients) {
let sinfo = sessioninfos[client.id]; let sinfo = sessioninfos[client.id];
if (sinfo && sinfo.author == author) { if (sinfo && sinfo.author == authorID) {
// fix user's counter, works on page refresh or if user closes browser window and then rejoins // fix user's counter, works on page refresh or if user closes browser window and then rejoins
sessioninfos[client.id] = {}; sessioninfos[client.id] = {};
client.leave(padIds.padId); client.leave(padIds.padId);
@ -1104,7 +1102,7 @@ async function handleClientReady(client, message)
"readOnlyId": padIds.readOnlyPadId, "readOnlyId": padIds.readOnlyPadId,
"readonly": padIds.readonly, "readonly": padIds.readonly,
"serverTimestamp": Date.now(), "serverTimestamp": Date.now(),
"userId": author, "userId": authorID,
"abiwordAvailable": settings.abiwordAvailable(), "abiwordAvailable": settings.abiwordAvailable(),
"sofficeAvailable": settings.sofficeAvailable(), "sofficeAvailable": settings.sofficeAvailable(),
"exportAvailable": settings.exportAvailable(), "exportAvailable": settings.exportAvailable(),
@ -1149,7 +1147,7 @@ async function handleClientReady(client, message)
// Save the current revision in sessioninfos, should be the same as in clientVars // Save the current revision in sessioninfos, should be the same as in clientVars
sessioninfos[client.id].rev = pad.getHeadRevisionNumber(); sessioninfos[client.id].rev = pad.getHeadRevisionNumber();
sessioninfos[client.id].author = author; sessioninfos[client.id].author = authorID;
// prepare the notification for the other users on the pad, that this user joined // prepare the notification for the other users on the pad, that this user joined
let messageToTheOtherUsers = { let messageToTheOtherUsers = {
@ -1160,7 +1158,7 @@ async function handleClientReady(client, message)
"ip": "127.0.0.1", "ip": "127.0.0.1",
"colorId": authorColorId, "colorId": authorColorId,
"userAgent": "Anonymous", "userAgent": "Anonymous",
"userId": author "userId": authorID,
} }
} }
}; };