mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
PadMessageHandler: Populate session info as early as possible
This commit is contained in:
parent
b7de24c85f
commit
c98910e1c5
1 changed files with 10 additions and 14 deletions
|
@ -806,10 +806,13 @@ const handleClientReady = async (socket, message) => {
|
||||||
// Check if the user has already disconnected.
|
// Check if the user has already disconnected.
|
||||||
if (sessionInfo == null) return;
|
if (sessionInfo == null) return;
|
||||||
|
|
||||||
await hooks.aCallAll('clientReady', message);
|
|
||||||
|
|
||||||
// Get ro/rw id:s
|
|
||||||
const padIds = await readOnlyManager.getIds(sessionInfo.auth.padID);
|
const padIds = await readOnlyManager.getIds(sessionInfo.auth.padID);
|
||||||
|
sessionInfo.padId = padIds.padId;
|
||||||
|
sessionInfo.readOnlyPadId = padIds.readOnlyPadId;
|
||||||
|
sessionInfo.readonly =
|
||||||
|
padIds.readonly || !webaccess.userCanModify(sessionInfo.auth.padID, socket.client.request);
|
||||||
|
|
||||||
|
await hooks.aCallAll('clientReady', message);
|
||||||
|
|
||||||
// get all authordata of this new user
|
// get all authordata of this new user
|
||||||
assert(sessionInfo.author);
|
assert(sessionInfo.author);
|
||||||
|
@ -817,7 +820,7 @@ const handleClientReady = async (socket, message) => {
|
||||||
await authorManager.getAuthor(sessionInfo.author);
|
await authorManager.getAuthor(sessionInfo.author);
|
||||||
|
|
||||||
// load the pad-object from the database
|
// load the pad-object from the database
|
||||||
const pad = await padManager.getPad(padIds.padId);
|
const pad = await padManager.getPad(sessionInfo.padId);
|
||||||
|
|
||||||
// these db requests all need the pad object (timestamp of latest revision, author data)
|
// these db requests all need the pad object (timestamp of latest revision, author data)
|
||||||
const authors = pad.getAllAuthors();
|
const authors = pad.getAllAuthors();
|
||||||
|
@ -840,9 +843,8 @@ const handleClientReady = async (socket, message) => {
|
||||||
|
|
||||||
// glue the clientVars together, send them and tell the other clients that a new one is there
|
// glue the clientVars together, send them and tell the other clients that a new one is there
|
||||||
|
|
||||||
// Check that the client is still here. It might have disconnected between callbacks.
|
// Check if the user has disconnected during any of the above awaits.
|
||||||
const sessionInfo = sessioninfos[socket.id];
|
if (sessionInfo !== sessioninfos[socket.id]) return;
|
||||||
if (sessionInfo == null) return;
|
|
||||||
|
|
||||||
// Check if this author is already on the pad, if yes, kick the other sessions!
|
// Check if this author is already on the pad, if yes, kick the other sessions!
|
||||||
const roomSockets = _getRoomSockets(pad.id);
|
const roomSockets = _getRoomSockets(pad.id);
|
||||||
|
@ -854,17 +856,11 @@ const handleClientReady = async (socket, message) => {
|
||||||
if (sinfo && sinfo.author === sessionInfo.author) {
|
if (sinfo && sinfo.author === sessionInfo.author) {
|
||||||
// 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[otherSocket.id] = {};
|
sessioninfos[otherSocket.id] = {};
|
||||||
otherSocket.leave(padIds.padId);
|
otherSocket.leave(sessionInfo.padId);
|
||||||
otherSocket.json.send({disconnect: 'userdup'});
|
otherSocket.json.send({disconnect: 'userdup'});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save in sessioninfos that this session belonges to this pad
|
|
||||||
sessionInfo.padId = padIds.padId;
|
|
||||||
sessionInfo.readOnlyPadId = padIds.readOnlyPadId;
|
|
||||||
sessionInfo.readonly =
|
|
||||||
padIds.readonly || !webaccess.userCanModify(sessionInfo.auth.padID, socket.client.request);
|
|
||||||
|
|
||||||
const {session: {user} = {}} = socket.client.request;
|
const {session: {user} = {}} = socket.client.request;
|
||||||
/* eslint-disable prefer-template -- it doesn't support breaking across multiple lines */
|
/* eslint-disable prefer-template -- it doesn't support breaking across multiple lines */
|
||||||
accessLogger.info(`[${pad.head > 0 ? 'ENTER' : 'CREATE'}]` +
|
accessLogger.info(`[${pad.head > 0 ? 'ENTER' : 'CREATE'}]` +
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue