mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
ac_msg fallback support
This commit is contained in:
1 parent
9428efb156
commit
5980080302
9 files changed
+51
-9
No files matched your search
+19
-3
@@ -4,12 +4,15 @@ import * as db from '../service/db';
|
||||
|
||||
const coll = db.collection('message');
|
||||
|
||||
export async function send(from: number, to: number, content: string): Promise<Mdoc> {
|
||||
export const FLAG_UNREAD = 1;
|
||||
export const FLAG_NOTIFICATION = 2;
|
||||
|
||||
export async function send(from: number, to: number, content: string, flag: number): Promise<Mdoc> {
|
||||
const res = await coll.insertOne({
|
||||
from, to, content, unread: true,
|
||||
from, to, content, flag: FLAG_UNREAD | flag,
|
||||
});
|
||||
return {
|
||||
from, to, content, unread: true, _id: res.insertedId,
|
||||
from, to, content, _id: res.insertedId, flag: FLAG_UNREAD | flag,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -27,6 +30,15 @@ export async function getMany(query: any, sort: any, page: number, limit: number
|
||||
.toArray();
|
||||
}
|
||||
|
||||
export async function setFlag(messageId: ObjectID, flag: number) {
|
||||
const result = await coll.findOneAndUpdate(
|
||||
{ _id: messageId },
|
||||
{ $bit: { flag: { xor: flag } } },
|
||||
{ returnOriginal: false },
|
||||
);
|
||||
return result.value;
|
||||
}
|
||||
|
||||
export async function del(_id: ObjectID) {
|
||||
return await coll.deleteOne({ _id });
|
||||
}
|
||||
@@ -47,10 +59,14 @@ export function ensureIndexes() {
|
||||
}
|
||||
|
||||
global.Hydro.model.message = {
|
||||
FLAG_UNREAD,
|
||||
FLAG_NOTIFICATION,
|
||||
|
||||
count,
|
||||
get,
|
||||
getByUser,
|
||||
del,
|
||||
setFlag,
|
||||
getMany,
|
||||
getMulti,
|
||||
send,
|
||||
|
||||
Reference in new issue
Block a user