ui: 收到站内消息是增加提醒 (#86)

This commit is contained in:
undefined committed 2021-04-05 02:32:04 +08:00
1 parent fb47598c57
commit 6cae5cb7d1
10 files changed
+62 -67

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.21.5",
"version": "2.21.6",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+3 -5
View File
@@ -1,6 +1,6 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-eval */
import fs from 'fs';
import fs from 'fs-extra';
import os from 'os';
import path from 'path';
import yaml from 'js-yaml';
@@ -130,9 +130,7 @@ export async function template(pending: string[], fail: string[]) {
try {
const files = getFiles(p);
for (const file of files) {
global.Hydro.ui.template[file] = fs.readFileSync(
path.resolve(p, file),
).toString();
global.Hydro.ui.template[file] = await fs.readFile(path.resolve(p, file), 'utf-8');
}
logger.info('Template init: %s', i);
} catch (e) {
@@ -216,7 +214,7 @@ export async function service(pending: string[], fail: string[]) {
export async function script(pending: string[], fail: string[], active: string[]) {
for (const i of pending) {
const p = path.resolve(i, 'script.js');
if (fs.existsSync(p) && !fail.includes(i)) {
if (await fs.pathExists(p) && !fail.includes(i)) {
try {
logger.info('Script init: %s', i);
eval('require')(p);
+6 -2
View File
@@ -3,6 +3,7 @@ import {
VerifyPasswordError, UserAlreadyExistError, InvalidTokenError,
NotFoundError, UserNotFoundError, PermissionError, DomainAlreadyExistsError,
} from '../error';
import { Mdoc } from '../interface';
import * as bus from '../service/bus';
import {
Route, Connection, Handler, ConnectionHandler, param, Types,
@@ -328,6 +329,7 @@ class HomeMessagesHandler extends Handler {
['Hydro', 'homepage'],
['home_messages', null],
];
await user.setById(this.user._id, { unreadMsg: 0 });
this.response.body = { messages: parsed, path };
this.response.template = 'home_messages.html';
}
@@ -367,9 +369,11 @@ class HomeMessagesConnectionHandler extends ConnectionHandler {
this.dispose = bus.on('user/message', this.onMessageReceived.bind(this));
}
async onMessageReceived(uid: number, e: any) {
async onMessageReceived(uid: number, mdoc: Mdoc) {
if (uid !== this.user._id) return;
this.send(e);
const udoc = await user.getById(this.domainId, mdoc.from);
udoc.gravatar_url = misc.gravatar(udoc.gravatar, 64);
this.send({ udoc, mdoc });
}
async cleanup() {
+1
View File
@@ -27,6 +27,7 @@ class MessageModel {
const udoc = await user.getById('system', to);
bus.boardcast('user/message', to, mdoc, udoc);
}
await user.inc(to, 'unreadMsg', 1);
return mdoc;
}
+1 -1
View File
@@ -114,7 +114,7 @@ AccountSetting(
Setting('setting_customize', 'backgroundImage',
'/components/profile/backgrounds/1.jpg', 'text', 'Profile Background Image',
'Choose the background image in your profile page.'),
Setting('setting_storage', 'usage', 0, 'number', 'Userfile Usage', null, FLAG_DISABLED | FLAG_HIDDEN),
Setting('setting_storage', 'unreadMsg', 0, 'number', 'Unread Message Count', null, FLAG_DISABLED | FLAG_HIDDEN),
Setting('setting_storage', 'checkincnt', 0, 'number', 'Check In Counter', null, FLAG_DISABLED | FLAG_HIDDEN),
Setting('setting_storage', 'lastcheckin', 0, 'number', 'Last checkin time', null, FLAG_DISABLED | FLAG_HIDDEN),
);
+1
View File
@@ -146,6 +146,7 @@ export async function parallel<K extends keyof EventMap>(name: K, ...args: Param
const tasks: Promise<any>[] = [];
if (argv.showBus) logger.debug('parallel: %s %o', name, args);
for (const callback of _hooks[name] || []) {
if (argv.busDetail) logger.debug(callback.toString());
tasks.push(callback.apply(this, args));
}
await Promise.all(tasks);