|
|
@@ -12,12 +12,12 @@
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
*/
|
|
|
let ThreadManager
|
|
|
-const mongojs = require('../../mongojs')
|
|
|
-const { db } = mongojs
|
|
|
-const { ObjectId } = mongojs
|
|
|
+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',
|
|
|
|
|
|
@@ -50,38 +50,35 @@ module.exports = ThreadManager = {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return db.rooms.update(query, { $set: update }, { upsert: true }, function (
|
|
|
- error
|
|
|
- ) {
|
|
|
- if (error != null) {
|
|
|
- return callback(error)
|
|
|
- }
|
|
|
- return db.rooms.find(query, function (error, rooms) {
|
|
|
- if (rooms == null) {
|
|
|
- rooms = []
|
|
|
- }
|
|
|
+ roomsCollectionPromise.then((rooms) =>
|
|
|
+ rooms.updateOne(query, { $set: update }, { upsert: true }, function (
|
|
|
+ error
|
|
|
+ ) {
|
|
|
if (error != null) {
|
|
|
return callback(error)
|
|
|
}
|
|
|
- return callback(null, rooms[0])
|
|
|
+ rooms.findOne(query, callback)
|
|
|
})
|
|
|
- })
|
|
|
+ )
|
|
|
},
|
|
|
|
|
|
findAllThreadRooms(project_id, callback) {
|
|
|
if (callback == null) {
|
|
|
callback = function (error, rooms) {}
|
|
|
}
|
|
|
- return db.rooms.find(
|
|
|
- {
|
|
|
- project_id: ObjectId(project_id.toString()),
|
|
|
- thread_id: { $exists: true }
|
|
|
- },
|
|
|
- {
|
|
|
- thread_id: 1,
|
|
|
- resolved: 1
|
|
|
- },
|
|
|
- callback
|
|
|
+ roomsCollectionPromise.then((rooms) =>
|
|
|
+ rooms
|
|
|
+ .find(
|
|
|
+ {
|
|
|
+ project_id: ObjectId(project_id.toString()),
|
|
|
+ thread_id: { $exists: true }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ thread_id: 1,
|
|
|
+ resolved: 1
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .toArray(callback)
|
|
|
)
|
|
|
},
|
|
|
|
|
|
@@ -89,20 +86,22 @@ module.exports = ThreadManager = {
|
|
|
if (callback == null) {
|
|
|
callback = function (error) {}
|
|
|
}
|
|
|
- return db.rooms.update(
|
|
|
- {
|
|
|
- project_id: ObjectId(project_id.toString()),
|
|
|
- thread_id: ObjectId(thread_id.toString())
|
|
|
- },
|
|
|
- {
|
|
|
- $set: {
|
|
|
- resolved: {
|
|
|
- user_id,
|
|
|
- ts: new Date()
|
|
|
+ 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
|
|
|
+ },
|
|
|
+ callback
|
|
|
+ )
|
|
|
)
|
|
|
},
|
|
|
|
|
|
@@ -110,17 +109,19 @@ module.exports = ThreadManager = {
|
|
|
if (callback == null) {
|
|
|
callback = function (error) {}
|
|
|
}
|
|
|
- return db.rooms.update(
|
|
|
- {
|
|
|
- project_id: ObjectId(project_id.toString()),
|
|
|
- thread_id: ObjectId(thread_id.toString())
|
|
|
- },
|
|
|
- {
|
|
|
- $unset: {
|
|
|
- resolved: true
|
|
|
- }
|
|
|
- },
|
|
|
- callback
|
|
|
+ roomsCollectionPromise.then((rooms) =>
|
|
|
+ rooms.updateOne(
|
|
|
+ {
|
|
|
+ project_id: ObjectId(project_id.toString()),
|
|
|
+ thread_id: ObjectId(thread_id.toString())
|
|
|
+ },
|
|
|
+ {
|
|
|
+ $unset: {
|
|
|
+ resolved: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ callback
|
|
|
+ )
|
|
|
)
|
|
|
},
|
|
|
|
|
|
@@ -135,16 +136,18 @@ module.exports = ThreadManager = {
|
|
|
if (error != null) {
|
|
|
return callback(error)
|
|
|
}
|
|
|
- return db.rooms.remove(
|
|
|
- {
|
|
|
- _id: room._id
|
|
|
- },
|
|
|
- function (error) {
|
|
|
- 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)
|
|
|
}
|
|
|
- return callback(null, room._id)
|
|
|
- }
|
|
|
+ )
|
|
|
)
|
|
|
})
|
|
|
}
|