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

+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 } },