core: discussion reaction

This commit is contained in:
undefined committed 2021-06-10 09:54:51 +08:00
1 parent 4b3e2a8e50
commit bc74870a39
6 files changed
+60 -25

No files matched your search

@@ -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) {
+25 -23
View File
@@ -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<string, number>;
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<string, number>;
}
export interface DiscussionTailReplyDoc {
+3
View File
@@ -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
+6
View File
@@ -176,6 +176,11 @@ export function getListReply(domainId: string, did: ObjectID): Promise<Discussio
return getMultiReply(domainId, did).toArray();
}
export async function react(domainId: string, docType: keyof document.DocType, did: ObjectID, id: string, uid: number, reverse = false) {
const updated = await document.setIfNotStatus(domainId, docType, did, uid, `react.${id}`, reverse ? 0 : 1, reverse ? 0 : 1, {});
if (updated) await document.inc(domainId, docType, did, `react.${id}`, reverse ? -1 : 1);
}
export async function addTailReply(
domainId: string, drid: ObjectID,
owner: number, content: string, ip: string,
@@ -330,6 +335,7 @@ global.Hydro.model.discussion = {
getTailReply,
editTailReply,
delTailReply,
react,
setStar,
getStatus,
addNode,
+10 -1
View File
@@ -304,7 +304,16 @@ export async function setIfNotStatus<T extends keyof DocStatusType, K extends ke
key: K, value: DocStatusType[T][K], ifNot: DocStatusType[T][K], args: Partial<DocStatusType[T]>,
): Promise<DocStatusType[T]> {
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 } },
+6 -1
View File
@@ -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(),