mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: add additional flag hooks [breaking]
`action:flags.create` on initial flag creation `action:flags.notify` on notification to admins and moderators `action:flags.addReport` on flag report addition (called during initial flag create, too)
This commit is contained in:
13
src/flags.js
13
src/flags.js
@@ -443,7 +443,10 @@ Flags.create = async function (type, id, uid, reason, timestamp) {
|
|||||||
Flags.update(flagId, uid, { state: 'open' });
|
Flags.update(flagId, uid, { state: 'open' });
|
||||||
}
|
}
|
||||||
|
|
||||||
return await Flags.get(flagId);
|
const flagObj = await Flags.get(flagId);
|
||||||
|
|
||||||
|
plugins.hooks.fire('action:flags.create', { flag: flagObj });
|
||||||
|
return flagObj;
|
||||||
};
|
};
|
||||||
|
|
||||||
Flags.getReports = async function (flagId) {
|
Flags.getReports = async function (flagId) {
|
||||||
@@ -474,6 +477,8 @@ Flags.addReport = async function (flagId, type, id, uid, reason, timestamp) {
|
|||||||
|
|
||||||
['flags:hash', flagId, [type, id, uid].join(':')],
|
['flags:hash', flagId, [type, id, uid].join(':')],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
plugins.fireHook('action:flags.addReport', { flagId, type, id, uid, reason, timestamp });
|
||||||
};
|
};
|
||||||
|
|
||||||
Flags.exists = async function (type, id, uid) {
|
Flags.exists = async function (type, id, uid) {
|
||||||
@@ -743,9 +748,11 @@ Flags.notify = async function (flagObj, uid) {
|
|||||||
throw new Error('[[error:invalid-data]]');
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins.hooks.fire('action:flags.create', {
|
plugins.hooks.fire('action:flags.notify', {
|
||||||
flag: flagObj,
|
flag: flagObj,
|
||||||
uid: uid,
|
notification: notifObj,
|
||||||
|
from: uid,
|
||||||
|
to: uids,
|
||||||
});
|
});
|
||||||
uids = uids.filter(_uid => parseInt(_uid, 10) !== parseInt(uid, 10));
|
uids = uids.filter(_uid => parseInt(_uid, 10) !== parseInt(uid, 10));
|
||||||
await notifications.push(notifObj, uids);
|
await notifications.push(notifObj, uids);
|
||||||
|
|||||||
Reference in New Issue
Block a user