| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- /* eslint-disable
- camelcase,
- handle-callback-err,
- max-len,
- */
- // TODO: This file was created by bulk-decaffeinate.
- // Fix any style issues and re-enable lint.
- /*
- * 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
- */
- let ThreadManager
- const { ObjectId, getCollection } = require('../../mongodb')
- const logger = require('logger-sharelatex')
- const metrics = require('metrics-sharelatex')
- const roomsCollectionPromise = getCollection('rooms')
- module.exports = ThreadManager = {
- GLOBAL_THREAD: 'GLOBAL',
- findOrCreateThread(project_id, thread_id, callback) {
- let query, update
- if (callback == null) {
- callback = function (error, thread) {}
- }
- project_id = ObjectId(project_id.toString())
- if (thread_id !== ThreadManager.GLOBAL_THREAD) {
- thread_id = ObjectId(thread_id.toString())
- }
- if (thread_id === ThreadManager.GLOBAL_THREAD) {
- query = {
- project_id,
- thread_id: { $exists: false }
- }
- update = {
- project_id
- }
- } else {
- query = {
- project_id,
- thread_id
- }
- update = {
- project_id,
- thread_id
- }
- }
- roomsCollectionPromise.then((rooms) =>
- rooms.updateOne(query, { $set: update }, { upsert: true }, function (
- error
- ) {
- if (error != null) {
- return callback(error)
- }
- rooms.findOne(query, callback)
- })
- )
- },
- findAllThreadRooms(project_id, callback) {
- if (callback == null) {
- callback = function (error, rooms) {}
- }
- roomsCollectionPromise.then((rooms) =>
- rooms
- .find(
- {
- project_id: ObjectId(project_id.toString()),
- thread_id: { $exists: true }
- },
- {
- thread_id: 1,
- resolved: 1
- }
- )
- .toArray(callback)
- )
- },
- resolveThread(project_id, thread_id, user_id, callback) {
- if (callback == null) {
- callback = function (error) {}
- }
- roomsCollectionPromise.then((rooms) =>
- rooms.updateOne(
- {
- project_id: ObjectId(project_id.toString()),
- thread_id: ObjectId(thread_id.toString())
- },
- {
- $set: {
- resolved: {
- user_id,
- ts: new Date()
- }
- }
- },
- callback
- )
- )
- },
- reopenThread(project_id, thread_id, callback) {
- if (callback == null) {
- callback = function (error) {}
- }
- roomsCollectionPromise.then((rooms) =>
- rooms.updateOne(
- {
- project_id: ObjectId(project_id.toString()),
- thread_id: ObjectId(thread_id.toString())
- },
- {
- $unset: {
- resolved: true
- }
- },
- callback
- )
- )
- },
- deleteThread(project_id, thread_id, callback) {
- if (callback == null) {
- callback = function (error, room_id) {}
- }
- return this.findOrCreateThread(project_id, thread_id, function (
- error,
- room
- ) {
- if (error != null) {
- return callback(error)
- }
- roomsCollectionPromise.then((rooms) =>
- rooms.deleteOne(
- {
- _id: room._id
- },
- function (error) {
- if (error != null) {
- return callback(error)
- }
- return callback(null, room._id)
- }
- )
- )
- })
- }
- }
- ;[
- 'findOrCreateThread',
- 'findAllThreadRooms',
- 'resolveThread',
- 'reopenThread',
- 'deleteThread'
- ].map((method) =>
- metrics.timeAsyncMethod(ThreadManager, method, 'mongo.ThreadManager', logger)
- )
|