2020-02-17 02:37:55 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-17 02:37:54 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-17 02:38:00 -05:00
|
|
|
let ContactManager
|
2020-08-21 11:30:18 -04:00
|
|
|
const { db, ObjectId } = require('./mongodb')
|
2021-12-14 08:00:35 -05:00
|
|
|
const logger = require('@overleaf/logger')
|
2020-11-25 06:57:24 -05:00
|
|
|
const metrics = require('@overleaf/metrics')
|
2015-10-06 11:41:35 -04:00
|
|
|
|
2020-02-17 02:38:00 -05:00
|
|
|
module.exports = ContactManager = {
|
|
|
|
touchContact(user_id, contact_id, callback) {
|
|
|
|
if (callback == null) {
|
2021-10-27 05:49:18 -04:00
|
|
|
callback = function () {}
|
2020-02-17 02:38:00 -05:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
user_id = ObjectId(user_id.toString())
|
|
|
|
} catch (error1) {
|
|
|
|
const error = error1
|
|
|
|
return callback(error)
|
|
|
|
}
|
2015-10-06 11:41:35 -04:00
|
|
|
|
2020-02-17 02:38:00 -05:00
|
|
|
const update = { $set: {}, $inc: {} }
|
|
|
|
update.$inc[`contacts.${contact_id}.n`] = 1
|
|
|
|
update.$set[`contacts.${contact_id}.ts`] = new Date()
|
2015-10-06 11:41:35 -04:00
|
|
|
|
2020-08-21 11:30:18 -04:00
|
|
|
db.contacts.updateOne(
|
2020-02-17 02:38:00 -05:00
|
|
|
{
|
2021-07-13 07:04:47 -04:00
|
|
|
user_id,
|
2020-02-17 02:38:00 -05:00
|
|
|
},
|
|
|
|
update,
|
|
|
|
{
|
2021-07-13 07:04:47 -04:00
|
|
|
upsert: true,
|
2020-02-17 02:38:00 -05:00
|
|
|
},
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
},
|
2017-03-17 05:31:12 -04:00
|
|
|
|
2020-02-17 02:38:00 -05:00
|
|
|
getContacts(user_id, callback) {
|
|
|
|
if (callback == null) {
|
2021-10-27 05:49:18 -04:00
|
|
|
callback = function () {}
|
2020-02-17 02:38:00 -05:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
user_id = ObjectId(user_id.toString())
|
|
|
|
} catch (error1) {
|
|
|
|
const error = error1
|
|
|
|
return callback(error)
|
|
|
|
}
|
|
|
|
|
|
|
|
return db.contacts.findOne(
|
|
|
|
{
|
2021-07-13 07:04:47 -04:00
|
|
|
user_id,
|
2020-02-17 02:38:00 -05:00
|
|
|
},
|
2020-06-04 03:49:46 -04:00
|
|
|
function (error, user) {
|
2020-02-17 02:38:00 -05:00
|
|
|
if (error != null) {
|
|
|
|
return callback(error)
|
|
|
|
}
|
|
|
|
return callback(null, user != null ? user.contacts : undefined)
|
|
|
|
}
|
|
|
|
)
|
2021-07-13 07:04:47 -04:00
|
|
|
},
|
2020-02-17 02:38:00 -05:00
|
|
|
}
|
2021-07-13 07:04:47 -04:00
|
|
|
;['touchContact', 'getContacts'].map(method =>
|
2020-02-17 02:38:00 -05:00
|
|
|
metrics.timeAsyncMethod(
|
|
|
|
ContactManager,
|
|
|
|
method,
|
|
|
|
'mongo.ContactManager',
|
|
|
|
logger
|
|
|
|
)
|
|
|
|
)
|