mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
Merge pull request #12211 from overleaf/em-camel-case-real-time
Camel case variables in real-time GitOrigin-RevId: 0a35d2e39d54c258bed017ea4dcdbf9a19a2a9b1
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
/* eslint-disable
|
||||
camelcase,
|
||||
*/
|
||||
const async = require('async')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const logger = require('@overleaf/logger')
|
||||
@@ -20,52 +17,52 @@ module.exports = {
|
||||
// Use the same method for when a user connects, and when a user sends a cursor
|
||||
// update. This way we don't care if the connected_user key has expired when
|
||||
// we receive a cursor update.
|
||||
updateUserPosition(project_id, client_id, user, cursorData, callback) {
|
||||
logger.debug(
|
||||
{ project_id, client_id },
|
||||
'marking user as joined or connected'
|
||||
)
|
||||
updateUserPosition(projectId, clientId, user, cursorData, callback) {
|
||||
logger.debug({ projectId, clientId }, 'marking user as joined or connected')
|
||||
|
||||
const multi = rclient.multi()
|
||||
|
||||
multi.sadd(Keys.clientsInProject({ project_id }), client_id)
|
||||
multi.expire(Keys.clientsInProject({ project_id }), FOUR_DAYS_IN_S)
|
||||
multi.sadd(Keys.clientsInProject({ project_id: projectId }), clientId)
|
||||
multi.expire(
|
||||
Keys.clientsInProject({ project_id: projectId }),
|
||||
FOUR_DAYS_IN_S
|
||||
)
|
||||
|
||||
multi.hset(
|
||||
Keys.connectedUser({ project_id, client_id }),
|
||||
Keys.connectedUser({ project_id: projectId, client_id: clientId }),
|
||||
'last_updated_at',
|
||||
Date.now()
|
||||
)
|
||||
multi.hset(
|
||||
Keys.connectedUser({ project_id, client_id }),
|
||||
Keys.connectedUser({ project_id: projectId, client_id: clientId }),
|
||||
'user_id',
|
||||
user._id
|
||||
)
|
||||
multi.hset(
|
||||
Keys.connectedUser({ project_id, client_id }),
|
||||
Keys.connectedUser({ project_id: projectId, client_id: clientId }),
|
||||
'first_name',
|
||||
user.first_name || ''
|
||||
)
|
||||
multi.hset(
|
||||
Keys.connectedUser({ project_id, client_id }),
|
||||
Keys.connectedUser({ project_id: projectId, client_id: clientId }),
|
||||
'last_name',
|
||||
user.last_name || ''
|
||||
)
|
||||
multi.hset(
|
||||
Keys.connectedUser({ project_id, client_id }),
|
||||
Keys.connectedUser({ project_id: projectId, client_id: clientId }),
|
||||
'email',
|
||||
user.email || ''
|
||||
)
|
||||
|
||||
if (cursorData) {
|
||||
multi.hset(
|
||||
Keys.connectedUser({ project_id, client_id }),
|
||||
Keys.connectedUser({ project_id: projectId, client_id: clientId }),
|
||||
'cursorData',
|
||||
JSON.stringify(cursorData)
|
||||
)
|
||||
}
|
||||
multi.expire(
|
||||
Keys.connectedUser({ project_id, client_id }),
|
||||
Keys.connectedUser({ project_id: projectId, client_id: clientId }),
|
||||
USER_TIMEOUT_IN_S
|
||||
)
|
||||
|
||||
@@ -77,34 +74,39 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
|
||||
refreshClient(project_id, client_id) {
|
||||
logger.debug({ project_id, client_id }, 'refreshing connected client')
|
||||
refreshClient(projectId, clientId) {
|
||||
logger.debug({ projectId, clientId }, 'refreshing connected client')
|
||||
const multi = rclient.multi()
|
||||
multi.hset(
|
||||
Keys.connectedUser({ project_id, client_id }),
|
||||
Keys.connectedUser({ project_id: projectId, client_id: clientId }),
|
||||
'last_updated_at',
|
||||
Date.now()
|
||||
)
|
||||
multi.expire(
|
||||
Keys.connectedUser({ project_id, client_id }),
|
||||
Keys.connectedUser({ project_id: projectId, client_id: clientId }),
|
||||
USER_TIMEOUT_IN_S
|
||||
)
|
||||
multi.exec(function (err) {
|
||||
if (err) {
|
||||
logger.err(
|
||||
{ err, project_id, client_id },
|
||||
{ err, projectId, clientId },
|
||||
'problem refreshing connected client'
|
||||
)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
markUserAsDisconnected(project_id, client_id, callback) {
|
||||
logger.debug({ project_id, client_id }, 'marking user as disconnected')
|
||||
markUserAsDisconnected(projectId, clientId, callback) {
|
||||
logger.debug({ projectId, clientId }, 'marking user as disconnected')
|
||||
const multi = rclient.multi()
|
||||
multi.srem(Keys.clientsInProject({ project_id }), client_id)
|
||||
multi.expire(Keys.clientsInProject({ project_id }), FOUR_DAYS_IN_S)
|
||||
multi.del(Keys.connectedUser({ project_id, client_id }))
|
||||
multi.srem(Keys.clientsInProject({ project_id: projectId }), clientId)
|
||||
multi.expire(
|
||||
Keys.clientsInProject({ project_id: projectId }),
|
||||
FOUR_DAYS_IN_S
|
||||
)
|
||||
multi.del(
|
||||
Keys.connectedUser({ project_id: projectId, client_id: clientId })
|
||||
)
|
||||
multi.exec(function (err) {
|
||||
if (err) {
|
||||
err = new OError('problem marking user as disconnected').withCause(err)
|
||||
@@ -113,24 +115,24 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
|
||||
_getConnectedUser(project_id, client_id, callback) {
|
||||
_getConnectedUser(projectId, clientId, callback) {
|
||||
rclient.hgetall(
|
||||
Keys.connectedUser({ project_id, client_id }),
|
||||
Keys.connectedUser({ project_id: projectId, client_id: clientId }),
|
||||
function (err, result) {
|
||||
if (err) {
|
||||
err = new OError('problem fetching connected user details', {
|
||||
other_client_id: client_id,
|
||||
other_client_id: clientId,
|
||||
}).withCause(err)
|
||||
return callback(err)
|
||||
}
|
||||
if (!(result && result.user_id)) {
|
||||
result = {
|
||||
connected: false,
|
||||
client_id,
|
||||
client_id: clientId,
|
||||
}
|
||||
} else {
|
||||
result.connected = true
|
||||
result.client_id = client_id
|
||||
result.client_id = clientId
|
||||
result.client_age =
|
||||
(Date.now() - parseInt(result.last_updated_at, 10)) / 1000
|
||||
if (result.cursorData) {
|
||||
@@ -138,7 +140,7 @@ module.exports = {
|
||||
result.cursorData = JSON.parse(result.cursorData)
|
||||
} catch (e) {
|
||||
OError.tag(e, 'error parsing cursorData JSON', {
|
||||
other_client_id: client_id,
|
||||
other_client_id: clientId,
|
||||
cursorData: result.cursorData,
|
||||
})
|
||||
return callback(e)
|
||||
@@ -150,17 +152,17 @@ module.exports = {
|
||||
)
|
||||
},
|
||||
|
||||
getConnectedUsers(project_id, callback) {
|
||||
getConnectedUsers(projectId, callback) {
|
||||
const self = this
|
||||
rclient.smembers(
|
||||
Keys.clientsInProject({ project_id }),
|
||||
Keys.clientsInProject({ project_id: projectId }),
|
||||
function (err, results) {
|
||||
if (err) {
|
||||
err = new OError('problem getting clients in project').withCause(err)
|
||||
return callback(err)
|
||||
}
|
||||
const jobs = results.map(
|
||||
client_id => cb => self._getConnectedUser(project_id, client_id, cb)
|
||||
clientId => cb => self._getConnectedUser(projectId, clientId, cb)
|
||||
)
|
||||
async.series(jobs, function (err, users) {
|
||||
if (err) {
|
||||
|
||||
Reference in New Issue
Block a user