core&ui: add clarification (#669)

This commit is contained in:
panda authored and GitHub committed 2023-11-05 06:49:51 +08:00
1 parent bc4f5115d2
commit c8c8063240
14 files changed
+373 -80

No files matched your search

+35
View File
@@ -911,6 +911,37 @@ export async function getScoreboard(
return [tdoc, rows, udict, pdict];
}
export function addClarification(
domainId: string, tid: ObjectId, owner: number, content: string,
ip: string, subject = 0,
) {
return document.add(
domainId, content, owner, document.TYPE_CONTEST_CLARIFICATION,
null, document.TYPE_CONTEST, tid, { ip, subject },
);
}
export function addClarificationReply(
domainId: string, did: ObjectId, owner: number,
content: string, ip: string,
) {
return document.push(
domainId, document.TYPE_CONTEST_CLARIFICATION, did,
'reply', { content, owner, ip },
);
}
export function getClarification(domainId: string, did: ObjectId) {
return document.get(domainId, document.TYPE_CONTEST_CLARIFICATION, did);
}
export function getMultiClarification(domainId: string, tid: ObjectId, owner = 0) {
return document.getMulti(
domainId, document.TYPE_CONTEST_CLARIFICATION,
{ parentType: document.TYPE_CONTEST, parentId: tid, ...(owner ? { owner: { $in: [owner, 0] } } : {}) },
).sort('_id', -1).toArray();
}
export const statusText = (tdoc: Tdoc, tsdoc?: any) => (
isNew(tdoc)
? 'New'
@@ -948,6 +979,10 @@ global.Hydro.model.contest = {
canShowScoreboard,
canViewHiddenScoreboard,
getScoreboard,
addClarification,
addClarificationReply,
getClarification,
getMultiClarification,
isNew,
isUpcoming,
isNotStarted,
+4 -1
View File
@@ -5,7 +5,7 @@ import {
} from 'mongodb';
import { Context } from '../context';
import {
Content, DiscussionDoc,
Content, ContestClarificationDoc, DiscussionDoc,
DiscussionReplyDoc, ProblemDoc, ProblemStatusDoc,
Tdoc, TrainingDoc,
} from '../interface';
@@ -27,6 +27,7 @@ export const TYPE_DISCUSSION_NODE: 20 = 20;
export const TYPE_DISCUSSION: 21 = 21;
export const TYPE_DISCUSSION_REPLY: 22 = 22;
export const TYPE_CONTEST: 30 = 30;
export const TYPE_CONTEST_CLARIFICATION: 31 = 31;
export const TYPE_TRAINING: 40 = 40;
/** @deprecated use `TYPE_CONTEST` with rule `homework` instead. */
export const TYPE_HOMEWORK: 60 = 60;
@@ -39,6 +40,7 @@ export interface DocType {
[TYPE_DISCUSSION]: DiscussionDoc;
[TYPE_DISCUSSION_REPLY]: DiscussionReplyDoc;
[TYPE_CONTEST]: Tdoc;
[TYPE_CONTEST_CLARIFICATION]: ContestClarificationDoc;
[TYPE_TRAINING]: TrainingDoc;
}
@@ -498,6 +500,7 @@ global.Hydro.model.document = {
setSub,
TYPE_CONTEST,
TYPE_CONTEST_CLARIFICATION,
TYPE_DISCUSSION,
TYPE_DISCUSSION_NODE,
TYPE_DISCUSSION_REPLY,
+2 -1
View File
@@ -12,6 +12,7 @@ class MessageModel {
static FLAG_ALERT = 2;
static FLAG_RICHTEXT = 4;
static FLAG_INFO = 8;
static FLAG_I18N = 16;
static coll = db.collection('message');
@@ -33,7 +34,7 @@ class MessageModel {
static async sendInfo(to: number, content: string) {
const _id = new ObjectId();
const mdoc: MessageDoc = {
_id, from: 1, to, content, flag: MessageModel.FLAG_INFO,
_id, from: 1, to, content, flag: MessageModel.FLAG_INFO | MessageModel.FLAG_I18N,
};
bus.broadcast('user/message', to, mdoc);
}