mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +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
@@ -2,3 +2,7 @@
|
||||
为model.system添加缓存
|
||||
bug修复
|
||||
修复discussion前端权限节点显示异常
|
||||
web端运行脚本似乎异常
|
||||
讨论回复通知
|
||||
比赛举办者发布通知
|
||||
举报功能
|
||||
@@ -141,7 +141,7 @@ export function load() {
|
||||
),
|
||||
db.collection('system').updateOne(
|
||||
{ _id: 'server.port' },
|
||||
{ $set: { value: listenPort } },
|
||||
{ $set: { value: parseInt(listenPort, 10) } },
|
||||
{ upsert: true },
|
||||
),
|
||||
]);
|
||||
|
||||
@@ -336,6 +336,14 @@ class HomeMessagesHandler extends Handler {
|
||||
else throw new PermissionError();
|
||||
this.back();
|
||||
}
|
||||
|
||||
@param('messageId', Types.ObjectID)
|
||||
async postRead(domainId: string, messageId: ObjectID) {
|
||||
const msg = await message.get(messageId);
|
||||
if ([msg.from, msg.to].includes(this.user._id)) await message.setFlag(messageId, message.FLAG_UNREAD);
|
||||
else throw new PermissionError();
|
||||
this.back();
|
||||
}
|
||||
}
|
||||
|
||||
class HomeMessagesConnectionHandler extends ConnectionHandler {
|
||||
|
||||
+2
-1
@@ -69,6 +69,7 @@ export interface Pdoc {
|
||||
data?: ObjectID | string,
|
||||
hidden: boolean,
|
||||
config: string,
|
||||
acMsg?: string,
|
||||
}
|
||||
|
||||
export type Pdict = Dictionary<Pdoc>;
|
||||
@@ -150,7 +151,7 @@ export interface Mdoc {
|
||||
from: number,
|
||||
to: number,
|
||||
content: string,
|
||||
unread: boolean,
|
||||
flag: number,
|
||||
}
|
||||
|
||||
// Userfile
|
||||
|
||||
+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(
|
||||
|
||||
@@ -13,6 +13,7 @@ import Router from 'koa-router';
|
||||
import cache from 'koa-static-cache';
|
||||
import sockjs from 'sockjs';
|
||||
import serialize from 'serialize-javascript';
|
||||
import parse from 'yargs-parser';
|
||||
import { lrucache } from '../utils';
|
||||
import { User, DomainDoc } from '../interface';
|
||||
import {
|
||||
@@ -31,8 +32,8 @@ import * as token from '../model/token';
|
||||
import * as opcount from '../model/opcount';
|
||||
import hash from '../lib/hash.hydro';
|
||||
|
||||
const argv = parse(process.argv.slice(2));
|
||||
let enableLog = true;
|
||||
|
||||
const app = new Koa();
|
||||
let server;
|
||||
const router = new Router();
|
||||
@@ -760,8 +761,8 @@ export async function start() {
|
||||
} else enableLog = false;
|
||||
app.use(router.routes()).use(router.allowedMethods());
|
||||
Route('notfound_handler', '*', Handler);
|
||||
server.listen(port);
|
||||
console.log('Server listening at: %s', port);
|
||||
server.listen(argv.port || port);
|
||||
console.log('Server listening at: %s', argv.port || port);
|
||||
}
|
||||
|
||||
global.Hydro.service.server = {
|
||||
|
||||
@@ -97,6 +97,10 @@
|
||||
{% else %}
|
||||
{{ _('(None)') }}
|
||||
{% endif %}
|
||||
{% if pdoc['acMsg'] and pdoc['psdoc']['status'] == STATUS.STATUS_ACCEPTED %}
|
||||
<dt>{{ _('AC Message') }}</dt>
|
||||
<dd>{{ pdoc['acMsg'] }}</dd>
|
||||
{% endif %}
|
||||
</dd>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
Reference in new issue
Block a user