From bc74870a396f65ed86e111b14c00d209a3bc2fd4 Mon Sep 17 00:00:00 2001 From: undefined Date: Thu, 10 Jun 2021 09:54:51 +0800 Subject: [PATCH] core: discussion reaction --- packages/hydrooj/src/handler/discussion.ts | 10 +++++ packages/hydrooj/src/interface.ts | 48 +++++++++++---------- packages/hydrooj/src/model/builtin.ts | 3 ++ packages/hydrooj/src/model/discussion.ts | 6 +++ packages/hydrooj/src/model/document.ts | 11 ++++- packages/ui-default/build/config/webpack.js | 7 ++- 6 files changed, 60 insertions(+), 25 deletions(-) diff --git a/packages/hydrooj/src/handler/discussion.ts b/packages/hydrooj/src/handler/discussion.ts index d5dae1aaa..40191bd3e 100644 --- a/packages/hydrooj/src/handler/discussion.ts +++ b/packages/hydrooj/src/handler/discussion.ts @@ -206,6 +206,16 @@ class DiscussionDetailHandler extends DiscussionHandler { this.checkPriv(PRIV.PRIV_USER_PROFILE); } + @param('type', Types.Range(['did', 'drid'])) + @param('did', Types.ObjectID) + @param('id', Types.Name) + @param('reverse', Types.Boolean) + async postReaction(domainId: string, type: string, did: ObjectID, id: string, reverse = false) { + this.checkPerm(PERM.PERM_ADD_REACTION); + await discussion.react(domainId, type === 'did' ? document.TYPE_DISCUSSION : document.TYPE_DISCUSSION_REPLY, did, id, this.user._id, reverse); + this.back(); + } + @param('did', Types.ObjectID) @param('content', Types.Content) async postReply(domainId: string, did: ObjectID, content: string) { diff --git a/packages/hydrooj/src/interface.ts b/packages/hydrooj/src/interface.ts index e37288b54..5738b8a63 100644 --- a/packages/hydrooj/src/interface.ts +++ b/packages/hydrooj/src/interface.ts @@ -368,33 +368,35 @@ export interface HistoryDoc { export type { DiscussionDoc } from './model/discussion'; declare module './model/discussion' { interface DiscussionDoc { - docType: document['TYPE_DISCUSSION'], - docId: ObjectID, - parentType: number, - parentId: ObjectID | number | string, - title: string, - content: string, - ip: string, - pin: boolean, - highlight: boolean, - updateAt: Date, - nReply: number, - views: number, - history: HistoryDoc[], - sort: number, - lastRCount: number, + docType: document['TYPE_DISCUSSION']; + docId: ObjectID; + parentType: number; + parentId: ObjectID | number | string; + title: string; + content: string; + ip: string; + pin: boolean; + highlight: boolean; + updateAt: Date; + nReply: number; + views: number; + history: HistoryDoc[]; + react: Record; + sort: number; + lastRCount: number; } } export interface DiscussionReplyDoc extends Document { - docType: document['TYPE_DISCUSSION_REPLY'], - docId: ObjectID, - parentType: document['TYPE_DISCUSSION'], - parentId: ObjectID, - ip: string, - content: string, - reply: DiscussionTailReplyDoc[], - history: HistoryDoc[], + docType: document['TYPE_DISCUSSION_REPLY']; + docId: ObjectID; + parentType: document['TYPE_DISCUSSION']; + parentId: ObjectID; + ip: string; + content: string; + reply: DiscussionTailReplyDoc[]; + history: HistoryDoc[]; + react: Record; } export interface DiscussionTailReplyDoc { diff --git a/packages/hydrooj/src/model/builtin.ts b/packages/hydrooj/src/model/builtin.ts index 2bce0edb3..3fb2c6214 100644 --- a/packages/hydrooj/src/model/builtin.ts +++ b/packages/hydrooj/src/model/builtin.ts @@ -57,6 +57,7 @@ export const PERM = { PERM_DELETE_DISCUSSION: 1n << 32n, PERM_DELETE_DISCUSSION_SELF: 1n << 33n, PERM_REPLY_DISCUSSION: 1n << 34n, + PERM_ADD_REACTION: 1 << 62n, PERM_EDIT_DISCUSSION_REPLY_SELF: 1n << 36n, PERM_DELETE_DISCUSSION_REPLY: 1n << 38n, PERM_DELETE_DISCUSSION_REPLY_SELF: 1n << 39n, @@ -134,6 +135,7 @@ export const PERMS = [ Permission('perm_discussion', PERM.PERM_DELETE_DISCUSSION, 'Delete discussions'), Permission('perm_discussion', PERM.PERM_DELETE_DISCUSSION_SELF, 'Delete own discussions'), Permission('perm_discussion', PERM.PERM_REPLY_DISCUSSION, 'Reply discussions'), + Permission('perm_discussion', PERM.PERM_ADD_REACTION, 'React to discussion'), Permission('perm_discussion', PERM.PERM_EDIT_DISCUSSION_REPLY_SELF, 'Edit own discussion replies'), Permission('perm_discussion', PERM.PERM_DELETE_DISCUSSION_REPLY, 'Delete discussion replies'), Permission('perm_discussion', PERM.PERM_DELETE_DISCUSSION_REPLY_SELF, 'Delete own discussion replies'), @@ -192,6 +194,7 @@ PERM.PERM_DEFAULT = PERM.PERM_VIEW | PERM.PERM_CREATE_DISCUSSION | PERM.PERM_EDIT_DISCUSSION_SELF | PERM.PERM_REPLY_DISCUSSION + | PERM.PERM_ADD_REACTION | PERM.PERM_EDIT_DISCUSSION_REPLY_SELF | PERM.PERM_DELETE_DISCUSSION_REPLY_SELF | PERM.PERM_DELETE_DISCUSSION_REPLY_SELF_DISCUSSION diff --git a/packages/hydrooj/src/model/discussion.ts b/packages/hydrooj/src/model/discussion.ts index 563a35485..047868d09 100644 --- a/packages/hydrooj/src/model/discussion.ts +++ b/packages/hydrooj/src/model/discussion.ts @@ -176,6 +176,11 @@ export function getListReply(domainId: string, did: ObjectID): Promise, ): Promise { const current = await collStatus.findOne({ domainId, docType, docId, uid }) || {}; - if (current[key] === ifNot) return null; + if (typeof key === 'string' && key.includes('.')) { + const acc = key.split('.'); + let c = current; + for (const i of acc) { + if (!(i in c)) break; + c = c[i]; + if (c === null || c === undefined) break; + } + if (c === ifNot) return null; + } else if (current[key] === ifNot) return null; const res = await collStatus.findOneAndUpdate( { domainId, docType, docId, uid }, { $set: { [key]: value, ...args } }, diff --git a/packages/ui-default/build/config/webpack.js b/packages/ui-default/build/config/webpack.js index 1848886ca..a7ecbfa83 100644 --- a/packages/ui-default/build/config/webpack.js +++ b/packages/ui-default/build/config/webpack.js @@ -124,8 +124,13 @@ export default function (env = {}) { }, optimization: { splitChunks: { - minChunks: 2, + minSize: 80000, + maxAsyncRequests: 15, + maxInitialRequests: 10, + chunks: 'all', }, + moduleIds: env.production ? 'size' : 'named', + chunkIds: env.production ? 'size' : 'named', }, plugins: [ new WebpackBar(),