This commit is contained in:
masnn committed 2020-06-03 13:44:39 +08:00
1 parent 2b6a510c1e
commit f2bcc3bc93
23 files changed
+241 -119

No files matched your search

+7 -23
View File
@@ -5,29 +5,8 @@ const db = require('../service/db.js');
const coll = db.collection('message');
async function send(from, to, content) {
await coll.updateOne({
from: Math.min(from, to),
to: Math.max(from, to),
}, {
$push: {
reply: {
_id: new ObjectID(),
from,
content,
unread: true,
at: new Date(),
},
},
$setOnInsert: {
from: Math.min(from, to),
to: Math.max(from, to),
fromUnread: from > to,
toUnread: from < to,
},
}, { upsert: true });
return await coll.findOne({ // eslint-disable-line no-return-await
from: Math.min(from, to),
to: Math.max(from, to),
await coll.insertOne({
from, to, content, unread: true,
});
}
@@ -37,6 +16,10 @@ async function get(_id) {
return doc;
}
function getByUser(uid) {
return coll.find({ $or: [{ from: uid }, { to: uid }] }).toArray();
}
function getMany(query, sort, page, limit) {
return coll.find(query).sort(sort)
.skip((page - 1) * limit).limit(limit)
@@ -65,6 +48,7 @@ function ensureIndexes() {
global.Hydro.model.message = module.exports = {
count,
get,
getByUser,
del,
getMany,
getMulti,