mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01: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
+8
-1
@@ -135,6 +135,13 @@ export function url(arg0: any, name: any) {
|
||||
return __url(arg0, name);
|
||||
}
|
||||
|
||||
export function ensureIndexes() {
|
||||
return Promise.all([
|
||||
collChunk.createIndex({ files_id: 1, n: 1 }, { unique: true }),
|
||||
collFile.createIndex({ md5: 1 }),
|
||||
]);
|
||||
}
|
||||
|
||||
global.Hydro.model.file = {
|
||||
add, get, del, inc, dec, getMeta, getWithSecret, getMulti, getMetaDict, url,
|
||||
add, get, del, inc, dec, getMeta, getWithSecret, getMulti, getMetaDict, url, ensureIndexes,
|
||||
};
|
||||
+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,
|
||||
|
||||
@@ -22,6 +22,7 @@ export const pdocHidden: Pdoc = {
|
||||
data: null,
|
||||
hidden: true,
|
||||
config: '',
|
||||
acMsg: '',
|
||||
};
|
||||
|
||||
export async function add(
|
||||
|
||||
Reference in new issue
Block a user